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:
Activate the cross development environment:
$ . ./ACTIVATE.sh $ cd projects/rootfs
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
Run the resultant
rootfs.uImage
on the target.Configure the USB Gadgets in the Linux console on the target board:
Mount the
configfs
File System:/ # mount -t configfs configfs /sys/kernel/config/
Create new composite USB gadget:
Add description for new device:
Create configuration for the composite device:
Define the mass storage function:
Provide whole SD card to mass storage:
Define the Ethernet Gadget (RNDIS) function:
Link the Gadget functions to the composite device:
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
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):
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:
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
On the Linux host check the Mass Storage Gadget is automatically mounted:
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.