#no-std #ethercat #beckhoff #igh #soem

no-std ethercrab

An EtherCAT master in pure Rust that is no_std compatible

8 releases

0.3.4 Nov 20, 2023
0.3.3 Nov 10, 2023
0.3.1 Oct 16, 2023
0.2.1 Jul 31, 2023
0.1.0 Jan 2, 2023

#63 in Robotics

Download history 4/week @ 2023-08-19 3/week @ 2023-08-26 5/week @ 2023-09-02 3/week @ 2023-09-09 5/week @ 2023-09-16 3/week @ 2023-09-23 3/week @ 2023-09-30 37/week @ 2023-10-07 41/week @ 2023-10-14 14/week @ 2023-10-21 32/week @ 2023-10-28 42/week @ 2023-11-04 16/week @ 2023-11-11 35/week @ 2023-11-18 26/week @ 2023-11-25 35/week @ 2023-12-02

138 downloads per month


12K SLoC


Build Status Crates.io Docs.rs Matrix chat

A performant, async-first EtherCAT master written in pure Rust.

Are you looking to use Rust in your next EtherCAT deployment? Commercial support for EtherCrab is available! Send me a message at james@wapl.es to get started with a free consulting call.

Crate features

  • std (enabled by default) - exposes the [std] module, containing helpers to run the TX/RX loop on desktop operating systems.
  • defmt - enable logging with the defmt crate.
  • log - enable logging with the log crate. This is enabled by default when the std feature is enabled.
  • serde - enable serde impls for some public items.

For no_std targets, it is recommended to add this crate with

cargo add --no-default-features --features defmt


This example increments the output bytes of all detected slaves every tick. It is tested on an EK1100 with output modules but may work on other basic slave devices.

Run with e.g.


RUST_LOG=debug cargo run --example ek1100 --release -- eth0


$env:RUST_LOG="debug" ; cargo run --example ek1100 --release -- '\Device\NPF_{FF0ACEE6-E8CD-48D5-A399-619CD2340465}'
use env_logger::Env;
use ethercrab::{
    error::Error, std::tx_rx_task, Client, ClientConfig, PduStorage, SlaveGroup, Timeouts,
use std::{sync::Arc, time::Duration};
use tokio::time::MissedTickBehavior;

/// Maximum number of slaves that can be stored. This must be a power of 2 greater than 1.
const MAX_SLAVES: usize = 16;
/// Maximum PDU data payload size - set this to the max PDI size or higher.
const MAX_PDU_DATA: usize = 1100;
/// Maximum number of EtherCAT frames that can be in flight at any one time.
const MAX_FRAMES: usize = 16;
/// Maximum total PDI length.
const PDI_LEN: usize = 64;

static PDU_STORAGE: PduStorage<MAX_FRAMES, MAX_PDU_DATA> = PduStorage::new();

async fn main() -> Result<(), Error> {

    let interface = std::env::args()
        .expect("Provide network interface as first argument.");

    log::info!("Starting EK1100 demo...");
    log::info!("Ensure an EK1100 is the first slave, with any number of modules connected after");
    log::info!("Run with RUST_LOG=ethercrab=debug or =trace for debug information");

    let (tx, rx, pdu_loop) = PDU_STORAGE.try_split().expect("can only split once");

    let client = Arc::new(Client::new(
        Timeouts {
            wait_loop_delay: Duration::from_millis(2),
            mailbox_response: Duration::from_millis(1000),

    tokio::spawn(tx_rx_task(&interface, tx, rx).expect("spawn TX/RX task"));

    let mut group = client
        .init_single_group::<MAX_SLAVES, PDI_LEN>()

    log::info!("Discovered {} slaves", group.len());

    for slave in group.iter(&client) {
        // Special case: if an EL3004 module is discovered, it needs some specific config during
        // init to function properly
        if slave.name() == "EL3004" {
            log::info!("Found EL3004. Configuring...");

            slave.sdo_write(0x1c12, 0, 0u8).await?;
            slave.sdo_write(0x1c13, 0, 0u8).await?;

            slave.sdo_write(0x1c13, 1, 0x1a00u16).await?;
            slave.sdo_write(0x1c13, 2, 0x1a02u16).await?;
            slave.sdo_write(0x1c13, 3, 0x1a04u16).await?;
            slave.sdo_write(0x1c13, 4, 0x1a06u16).await?;
            slave.sdo_write(0x1c13, 0, 4u8).await?;

    let mut group = group.into_op(&client).await.expect("PRE-OP -> OP");

    for slave in group.iter(&client) {
        let (i, o) = slave.io_raw();

            "-> Slave {:#06x} {} inputs: {} bytes, outputs: {} bytes",

    let mut tick_interval = tokio::time::interval(Duration::from_millis(5));

    loop {

        // Increment every output byte for every slave device by one
        for slave in group.iter(&client) {
            let (_i, o) = slave.io_raw();

            for byte in o.iter_mut() {
                *byte = byte.wrapping_add(1);



We're on Matrix!

Current and future features

  • async API
  • Usable in no_std contexts with no allocator required, as long as an async executor is available.
  • Autoconfigure slaves from their EEPROM (SII) data during startup
    • Supports configuration using CoE data
  • Safely usable in multi-threaded Linux systems with e.g. smol, tokio or std::thread and block_on.
  • Support for SDO read/writes to configure slave devices
  • Distributed clocks
    • Detection of delays between slave devices in topology
    • Static drift compensation on startup
    • Cyclic synchronisation during OP
  • Basic support for CiA402/DS402 drives
    • A higher level DS402 API for torque, position and velocity control of common servo drives in a more abstract way.
  • Integration with LinuxCNC as a HAL component using the linuxcnc-hal crate.
  • Load slave configurations from ESI XML files


GitHub Sponsors

Thank you to everyone who has donated test equipment, time or money to the EtherCrab project! Would you like to be in this list? Then please consider becoming a Github sponsor!

  • @nealsjoe generously donated an EK1100 with several IO modules for testing with.
  • Trisk Bio generously donated some additional Beckhoff modules and some optical ethernet gear.
  • Smark sent a $200 one time donation. Thank you!


Licensed under either of

at your option.


~251K SLoC