MCUXpresso SDK Documentation

ecat_foe#

Overview#

This example demonstrates how to develop EtherCAT FoE(File Access over EtherCAT) example based on Slave Stack Code(SSC).

Note that the demo CAN NOT be built directly. Please see the “Prepare the Demo” section for more details.

Running the demo#

When FoE upgrade is successful, the serial port will output:

	System reset...
	hello sbl.
	Bootloader Version 1.9.0
	Primary image: magic=good, swap_type=0x1, copy_done=0x3, image_ok=0x1
	Secondary image: magic=good, swap_type=0x1, copy_done=0x3, image_ok=0x3
	Boot source: none
	Swap type: test
	Starting swap using move algorithm.
	Bootloader chainload address offset: 0x40000
	Reset_Handler address offset: 0x40400
	Jumping to the image

   	Start the SSC FoE example...
   	Image version: 2.3.0
	Image state: testing
	Set image as confirmed: success

TwinCAT Setup#

To demonstrate this FoE example, TwinCAT is used as the EtherCAT MainDevice.

Supported Boards#

MIMXRT1180-EVK
Hardware requirements
  • MIMXRT1180-EVK RevC

  • RJ45 Network cable

  • Mini/micro USB cable

  • Personal Computer on which the TwinCat3 has been installed(Windows 10 is recommended)

Board settings

No special settings are required.

EEPROM LPI2C Emulator
  1. i.MX RT1180 supports EEPROM LPI2C emulator, please skip this chapter if you used EEPROM hardware.

  2. Hardware Setting

    • Connection:

      J51: pin4 <–> J44: pin20

      J51: pin6 <–> J44: pin18

    • Remove EEPROM:

      U48

  3. Add EEPROM_I2C_EMULATOR macro

    • Add EEPROM_I2C_EMULATOR macro to enable eeprom i2c emulator funtion

  4. Now you can refer “Prepare the Demo” to setup ecat_examples

MCUBoot layout

Region

From

To

Size

MCUboot code

0x28000000

0x2803FFFF

256kB

Primary slot

0x28040000

0x2823FFFF

2048kB

Secondary slot

0x28240000

0x2843FFFF

2048kB

  • MCUBoot header size is set to 1024 bytes

  • Signing algorithm is ECDSA-P256

  • Write alignment is 4 bytes

  • MCUBoot is configured to use SWAP_MOVE image handling strategy

Prepare the Demo
  1. Generate the SSC source code

    • Download Slave Stack Code Tool(SSC Tool V5.13) from BECKHOFF official website and install it

    • Open Slave Stack Code Tool

    • Click ‘File’ -> ‘New’ -> ‘Import’ to import the Congfig file Select foe.xml under path ‘.\boards\evkmimxrt1180\ecat_examples\foe<core>\SSC’.

    • Click ‘Custom’ -> ‘NXP ECAT…’ -> ‘OK’ to select the subdevice description file

    • Click ‘Tool’ -> ‘Application’ -> ‘Import’ to import Application information Select foe.xlsx under path ‘.\boards\evkmimxrt1180\ecat_examples\foe<core>\SSC’.

    • Click ‘Project’ -> ‘Create new Slave Files’ ‘Source Folder’(default): ‘.\boards\evkmimxrt1180\ecat_examples\foe<core>\SSC\Src’. Click ‘Start’.

    • Remove foe.c under Src folder

  2. Connect EtherCAT Port0 with TwinCAT3

    • RJ45 interface labeled as J28 is the EtherCAT Port0 and RJ45 interface labeled as J32 is the EtherCAT Port1.

  3. Connect a USB cable between the host PC and the OpenSDA USB port on the target board

  4. Open a serial terminal with the following settings

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  5. Compile mcuboot_opensource and FoE example image

    • mcuboot_opensource example path: ‘boards\evkmimxrt1180\ota_examples\mcuboot_opensource\cm33’

    • FoE example path: ‘boards\evkmimxrt1180\ecat_examples\foe\cm33’

  6. Download mcuboot_opensource and signed FoE image to the target board using ‘MCUXpresso Secure Provisioning Tool’

    • Download ‘MCUXpresso Secure Provisioning Tool’ from NXP official website

    • Change EVK SW5[1..4] to 0000 and press the reset SW3 key

    • Open ‘SPT’ and create a new workspace for the selected processor

    • Connect the board via UART

    • Verify the selected boot memory in ‘main menu’ > ‘Target’ > ‘Boot Memory’

    • On the Build image view, select the ‘mcuboot_opensource_cm33.elf’ image as ‘Source executable image’

    • Open ‘main menu’ > ‘Tools’ > ‘MCUboot’ > ‘Sign Image’ and configure the following

      • ‘ecat_foe.bin’ image to be signed

      • The signing key; it is located in the same folder that the prebuilt application or in MCUXpresso SDK, in folder ‘middleware\mcuboot_opensource\boot\nxp_mcux_sdk\keys\sign-ecdsa-p256-priv.pem’

      • The imgtool arguments by default should match the SDK example. It is not needed to change them

      • Click the ‘Sign’ button to sign the application; fix problems, if any

      • Set target address: ‘0x28040000’

      • Close the dialog by clicking the ‘Save & Close’ button

    • On the Build tab, double-check that the ‘Build script hooks’ section contains the pre-build script

    • Open ‘Additional Images’ and check that the signed application is properly configured as ‘Image 1’

    • Build and write the bootable image into the processor

    • Note: You can refer ‘MCUboot workflow’ chapter of ‘MCUXSPTUG.pdf’, which is from ‘SPT Documentation page’

  7. Run FoE example

    • Change EVK SW5[1..4] to 0100 and press the reset SW3 key.

    • The serial port will output:

        hello sbl.
        Bootloader Version 1.9.0
        Primary image: magic=good, swap_type=0x1, copy_done=0x3, image_ok=0x1
        Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
        Boot source: primary slot
        Swap type: none
        Bootloader chainload address offset: 0x40000
        Reset_Handler address offset: 0x40400
        Jumping to the image
      
        Start the SSC FoE example...
        Image version: 2.3.0
      
  8. Update ESI file to EEPROM

    • Copy ESI file ‘ECAT-FOE.xml’ generated by SSC TOOL to <TwinCAT_installation_folder>/<twincat_version>/Config/io/EtherCAT/

    • Restart TwinCAT3 IDE

    • Scan device and Update EEPROM

  9. Scan and load this device and create a PLC project in TwinCat3

    The PLC Main code is as follows:

     PROGRAM MAIN
     VAR 
     	Delay : TON;
     	LedIn AT %I* : BOOL; 
     	LedOut AT %Q* : BOOL;
     END_VAR
     
     Delay(IN := TRUE, PT := T#1S);
     IF Delay.Q THEN
     	LedOut := NOT LedIn;
     	Delay(IN := FALSE);
     END_IF;
    
  10. Activate configuration

    • Click ‘TwinCAT’ -> ‘Restart TwinCAT(Config Mode)’ to activate configuration

  11. FoE image upgrade

    • Compile FoE image

    • Install imgtool by the Python package manager

      • ‘pip install imgtool’

    • Generate new version FoE example signed image

      • ‘imgtool sign –key sign-ecdsa-p256-priv.pem –align 4 –header-size 0x400 –pad-header –slot-size 0x200000 –max-sectors 800 –version “2.4.0” ecat_foe.bin ecat_foe_2-4-0_SIGNED.bin’

    • Click ‘Device’ -> ‘Box1’ -> ‘Online’ -> ‘Bootstrap’

    • Click ‘Download’ -> ‘ecat_foe_2-4-0_SIGNED.bin’ -> ‘Password: 12369874’ -> ‘Ok’ to upgrade image

    • The serial port will output:

        Firmware upgrade in progress...
      
        FoE_StoreImage: processed 116 bytes
      
        FoE_StoreImage: processed 232 bytes
      
        ...
      
        FoE_StoreImage: upload complete (42028 bytes)
      
        write magic number offset = 0x43ff00
      
        Update image success
      
    • After download, click ‘Init’ to restart board

  12. FoE image download

    • Click ‘Upload’ -> ‘ecat_foe_2-4-0_SIGNED.bin’ -> ‘Ok’ to download upgraded image

  13. Note:

    • For subsequent upgrades, new version number must be greater than the old version number, perform step 11 to generate the new version signed image

    • For more mcuboot information, please refer to mcuboot_opensource example

FRDM-MIMXRT1186
Hardware requirements
  • FRDM-IMXRT1186 A2

  • RJ45 Network cable

  • Type-C USB cable

  • Personal Computer on which the TwinCat3 has been installed(Windows 10 is recommended)

Board settings
  • J12(2-3)/J13(2-3): eCAT0 Function Via J57A(Default).

  • J18(2-3)/J17(2-3): eCAT1 Function Via J57B(Default).

MCUBoot layout

Region

From

To

Size

MCUboot code

0x04000000

0x0403FFFF

256kB

Primary slot

0x04040000

0x0423FFFF

2048kB

Secondary slot

0x04240000

0x0443FFFF

2048kB

  • MCUBoot header size is set to 1024 bytes

  • Signing algorithm is ECDSA-P256

  • Write alignment is 4 bytes

  • MCUBoot is configured to use SWAP_MOVE image handling strategy

EEPROM LPI2C Emulator
  1. FRDM-IMXRT1186 supports EEPROM LPI2C emulator, please skip this chapter if you used EEPROM hardware.

  2. Hardware Setting

    • Remove Jumper:

      J31: pin1 - pin2

      J35: pin1 - pin2

    • Remove Resistors:

      R297: pin1 - pin2

      R299: pin1 - pin2

    • Add Resistors:

      R30

      R31

      R297: pin1 - pin3

      R299: pin1 - pin3

    • Connection:

      J31: pin1 <–> J2: pin18

      J35: pin1 <–> J2: pin20

  3. Add EEPROM_I2C_EMULATOR macro

    • Add EEPROM_I2C_EMULATOR macro to enable eeprom i2c emulator funtion

  4. Now you can refer “Prepare the Demo” to setup ecat_examples

Prepare the Demo
  1. Generate the SSC source code

    • Download Slave Stack Code Tool(SSC Tool V5.13) from BECKHOFF official website and install it

    • Open Slave Stack Code Tool

    • Click ‘File’ -> ‘New’ -> ‘Import’ to import the Congfig file Select foe.xml under path ‘.\boards\frdmimxrt1186\ecat_examples\foe<core>\SSC’.

    • Click ‘Custom’ -> ‘NXP ECAT…’ -> ‘OK’ to select the subdevice description file

    • Click ‘Tool’ -> ‘Application’ -> ‘Import’ to import Application information Select foe.xlsx under path ‘.\boards\frdmimxrt1186\ecat_examples\foe<core>\SSC’.

    • Click ‘Project’ -> ‘Create new Slave Files’ ‘Source Folder’(default): ‘.\boards\frdmimxrt1186\ecat_examples\foe<core>\SSC\Src’. Click ‘Start’.

    • Remove foe.c under Src folder

  2. Connect EtherCAT Port0 with TwinCAT3

    • RJ45 interface labeled as J57A is the EtherCAT Port0 and RJ45 interface labeled as J57B is the EtherCAT Port1.

  3. Connect a USB cable between the host PC and the OpenSDA USB port on the target board

  4. Open a serial terminal with the following settings

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  5. Compile mcuboot_opensource and FoE example image

    • mcuboot_opensource example path: ‘boards\frdmimxrt1186\ota_examples\mcuboot_opensource\cm33’

    • FoE example path: ‘boards\frdmimxrt1186\ecat_examples\foe\cm33’

  6. Download mcuboot_opensource and signed FoE image to the target board using ‘MCUXpresso Secure Provisioning Tool’

    • Download ‘MCUXpresso Secure Provisioning Tool’ from NXP official website

    • Change J60(from left to right)[1,2,3] to ‘100’ to open Serial Download mode, reset board

    • Open ‘SPT’ and create a new workspace for the selected processor

    • Connect the board via UART

    • Verify the selected boot memory in ‘main menu’ > ‘Target’ > ‘Boot Memory’

    • On the Build image view, select the ‘mcuboot_opensource_cm33.elf’ image as ‘Source executable image’

    • Open ‘main menu’ > ‘Tools’ > ‘MCUboot’ > ‘Sign Image’ and configure the following

      • ‘ecat_foe.bin’ image to be signed

      • The signing key; it is located in the same folder that the prebuilt application or in MCUXpresso SDK, in folder ‘middleware\mcuboot_opensource\boot\nxp_mcux_sdk\keys\sign-ecdsa-p256-priv.pem’

      • The imgtool arguments by default should match the SDK example. It is not needed to change them

      • Click the ‘Sign’ button to sign the application; fix problems, if any

      • Set target address: ‘0x04040000’

      • Close the dialog by clicking the ‘Save & Close’ button

    • On the Build tab, double-check that the ‘Build script hooks’ section contains the pre-build script

    • Open ‘Additional Images’ and check that the signed application is properly configured as ‘Image 1’

    • Build and write the bootable image into the processor

    • Note: You can refer ‘MCUboot workflow’ chapter of ‘MCUXSPTUG.pdf’, which is from ‘SPT Documentation website page’

  7. Run FoE example

    • Change J60(from left to right)[1,2,3] to ‘001’, reset board

    • The serial port will output:

      hello sbl. Bootloader Version 1.9.0 Primary image: magic=good, swap_type=0x1, copy_done=0x3, image_ok=0x1 Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 Boot source: primary slot Swap type: none Bootloader chainload address offset: 0x40000 Reset_Handler address offset: 0x40400 Jumping to the image

      Start the SSC FoE example… Image version: 2.3.0

  8. Update ESI file to EEPROM

    • Copy ESI file ‘ECAT-FOE.xml’ generated by SSC TOOL to <TwinCAT_installation_folder>/<twincat_version>/Config/io/EtherCAT/

    • Restart TwinCAT3 IDE

    • Scan device and Update EEPROM

  9. Scan and load this device and create a PLC project in TwinCat3

    The PLC Main code is as follows:

     PROGRAM MAIN
     VAR 
     	Delay : TON;
     	LedIn AT %I* : BOOL; 
     	LedOut AT %Q* : BOOL;
     END_VAR
     
     Delay(IN := TRUE, PT := T#1S);
     IF Delay.Q THEN
     	LedOut := NOT LedIn;
     	Delay(IN := FALSE);
     END_IF;
    
  10. Activate configuration

    • Click ‘TwinCAT’ -> ‘Restart TwinCAT(Config Mode)’ to activate configuration

  11. FoE image upgrade

    • Generate new version FoE example signed image ‘imgtool sign –key sign-ecdsa-p256-priv.pem –align 4 –header-size 0x400 –pad-header –slot-size 0x200000 –max-sectors 800 –version “2.4.0” ecat_foe_cm33.bin ecat_foe_2-4-0_SIGNED.bin’

    • Click ‘Device’ -> ‘Box1’ -> ‘Online’ -> ‘Bootstrap’

    • Click ‘Download’ -> ‘ecat_foe_2-4-0_SIGNED.bin’ -> ‘Password: 12369874’ -> ‘Ok’ to upgrade image

    • The serial port will output:

        Firmware upgrade in progress...
      
        FoE_StoreImage: processed 116 bytes
      
        FoE_StoreImage: processed 232 bytes
      
        ...
      
        FoE_StoreImage: upload complete (42028 bytes)
      
        write magic number offset = 0x43ff00
      
        Update image success
      
    • After download, click ‘Init’ to restart board

  12. FoE image download

    • Click ‘Upload’ -> ‘ecat_foe_2-4-0_SIGNED.bin’ -> ‘Ok’ to download upgraded image

Note:

-	For subsequent upgrades, new version number must be greater than the old version number, perform step 11 to generate the new version signed image
-	For more mcuboot information, please refer to mcuboot_opensource example