AM243x MCU+ SDK  08.00.00
EtherCAT Slave Setup with TwinCAT

Creating TwinCAT Project

  • Install TwinCAT3. A 7 days free trial license is available for free download from the Beckhoff's website. Select the eXtended Automation Engineering (XAE) mode of installation.
  • Copy the ESI file to {TWINCAT_INSTALL_DIR}\TwinCAT\3.1\Config\Io\EtherCAT folder.
    • ESI file for EtherCAT Slave application based on ETG stack is ${SDK_INSTALL_PATH}/source/industrial_protocols/ethercat_slave/beckhoff_stack/esi/TI_ESC.xml
  • Start the TwinCAT XAE Shell application.
  • Create a new TwinCAT XAE Project (XML format) by going to "File -> New -> Project -> TwinCAT Project"

    Creating a new TwinCAT Project
  • Go to "TwinCAT -> Show Real Time Ethernet Compatible Devices and Install TwinCAT RT Ethernet intermediate driver". For best performance, it is recommended to use a compatible NIC card listed in Supported Network Controller by Beckhoff Ethernet Driver . For the first time only you need to set the PC’s Ethernet port, which is used as the EtherCAT port. Go to "TwinCAT -> Show Realtime Ethernet Compatible Devices"

Note
Please check if the ethernet adapter is listed below "Installed and ready to use devices" before attempting to scan the slave. A tip, if your computer go to sleep and after awake it TwinCAT lost connection with slave(s) and/or is not able to discover EtherCAT IO devices, you can fix this issue by going in TwinCAT to your Ethernet adapters, and Disabling / Enabling your NIC.
  • Connect Ethernet cable from PC running TwinCAT to EtherCAT IN/Port0 of the PRU-ICSS on the EVM. If you have multiple devices in chain, please connect from EtherCAT OUT/Port1 to IN/Port0 of next device. For the last device in chain, OUT/Port1 will be left open (if NOT using redundancy mode).
AM243X-EVM
AM243X-LP

Scanning the slave

  • On powering up the AM243x-EVM and loading the application, you should see digital output LEDs 2, 4, 6 and 7 on. This indicates that slave is up and in INIT state.
  • On powering up the AM243x-LP and loading the application, you should see digital output LEDs 2 and 4 on. This indicates that slave is up and in INIT state.
  • In Solution Explorer, go to "TwinCAT project -> I/O -> Devices". Right click on Devices and select Scan. Press OK in the next dialog to start scanning for EtherCAT devices.

  • Once an EtherCAT compatible device has been detected on this Ethernet port, the following dialog shows up. Note that there is a tick mark next to the adapter to which the EVM is connected. Press OK and confirm to start "Scan for boxes".

  • TI Box n(TIESC) will be detected automatically. The TI device will be listed "Box n (TIESC-*)". Press Yes to activate Free Run. This will put TI ESC into OP mode. TIESC number is based on the platform and application. Please check the ESI file for more details.

  • The EtherCAT device state can be displayed by selecting a Device (Double click on Device) and then selecting the Online tab. The device should be in the OP state with no Lost Frames or Tx/Rx Errors.

  • The user can control 8 digital out LEDs using TwinCAT. LED[0] to LED[7] in "Box n (TIESC-*) -> DO Outputs -> LED". Each LED can be turned on and off by selecting "Online write 1" and "Online write 0" respectively.

  • Above steps test the slave in Free Run Operation Mode. For testing Distributed Clock (DC) Synchronization mode, refer to the Testing DC Synchronization mode section.

Testing DC Synchronization mode

  • Launch TwinCAT XAE Shell application and discover all the slaves in slave chain. Multiple slaves are required to make use of distributed clocks. Here, we used two devices in the chain.
  • Choose DC Synchronization for all devices in the chain. Click on Box n (TIESC-*). Open the DC tab, and choose DC-Synchron option in Operation Mode. Do this for all slaves in the chain.

  • In Solution Explorer, go to TwinCAT project, select "SYSTEM -> Real-Time". In the Settings tab, choose the desired Base Time. With compatible NIC cards, a base time of as low as 50 us can be chosen.

  • Right-click on "SYSTEM -> Tasks". Click "Add New Item" on the pop-up menu. Select "TwinCAT Image with Task" in the next dialog box. Type a name for the task, and choose OK.

  • In the "Task" tab for the created task, select Auto Priority Management. Press OK in dialog box saying "Global Priority Management should be turned on".
  • Choose "Auto start" for the task. Choose 2 cycle ticks’ frequency for the task.

  • Add an output variable to the task. Right-click on "[Task name] -> Outputs", and choose "Add New Item". You may choose default options for the variable.

  • Link the variable to an output for the last slave in the chain. Right-click on [Variable name], and choose "Change Link...".

  • Choose an output from the last slave. You may need to choose "All Types" in "Show Variable Types".

  • You can launch into Run mode by clicking the "Activate Configuration" button on the toolbar.
  • Choose Yes to generate mapping after modifying configuration, click on OK to "Activate Configuration?", and Yes to Restart in RUN mode.

Generating ESI Header file From ESI XML file

EtherCAT Slave Beckhoff SSC Example is expected to be used with ${SDK_INSTALL_PATH}/source/industrial_protocols/ethercat_slave/beckhoff_stack/esi/TI_ESC.xml file. If the application is modified to work with a different ESI XML file, user will need to update the corresponding ESI header file (tiesc_eeprom.h) and rebuild the application project.

  • Generate the binary file equivalent to ESI XML file:
    • Configure TwinCAT as mentioned in Creating TwinCAT Project and Scanning the slave.
    • Click on the TI Box. Select "EtherCAT" Tab. Click on the "Advanced Settings" button.
    • Select "ESC Access -> E2PROM -> Hex Editor". Select "Write to File" and save the binary as a ".bin" file.
Note
Please make sure that "Upload" button is not clicked any time during this step. It will load the EEPROM data from TI ESC to TwinCAT memory.
  • Convert the binary file to header file using the bin2c tool. This tool can be found in ${SDK_INSTALL_PATH}/tools/bin2c folder. Example usage is shown below.
    python ${SDK_INSTALL_PATH}/tools/bin2c/bin2c.py "Box 1 (TIESC-004).bin" new_tiesc_eeprom.c new_tiesc_eeprom
  • For AM243X-EVM, replace the contents within "const unsigned char tiesc_eeprom[]" array in ${SDK_INSTALL_PATH}/examples/industrial_protocols/ethercat_slave_beckhoff_ssc_demo/am243x-evm/tiesc_eeprom.h file with the data generated in new_tiesc_eeprom.h file within the brackets following "#define NEW_TIESC_EEPROM".
  • For AM243X-LP, replace the contents within "const unsigned char tiesc_eeprom[]" array in ${SDK_INSTALL_PATH}/examples/industrial_protocols/ethercat_slave_beckhoff_ssc_demo/am243x-lp/tiesc_eeprom.h file with the data generated in new_tiesc_eeprom.h file within the brackets following "#define NEW_TIESC_EEPROM".
Note
Please do not directly replace the existing tiesc_eeprom.h file with new header file.
  • Rebuild the application.

Online Application Upgrade

Note
Application should be loaded with SBL OSPI method to test this feature using following steps
  • Configure TwinCAT as mentioned in Creating TwinCAT Project and Scanning the slave.
  • Click on TI Box. Select "Online" tab.
  • Click "Bootstrap" button. This will take the Slave to BOOT state.

  • Once the state has changed to "BOOT", Click "Download" button.

  • Rename your EtherCAT application binary (.appimage file) as ECATFW__, and use this file as your new EtherCAT application.

  • Locate the new application to be dowloaded click "Open".
  • Click OK on the new dialog shown.

  • This will download the new application. The progress bar will show the status of download.
  • Once the download has finished, change the state back to "Init" by clicking "Init" button.
  • Perform a warm reset by writing "RST"(0x545352) or "rst"(0x747372) to ESC Reset(0x0E14-0x0E17) register to reload the application. Power restart of the EVM will also load the new application.