Beckhoff / CCAT

Beckhoff CCAT FPGA Kernel mode driver to run EtherCAT Master on CX devices
Other
34 stars 16 forks source link

Using CCAT on a CX2030 running Ubuntu #3

Closed jdugge closed 7 years ago

jdugge commented 7 years ago

We are trying to get a Beckhoff CX2030 Industrial PC running Ubuntu to accept input from Beckhoff EL3024 modules using Etherlab with the CCAT modules. However, we haven't been able to initialise the EtherCAT connection, the EtherCAT messages stop at EtherCAT: 1 master waiting for devices.

Could you give us a hand troubleshooting this issue? Below are the steps we took to install Etherlab and CCAT on a clean Ubuntu 14.04.5 install on the CX2030.

  1. Install Ubuntu Server 14.04.5 64bit
  2. Install build tools sudo apt install mercurial automake libtool build-essential
  3. Download Etherlab and CCAT
    wget http://etherlab.org/download/ethercat/ethercat-1.5.2.tar.bz2
    tar -xjf ethercat-1.5.2.tar.bz2
    hg update stable-1.5
    wget https://github.com/Beckhoff/CCAT/raw/master/etherlab.bundle
    hg unbundle etherlab.bundle
    hg update
    ./bootstrap
  4. Build Etherlab
    ./configure --disable-8139too --enable-ccat
    make
    make modules
    sudo make install
    sudo make modules_install

    The last line raises the following error, but apparently that can be ignored

testuser@ubuntu:~/ethercat-hg$ sudo make modules_install
make -C "/usr/src/linux-headers-4.4.0-31-generic" M="/home/testuser/ethercat-hg" \
                INSTALL_MOD_DIR="ethercat" modules_install
make[1]: Entering directory `/usr/src/linux-headers-4.4.0-31-generic'
  INSTALL /home/testuser/ethercat-hg/devices/ccat/ec_ccat.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:169
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:172
sign-file: certs/signing_key.pem: No such file or directory
  INSTALL /home/testuser/ethercat-hg/devices/ec_generic.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:169
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:172
sign-file: certs/signing_key.pem: No such file or directory
  INSTALL /home/testuser/ethercat-hg/examples/mini/ec_mini.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:169
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:172
sign-file: certs/signing_key.pem: No such file or directory
  INSTALL /home/testuser/ethercat-hg/master/ec_master.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:169
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:172
sign-file: certs/signing_key.pem: No such file or directory
  DEPMOD  4.4.0-31-generic
make[1]: Leaving directory `/usr/src/linux-headers-4.4.0-31-generic'

Continue installation:

sudo depmod
sudo mkdir /etc/sysconfig
sudo cp /opt/etherlab/etc/sysconfig/ethercat /etc/sysconfig
sudo ln -s /opt/etherlab/etc/init.d/ethercat /etc/init.d/

Edit /etc/sysconfig/ethercat:

#------------------------------------------------------------------------------
#
#  EtherCAT master sysconfig file
#
#  $Id$
#
#  vim: spelllang=en spell tw=78
#
#------------------------------------------------------------------------------

MASTER0_DEVICE="00:01:05:2b:b0:35"
DEVICE_MODULES="ccat"

#------------------------------------------------------------------------------
  1. Pull up the interface

    sudo ifconfig eth0 192.168.100.164 up
  2. Start ethercat:

    sudo /etc/init.d/ethercat start
  3. Check the status with dmesg:

    [  216.979012] EtherCAT: Master driver 1.5.2 a1079c6242a5
    [  216.979117] EtherCAT: 1 master waiting for devices.

And that's where it stops. Ethercat is never able to

If I use the generic module instead, ethercat at least recognises that there are slaves on the bus, but the initialisation doesn't complete successfully:

[   77.947636] EtherCAT: Master driver 1.5.2 a1079c6242a5
[   77.948481] EtherCAT: 1 master waiting for devices.
[   77.952178] ec_generic: EtherCAT master generic Ethernet device module 1.5.2                                                                                                a1079c6242a5
[   77.952193] EtherCAT: Accepting 00:01:05:2B:B0:35 as main device for master 0                                                                                               .
[   77.952207] ec_generic: Binding socket to interface 2 (eth0).
[   77.961825] EtherCAT 0: Starting EtherCAT-IDLE thread.
[   77.961865] EtherCAT 0: Link state of ecm0 changed to UP.
[   77.965837] EtherCAT 0: 2 slave(s) responding on main device.
[   77.965841] EtherCAT 0: Slave states on main device: INIT.
[   77.966014] EtherCAT 0: Scanning bus.
[   78.267722] EtherCAT WARNING 0: 1 frame CORRUPTED!
[   78.297973] EtherCAT ERROR 0-1: Failed receive FMMU clearing datagram.
[   78.298020] EtherCAT 0: Bus scanning completed in 332 ms.
[   78.298022] EtherCAT 0: No DC reference clock found.
[   78.337994] EtherCAT ERROR 0-0: Failed receive FMMU clearing datagram.
[   78.374011] EtherCAT ERROR 0-1: Failed receive FMMU clearing datagram.
[   78.414032] EtherCAT ERROR 0-0: Failed receive FMMU clearing datagram.
[   78.450049] EtherCAT ERROR 0-1: Failed receive FMMU clearing datagram.
pbruenn commented 7 years ago

Two things you could try:

  1. try sudo /etc/init.d/ethercat restart
  2. I suspect the EtherLab tarball to be outdate try to use: hg clone http://hg.code.sf.net/p/etherlabmaster/code ethercat-hg hg pull might work, too.

As a side note: sudo ifconfig eth0 192.168.100.164 up is just for debugging and development, of the pure (not EtherLab integrated) driver. In EtherCAT operation mode there is no IP traffic on the ccat ethernet device.

Update: MAC address should be fine as it is working with the generic driver.

jdugge commented 7 years ago

Thanks for getting back to me so quickly!

Unfortunately, that didn't work. I had actually already been using the current version of Etherlab from the Mercurial repository, the step of downloading the tarball shouldn't have been in my problem description. Sorry for that!

Do I need to update the CCAT firmware (I noticed that there's an update_ccat.sh script in the CCAT repository)? I guess not, since this is a brand new CX2030, so the firmware is probably already up to date?

Would it help in narrowing down the problem if I got the CCAT unit tests to run? At the moment, the rw_gpio scripts fail because /sys/class/gpio only contains an export and unexport file, but no gpio<number> subdirectories. Is this an indicator of something being wrong on my setup?

pbruenn commented 7 years ago

Ah, I am pretty sure I know what your problem is. Kernel 3.15 got a new driver ec_bhf and Ubuntu recently upgraded to a newer kernel. ec_bhf is a driver for the CCAT FPGA and was developed by Darek Marcinkiewicz, who isn't associated with Beckhoff in any way. Unfortunately his (ec_bhf) and our (ccat) driver, were developed at the same time without knowing of each other. So Darek pushed it to the kernel in an very early stage. And by luck it was accepted by upstream kernel. Unfortunately, ec_bhf only supports basic ethernet functionality to work with SOEM another open source EtherCAT Master like EtherLab. So you can't use it without adjustments to run with EtherLab. If you are okay by using SOEM, I think you could just use that driver. If you want to use EtherLab my suggestion would be to get rid of ec_bhf and replace it with ccat/ec_ccat. I would:

# unload ec_bhf
sudo rmmod ec_bhf
# blacklist ec_bhf (beware it might be included in your initramfs)
echo "blacklist ec_bhf" | sudo tee -a /etc/modpobe.d/blacklist.conf

Regards, Patrick Bruenn p.s.: Don't get me wrong. My favorite solution would be to advance ec_bhf so that you cold easily use it with EtherLab. But in practice that's a very very difficult work (at least for us). The first thing is the naming convention. The EtherLab version of ec_bhf would be named ec_ec_bhf. The next thing is ec_bhf only supports the Ethernet functionality of the CCAT FPGA. So ccat has some amount of infrastructure code, which needs to be ported to kernel FPGA infrastructure. We as Beckhoff just don't have the reputation (and experience) in the Linux kernel community to get such changes into upstream. Of course, in the long run that's what we want to do. But at the moment the reality is that even small changes to add board support for our products to U-Boot are not accepted by the community.

jdugge commented 7 years ago

Fantastic, Patrick, that was it! Removing the ec_bhf module did the trick. It works like a charm now: The connection is initialised, I can change the slaves' states, and read data from the inputs.

Thank you for your help in resolving this so quickly, and for the detailed explanations!