Supporting USB Gadgets in i.MX RT uClinux BSP

This application note explains how to configure the i.MX RT1170 as the composite USB Gadget providing the USB Ethernet and the Mass storage functions over the USB OTG High-Speed link.

In practical embedded applications, the Ethernet Gadget can be used for organizing TCP/IP-based communications with the i.MX RT1170 over the USB physical link. The Mass Storage Gadget can to used to share data on physical or virtual storage of the IMXRT1170 board to a PC, for example provide access to its SD card.

1. Configuration and Build

To enable USB Gadgets functionality in the rootfs project, do the following:

  1. Activate the cross development environment:

    $ . ./ACTIVATE.sh $ cd projects/rootfs
  2. Select the appropriate USB Gadget in the Linux configuration menu (go to the Device Drivers -> USB support -> USB Gadget Support -> USB Gadget functions configurable through configfs menu, and select the RNDIS and Mass storage options):

    $ make kmenuconfig Build the project: $ make
  3. Run the resultant rootfs.uImage on the target.

  4. Configure the USB Gadgets in the Linux console on the target board:

  5. Mount the configfs File System:

    / # mount -t configfs configfs /sys/kernel/config/
  6. Create new composite USB gadget:

  7. Add description for new device:

  8. Create configuration for the composite device:

  9. Define the mass storage function:

  10. Provide whole SD card to mass storage:

  11. Define the Ethernet Gadget (RNDIS) function:

  12. Link the Gadget functions to the composite device:

  13. Enable the USB Gadget on either USB1 (ci_hdrc.0) or USB2 (ci_hdrc.1) port:

2. Connect to the Linux Host

The host PC will detect the i.MX RT1170 as 2 devices: RNDIS Ethernet and USB Mass Storage:

3. Using the Ethernet Function of the Composite USB Gadget

  1. Setup an IP address of the USB Ethernet interface on the USB Device (i.MX RT1170) side. Select an address that will not conflict with the other network sub nets in the system (if present):

  2. Setup an IP address of the USB Ethernet interface on the USB host (PC) side (obviously, select the address from the same sub-net as the Gadget):

    Linux host example:

  3. Check communication between i.MX RT1170 and the host over USB with ping:

    • on i.MX RT1170:

    • on PC:

4. Using the Mass Storage Function of the Composite USB Gadget

  1. On the Linux host check the Mass Storage Gadget is automatically mounted:

  2. Verify that the mounted media contains the boot image:

5. Configuration USB Multifunction Composite Gadget via a Script

For convenience the usb_gadget.sh script is included into the rootfs project.

  • To configure USB Gadget as a mass storage device the following command can be used on the target board:

  • To configure USB Gadget as a network device the following command can be used on the target board:

  • To configure USB Gadget as a mass storage and a network devices the following command can be used on the target board:

  • To deactivate configured USB composite gadget the following command can be used on the target board:

Note: For configuring USB port 2 as USB gadget use the <-p 1> option.