This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] TDA4VM: How do I build the native IgH EtherCAT stack for TI microprocessors?

Part Number: TDA4VM
Other Parts Discussed in Thread: AM69

Tool/software:

The IgH EtherCAT stack is an open source EtherCAT stack.

It comes with a generic driver that uses generic Linux ethernet API calls, but is not optimized for specific platforms, and therefore comes with latency.

How do I build the IgH EtherCAT stack with a native driver that is more optomized for TI microprocessors?

  • Building and Testing the IgH EtherCAT Stack

    1. Requirements

    1.1. Hardware Requirements

    Note: the IgH stack has only been verified on kernel version 6.1 and the SK-TDA4VM platform. The following steps should carry over for other AM6x platforms.

    Item Quantity Description
    SK-TDA4VM 1 device to act as EtherCAT master
    Beckhoff Slave Devices 1+ devices to act as EtherCAT slaves
    Ethernet cables 1+ N/A

    1.2. Software Requirements

    The following software versions were what were used to test the stack. They are not strict requirements, but the stack hasn't been verified on other variations.

    Item Version Description
    aarch64-none-linux-gnu toolchain 12.3 cross compiler toolchain
    ti-linux-kernel ti-linux-6.1.y kernel source
    ti-am65-cpsw-nuss IgH fork ti-am65-cpsw-nuss_6.1_6.6 branch repo for the am65-cpsw-nuss IgH driver (specifically the branch that is based off of the ti-linux-6.1.y branch)
    J721 default image 09.02.00.005 default image initially flashed to the SD card

    The following is additional software that was written.

    Item Description Link to File
    0001-am65-cpsw-switchdev.c-export-switchdev-functions.patch patch for switchdev functions 3808.0001-am65-cpsw-switchdev.c-export-switchdev-functions.patch
    0002-ti_am65_cpsw_nuss-.config-add-am65_cpsw_nuss-module-.patch patch for config fragments 3808.0002-ti_am65_cpsw_nuss-.config-add-am65_cpsw_nuss-module-.patch
    0003-soc-ti-k3-ringacc-Add-check-for-DMA-descriptor.patch patch for adding a check to ensure DMA descriptors are not stale 3808.0003-soc-ti-k3-ringacc-Add-check-for-DMA-descriptor.patch
    setup_host.sh setup script for the host 3808.setup_host.sh
    setup_target.sh setup script for the target 6523.setup_target.sh

    2. Setup

    Notesetup_host.sh executes all of the steps from sections 2.2 to 2.8.

    2.1. Flash the SD Card

    The default image can be generated by building the tisdk-default-image with Yocto. The steps to do this can be found within the 1.2. Building the SDK with Yocto¶ section of the PROCESSOR-SDK-LINUX-J721E documentation.

    2.2. Install the Toolchain and Export Variables

    $ wget https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
    $ tar -xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
    $ export ARCH=arm64
    $ export CROSS_COMPILE=$PWD/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
    

    2.3. Clone the Repositories

    $ git clone -b ti-linux-6.1.y https://git.ti.com/git/ti-linux-kernel/ti-linux-kernel.git
    $ git clone -b ti-am65-cpsw-nuss_6.1_6.6 https://gitlab.com/npitre/ethercat.git
    

    2.4. Patch the ti-linux-kernel

    Apply the following patches to the kernel.

    1. The switchdev patch exports a couple functions that are required for the native EtherCAT driver to build.
    2. The config fragment patch adds two config fragments that make building the necessary kernel images easier.
    3. The DMA descriptor patch ensures that the DMA descriptors are not stale and cause a kernel panic

    $ cd ti-linux-kernel
    $ git am 0001-am65-cpsw-switchdev.c-export-switchdev-functions.patch
    $ git am 0002-ti_am65_cpsw_nuss-.config-add-am65_cpsw_nuss-module-.patch
    $ git am 0003-soc-ti-k3-ringacc-Add-check-for-DMA-descriptor.patch $ cd ../

    2.5. Build the Kernel without the am65-cpsw-nuss Driver

    The kernel must be built without the am65-cpsw-nuss driver for the ethercat driver to build correctly off of the kernel source. If the driver is built off of a kernel with the am65-cpsw-nuss driver compiled (even as a module), running the stack will spit out this error:

    [   31.207060] Error: Driver 'am65-cpsw-nuss' is already registered, aborting...
    [   31.248259] am65-cpsw-nuss 46000000.ethernet eth0: PHY [46000f00.mdio:00] driver [TI DP83867] (irq=POLL)
    [   31.257775] am65-cpsw-nuss 46000000.ethernet eth0: configuring for phy/rgmii-rxid link mode
    modprobe: ERROR: could not insert 'ec_ti_am65_cpsw_nuss': Device or resource busy
    
    $ cd ti-linux-kernel
    $ make defconfig ti_arm65_prune.config ti_am65_cpsw_nuss_remove.config
    $ make -j`nproc` Image modules
    $ sudo cp arch/arm64/boot/Image /media/`whoami`/root/boot/
    $ make INSTALL_MOD_PATH=/media/`whoami`/root/ modules_install
    $ cd ../
    

    2.6. Build the Native EtherCAT Driver

    $ cd ethercat
    $ ./bootstrap
    $ ./configure \
      --sysconfdir=/opt/etherlab --prefix=/opt/etherlab --with-linux-dir=$PWD/../ti-linux-kernel \
      --with-module-dir=/etherlab --enable-generic=no --enable-8139too=no --enable-eoe=no \
      --host=aarch64-none-linux-gnu --target=aarch64-none-linux-gnu \
      --enable-am65cpsw=yes --with-am65cpsw-kernel=6.1
    $ make -j`nproc`
    $ make -j`nproc` modules
    $ sudo chown -R `whoami` /media/`whoami`/root/
    $ make DESTDIR=/media/`whoami`/root/ install
    $ make INSTALL_MOD_PATH=/media/`whoami`/root/ modules_install
    $ cd ../
    

    2.7. Build the Kernel with the am65-cpsw-nuss Driver as a Module

    When starting the stack, if the module isn't present, the board will repeatedly spit out the following error:

    [ 647.879844] davinci_mdio 46000f00.mdio: davinci mdio revision 9.7, bus freq 1000000
    [ 647.890842] davinci_mdio 46000f00.mdio: phy[0]: device 46000f00.mdio:00, driver TI DP83867
    [ 647.899139] am65-cpsw-nuss 46000000.ethernet: initializing am65 cpsw nuss version 0x6BA02102, cpsw version 0x6BA82102 Ports: 2 quirks:00000000
    [ 647.911920] am65-cpsw-nuss 46000000.ethernet: /bus@100000/bus@28380000/ethernet@46000000/ethernet-ports/port@1 error retrieving port phy: -517
    
    $ cd ti-linux-kernel
    $ make defconfig ti_arm64_prune.config ti_am65_cpsw_nuss_module.config
    $ make -j`nproc` Image modules
    $ sudo cp arch/arm64/boot/Image /media/`whoami`/root/boot/
    $ sudo make INSTALL_MOD_PATH=/media/`whoami`/root/ modules_install
    $ cd ../
    

    2.8. Copy the Setup Script onto the Target

    The setup script sets the required variables within the ethercat.conf and blacklists the am65-cpsw-nuss module. If the module isn't blacklisted, the following error will appear.

    Starting EtherCAT master 1.6.0 [  25.397960] ec_master: loading out-of-tree module taints kernel.
    [  25.406605] EtherCAT: Master driver 1.6.0 1.6-alpha-51-gf3400a0f
    [  25.412783] EtherCAT: 1 master waiting for devices.
    [  25.441597] Error: Driver 'am65-cpsw-nuss' is already registered, aborting...
    modprobe: ERROR: could not insert 'ec_ti_am65_cpsw_nuss': Device or resource busy
     failed
    
    $ cp setup_target.sh /media/`whoami`/root/home/root/
    

    2.9. Boot the Target and run the Setup Script

    The following are the commands executed by the setup script.

    $ echo "blacklist ti-am65-cpsw-nuss" > /etc/modprobe.d/blacklist.conf
    $ sed -i 's/\(MASTER0_DEVICE="\).*/\1'`ifconfig | awk -F"[ ]+" '/ether/{print $3}'`'"/' /opt/etherlab/ethercat.conf
    $ sed -i 's/\(DEVICE_MODULES="\).*/\1ti-am65-cpsw-nuss"/' /opt/etherlab/ethercat.conf
    $ reboot
    
    $ ./setup_script.sh
    

    3. Execution

    Connect the EtherCAT slave devices, then run the following.

    $ /opt/etherlab/sbin/ethercatctl start
  • Hello, I want to port Ethercat master on AM69, but I only see the Ethercat repository for ti-am65-cpsw-nuss_6.1_6.6, not for AM69.

  • Hi,

    If you have a question, please create a new thread instead of replying to the FAQ.

    Best,
    Jared