The IgH EtherCat Master can be build and installed on a single-board computer (SBC) like the BeagleBone Black or the Raspberry Pi. The 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.
The username is debian, the hostname SBC. Install needed tools for building on target:
debian@SBC:~$ sudo apt-get update
debian@SBC:~$ sudo apt-get install git autoconf libtool
Install PREEMPT_RT
patched kernel and sources on BBB. Write the current running kernel config to the kernel sources:
debian@SBC:~$ sudo apt-get install linux-image-5.10.100-ti-rt-r40
debian@SBC:~$ sudo apt-get install linux-headers-5.10.100-ti-rt-r40
Alternatively if there are no kernel headers available, install the linux sources (huge!):
debian@SBC:~$ sudo apt-get install linux-source
debian@SBC:~$ cd /usr/src
debian@SBC:/usr/src $ sudo xz -d linux-source-5.10.tar.xz
debian@SBC:/usr/src $ sudo tar -xvf linux-source-5.10.tar
debian@SBC:/usr/src $ sudo sh -c 'zcat /proc/config.gz > ./linux-source-5.10/.config'
debian@SBC:/usr/src $ sudo sh -c 'uname -r > ./linux-source-5.10/.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.
Fetch IgH EtherCat sources to the target and configure.
--with-linux-dir optional: should point to the kernel sources installed before, otherwise omit argument
debian@SBC:~$ git clone https://gitlab.com/etherlab.org/ethercat.git
debian@SBC:~$ cd ethercat
debian@SBC:~/ethercat$ git checkout -b stable-1.5 --track origin/stable-1.5
debian@SBC:~/ethercat$ echo "AUTOMAKE_OPTIONS = subdir-objects" >> tool/Makefile.am
debian@SBC:~/ethercat$ ./bootstrap
debian@SBC:~/ethercat$ ./configure --enable-generic --disable-8139too --with-linux-dir=/usr/src/linux-source-5.10
First a kernel module build from the unneeded examples must be removed, then kernel module build can be started:
debian@SBC:~/ethercat/ sed -i '\/obj-m := mini\//d' ./examples/Kbuild.in
debian@SBC:~/ethercat/ $ make modules && sudo make modules_install && sudo depmod
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
.
debian@SBC:~/ethercat/lib $ make all && sudo make install
debian@SBC:~/ethercat/include $ sudo make install
The libraries are installed per default into /usr/local/lib
. This directory must be assigned to CMAKE_PREFIX_PATH when invoking cmake from the project which is dependent on the EtherCat libraries.
debian@SBC:~/ECT60ctrl/build $ cmake .. -DCMAKE_PREFIX_PATH=/usr/local/lib
Build tools (ethercat-CLI) and install:
debian@SBC:~/ethercat/tool $ make all
debian@SBC:~/ethercat/tool $ 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
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:
debian@SBC:~/$ 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:
debian@SBC:~$ 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
:
debian@SBC:~$ sudo ethercatctl start
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