A Detailed Guide to Porting EtherCAT on the Forlinx OKMX6ULx Platform

EtherCAT (Ethernet for Control Automation Technology) is a high-performance industrial Ethernet protocol, widely used in fields that require real-time performance, high synchronization accuracy, and efficient data transmission. This article introduces how to port EtherCAT on the Forlinx OKMX6ULx series platforms. This method is based on IGH EtherCAT, which is an open-source master protocol stack compliant with the EtherCAT international standard. It is specifically designed for the Linux system and supports efficient management and control of EtherCAT slave devices.

Its core features include:

  • Open-source and low cost: Based on the LGPL license, it does not require dedicated hardware or licensing fees, making it suitable for rapid prototype verification‌.
  • Real-time communication: Supports nanosecond - level synchronization accuracy and reduces transmission delay through Distributed Clock (DC) technology‌.
  • Flexible topology: Supports any network topologies such as linear, tree, and star, and can connect up to 65,535 nodes at most‌.

1. Source Code Download

1.1 Select the 1.6 stable version for download. Other versions can be downloaded from the official GitLab.

https://gitlab.com/etherlab.org/ethercat/-/archive/stable-1.6/ethercat-stable-1.6.tar.gz

1.2 Copy it to the development environment provided by Forlinx and decompress it.

tar -xvf ethercat-stable-1.6.tar.gz
cd ethercat-stable-1.6

2. Cross-porting

2.1 Execute the environment variables and run bootstrap to generate the configure file.

forlinx@ubuntu:~/111/ethercat-stable-1.6$ sudo -s
forlinx@ubuntu:~/111/ethercat-stable-1.6$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi 
forlinx@ubuntu:~/111/ethercat-stable-1.6$./bootstrap

2.2 Execute configure to generate and compile the Makefile

forlinx@ubuntu:~/111/ethercat-stable-1.6$ ./configure --prefix=$PWD/__install --with-linux-dir=/home/forlinx/work/linux-4.1.15/ --enable-8139too=no --enable-generic=yes --host=arm-poky-linux-gnueabi
forlinx@ubuntu:~/111/ethercat-stable-1.6$ make
forlinx@ubuntu:~/111/ethercat-stable-1.6$ make install

Note: --with-linux-dir = The following path is the Linux source path

2.3 ethercat driver compilation

root@ubuntu:~/111/ethercat-stable-1.6# make modules

The driver has been generated.

root@ubuntu:~/111/ethercat-stable-1.6# find -name *.ko
./master/ec_master.ko
./devices/ec_generic.ko
./examples/mini/ec_mini.ko

3. Functions Test

3.1 Package and copy files to the development board

Ubuntu development environment:

root@ubuntu:~/111/ethercat-stable-1.6# cd __install/
root@ubuntu:~/111/ethercat-stable-1.6/__install# tar -cjvf ethercat.tar.bz2 *

Development Board

root@fl-imx6ull:~# tar -xvf /run/media/sda1/ethercat.tar.bz2 -C /
root@fl-imx6ull:~# cp /run/media/sda1/ec_generic.ko /lib/modules/4.1.15-00076-g448d07c/
root@fl-imx6ull:~# cp  /run/media/sda1/ec_master.ko /lib/modules/4.1.15-00076-g448d07c/
root@fl-imx6ull:~# sync

3.2 Add udev rule

root@fl-imx6ull:~# echo KERNEL==\"EtherCAT[0-9]*\", MODE=\"0664\" > /etc/udev/rules.d/99-EtherCAT.rules

3.3 View the network card mac

root@fl-imx6ull:~# ifconfig
eth0      Link encap:Ethernet  HWaddr E2:14:B0:1D:7C:CB
          inet addr:192.168.0.232  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::e014:b0ff:fe1d:7ccb%1996035792/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4325 errors:0 dropped:267 overruns:0 frame:0
          TX packets:71 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1296750 (1.2 MiB)  TX bytes:10368 (10.1 KiB)
eth1      Link encap:Ethernet  HWaddr D2:E1:14:B0:1D:7C
          inet addr:192.168.1.232  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%1996035792/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

3.4 Modify/etc/sysconfig/ethercat

vi /etc/sysconfig/ethercat
Modify:
MASTER0_DEVICE=""
to:
MASTER0_DEVICE="E2:14:B0:1D:7C:CB"

3.5 Run the ethercat service and load the driver

Restart the board

root@fl-imx6ull:~# /etc/init.d/ethercat start
root@fl-imx6ull:~# insmod /lib/modules/4.1.15-00076-g448d07c/ec_generic.ko

3.6 Ethercat as master

root@fl-imx6ull:~# ethercat master
Master0
  Phase: Waiting for device(s)...
  Active: no
  Slaves: 0
  Ethernet devices:
    Main: e2:14:b0:1d:7c:cb (waiting...)
      Link: DOWN
      Tx frames:   0
      Tx bytes:    0
      Rx frames:   0
      Rx bytes:    0
      Tx errors:   0
      Tx frame rate [1/s]:      0      0      0
      Tx rate [KByte/s]:      0.0    0.0    0.0
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
    Common:
      Tx frames:   0
      Tx bytes:    0
      Rx frames:   0
      Rx bytes:    0
      Lost frames: 0
      Tx frame rate [1/s]:      0      0      0
      Tx rate [KByte/s]:      0.0    0.0    0.0
      Rx frame rate [1/s]:      0      0      0
      Rx rate [KByte/s]:      0.0    0.0    0.0
      Loss rate [1/s]:          0      0      0
      Frame loss [%]:         0.0    0.0    0.0
  Distributed clocks:
    Reference clock:   None
    DC reference time: 0
    Application time:  0
    2000-01-01 00:00:00.000000000



Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!