Using NXP i.MX RT1170 as the USB Ethernet RNDIS Gadget Print

 

This application note explains how to configure the i.MX RT1170 as the USB Ethernet Gadget connected to the USB PC over the USB OTG High-Speed link.

The standard Linux Ethernet Gadget driver, with the CDC Ethernet support enabled, is used to implement this functionality. To provide support for Microsoft Windows USB hosts the gadget driver implements a second device configuration with "Remote NDIS" (RNDIS) protocol supported.

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.

Configuration and Build

To enable Ethernet Gadget functionality in the rootfs project, do the following:

  • Activate the cross development environment:
  • [yur@ubuntu linux-cortexm-2.5.0]$ . ./ACTIVATE.sh
    [yur@ubuntu linux-cortexm-2.5.0]$ cd projects/rootfs
    [yur@ubuntu rootfs]$

  • Select the appropriate USB Gadget in the Linux configuration menu (go to the Device Drivers -> USB support -> USB Gadget Support -> USB Gadget Drivers menu, and select the Ethernet Gadget (with CDC Ethernet support) variant):
  • [yur@ubuntu rootfs]$ make kmenuconfig

  • Build the project:
  • [yur@ubuntu rootfs]$ make

Run the resultant rootfs.uImage on the target. Observe the appropriate kernel messages indicating that the USB gadget is started:

...
using random self ethernet address
using random host ethernet address
usb0: HOST MAC 16:f2:10:f7:90:b7
usb0: MAC 4a:ef:b0:aa:d0:d4
using random self ethernet address
using random host ethernet address
...
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready
...
/ # ifconfig usb0
usb0 Link encap:Ethernet HWaddr 4A:EF:B0:AA:D0:D4
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:60 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

The MAC addresses used by default are generated by the driver randomly. You can set up fixed values by adding appropriate variables to the Linux kernel command line in U-Boot:

  • g_ether.host_addr=<value> (e.g. g_ether.host_addr=02:00:00:00:02:02) to specify the MAC address of the interface on the Host side;
  • g_ether.dev_addr=<value> (e.g. g_ether.dev_addr=04:00:00:00:04:04) to specify the MAC address of the interface on the Gadget side.

Connect to the Linux Host

If the host PC is running Linux, messages like these shown below will be displayed in the i.MX RT1170 console upon connection to the host:

g_ether gadget: high-speed config #1: CDC Ethernet (ECM)

The host PC will detect the i.MX RT1170 as a CDC Ethernet device:

[yur@ubuntu ~]$ dmesg | tail
[ 8089.518624] usb 1-1.4: new high-speed USB device number 7 using ehci-pci
[ 8089.613487] usb 1-1.4: New USB device found, idVendor=0525, idProduct=a4a2
[ 8089.613502] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 8089.613509] usb 1-1.4: Product: RNDIS/Ethernet Gadget
[ 8089.613516] usb 1-1.4: Manufacturer: Linux 4.5.0-00428-g34d61b4a0ecd-dirty with 402e0000.usb
[ 8089.730616] cdc_subset: probe of 1-1.4:1.0 failed with error -22
[ 8089.732362] cdc_subset 1-1.4:1.1 usb0: register 'cdc_subset' at usb-0000:00:12.0-1.4, Linux Device, fa:19:ef:9b:12:0f
[yur@ubuntu ~]$ ifconfig usb0
usb0Link encap:Ethernet HWaddr fa:19:ef:9b:12:0f
inet6 addr: fe80::f819:efff:fe9b:120f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)


Connect to the Windows Host

The RNDIS/Ethernet Gadget driver installation procedure depends on the Windows OS version. Here are the instructions for different versions:

USBnet Setup

After the host driver installation is complete, the i.MX RT1170 will print the following information on the console:

g_ether gadget: high-speed config #2: RNDIS


TCT/IP Communications

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):

/ # ifconfig usb0 192.168.2.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:
  • [yur@ubuntu ~]$ sudo ifconfig usb0 192.168.2.1

  • Windows host example depends on the Windows OS version. Also make sure here that anti-virus/OS firewall services will not block the traffic over this interface.

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

  • on i.MX RT1170:
  • / # ping 192.168.2.1 -c 3
    PING 192.168.2.1 (192.168.2.1): 56 data bytes
    64 bytes from 192.168.2.1: seq=0 ttl=64 time=1.044 ms
    64 bytes from 192.168.2.1: seq=1 ttl=64 time=0.559 ms
    64 bytes from 192.168.2.1: seq=2 ttl=64 time=0.574 ms
    ^C
    --- 192.168.2.1 ping statistics ---
    3 packets transmitted, 3 packets received, 0% packet loss
    round-trip min/avg/max = 0.559/0.725/1.044 ms

  • on PC:
  • [yur@ubuntu ~]$ ping 192.168.2.2-c 3
    PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
    64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=0.504 ms
    64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.370 ms
    64 bytes from 192.168.2.2: icmp_seq=3 ttl=64 time=0.360 ms

    --- 192.168.2.2 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 1998ms
    rtt min/avg/max/mdev = 0.360/0.411/0.504/0.067 ms

Start the HTTP daemon on the i.MX RT1170:

/ # httpd -h /httpd/html/

Connect to the website on the i.MX RT1170 over USB from the host: