The IgH EtherCat Master can be build from sources on the target like a BeagleBone Black, which is a single-board computer (SBC) similar to the Raspberry Pi. This should work on a regular PC too. The EtherCat master is using the Ethernet interface to connect to the EtherCat slaves, so an additional ethernet connection like WLAN is needed to login, install, build and setup all needed components. A realtime kernel must be used to operate EtherCat on time critical tasks like servo motor control.

Prerequisits

Logged in to the SBC, install needed tools for building on target:

sudo apt-get update
sudo apt-get install git autoconf libtool zstd

Install Linux kernel

Install PREEMPT_RT patched kernel and sources on BBB. Write the current running kernel config to the kernel sources:

sudo apt-get install linux-image-6.6.25-bone-rt-r14
sudo apt-get install linux-headers-6.6.25-bone-rt-r14

Alternatively if there are no kernel headers available, install the linux sources (huge!):

sudo apt-get install linux-source
cd /usr/src
sudo xz -d linux-source-6.6.tar.xz
sudo tar -xvf linux-source-6.6.tar
sudo sh -c 'zcat /proc/config.gz > ./linux-source-6.6/.config'
sudo sh -c 'uname -r > ./linux-source-6.6/.kernelrelease'

Unfortunately for the RPi there is no precompiled realtime patched kernel available in the armhf repos of the Raspberry Pi OS, so cross-compiling and installing a PREEMPT_RT patched kernel on a PC according this guide is necessary.

Get and configure IgH EtherCat

Fetch IgH EtherCat sources to the target and configure.

  • call configure --with-linux-dir optionally: should point to the kernel sources installed before, otherwise omit argument
git clone https://gitlab.com/etherlab.org/ethercat.git
cd ethercat
git checkout stable-1.6
echo "AUTOMAKE_OPTIONS = subdir-objects" >> tool/Makefile.am
./bootstrap
./configure --enable-generic --disable-8139too

Build and install EtherCat kernel modules

First a kernel module build from the unneeded examples must be removed, then kernel module build can be started:

sed -i '\/obj-m := mini\//d' ./examples/Kbuild.in
make modules && sudo make modules_install && sudo depmod

Building kernel modules on a BBB/RPi takes some time.

Build and install EtherCat libs

If you just want to build and install the EtherCat-libraries without kernel modules and examples, cd into ~/ethercat/lib/ and call make all. This also generates a EtherCATConfig.cmake which can be found by cmake find_package. For installing the includes, cd into ~/ethercat/include/ and call sudo make install.

cd ./lib
make all && sudo make install
cd ../include
sudo make install

The libraries are installed per default into /usr/local/lib. In case of building your own project dependent on the EtherCat libraries, the libraries path must be assigned to CMAKE_PREFIX_PATH when invoking cmake from the project.

<project dir> cmake .. -DCMAKE_PREFIX_PATH=/usr/local/lib

Build and install EtherCat tools

Build tools (ethercat-CLI) and install:

cd tool
make all
sudo make install

Cross build on a host

Alternatively build source cross compile against a kernel source in /home/debian/linux and install modules to mounted kernel directory on the the SBC:

debian@pc:~/$ mkdir piroot
debian@pc:~/$ sshfs root@pi:/ ~/piroot
debian@pc:~/$ cd ethercat
debian@pc:~/ethercat$ ./bootstrap
debian@pc:~/ethercat$ ./configure --with-linux-dir=/home/debian/linux --enable-generic --disable-8139too --host arm-linux-gnueabihf CFLAGS='-g -O0' CXXFLAGS='-g -O0'
debian@pc:~/ethercat$ export ARCH=arm
debian@pc:~/ethercat$ export CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf-
debian@pc:~/ethercat$ export INSTALL_MOD_PATH=~/piroot
debian@pc:~/ethercat$ make all modules
debian@pc:~/ethercat$ make doc
debian@pc:~/ethercat$ make modules_install

Setup IgH EtherCat

On the SBC add a udev rule for EtherCAT devices to /etc/udev/rules.d/99-EtherCAT.rules:

KERNEL =="EtherCAT[0-9]*" , SUBSYSTEM=="EtherCAT", MODE ="0664", GROUP ="users"

Reload the rules:

sudo udevadm control --reload-rules

Copy and edit /usr/local/etc/ethercat.conf. Use the MAC address of your eth0 device.

MASTER0_DEVICE="78:a5:04:c8:9e:12"
DEVICE_MODULES="generic"
LINK_DEVICES="eth0"

Set up ethercat NIC:

sudo ip link set eth0 up

The link can be set up permanently also by configuring the interface in /etc/network/interfaces.

iface eth0 inet manual
up ip link set eth0 up

Start ethercat service which generates the device file /dev/EtherCAT0:

sudo ethercatctl start

Test

First lets see, if device is created:

debian@SBC:~$ ls -la /dev/EtherCAT0
crw------- 1 root root 239, 0 13. Jan 12:01 /dev/EtherCAT0

Check master running:

debian@SBC:~$ sudo ethercat master
Master0
  Phase: Operation
  Active: yes
  Slaves: 0
  Ethernet devices:
    Main: b8:27:eb:0b:6e:ac (attached)
      Link: UP
      Tx frames:   699298
      Tx bytes:    41957880
      Rx frames:   0
      Rx bytes:    0
      Tx errors:   0
      Tx frame rate [1/s]:    200    268    434
      Tx rate [KByte/s]:     11.7   15.7   25.4
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
    Common:
      Tx frames:   699298
      Tx bytes:    41957880
      Rx frames:   0
      Rx bytes:    0
      Lost frames: 699298
      Tx frame rate [1/s]:    200    268    434
      Tx rate [KByte/s]:     11.7   15.7   25.4
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
      Loss rate [1/s]:        200    268    434
      Frame loss [%]:       100.0  100.0  100.0
  Distributed clocks:
    Reference clock:   None
    DC reference time: 0
    Application time:  0
                       2000-01-01 00:00:00.000000000

Detect slaves:

debian@SBC:~$ sudo ethercat slaves --verbose

Read SDO 0x6061 from slave alias 1001:

debian@SBC:~$ sudo ethercat upload -a1001 0x6061 0x0 --type int8

Previous Post