USB-OTG (CM-i.MX27)
Zur Navigation springen
Zur Suche springen
The CM-i.MX27 core module features a high-speed USB-OTG PHY (SMSC USB3317). It is connected to the mini-USB jack marked with USB-OTG on the DEV-i.MX27/35.
Linux kernel configuration
This configuration sets up full OTG mode, support for the Ethernet gadget (USB device mode) and mass storage support (USB host mode).
Device Drivers ---> SCSI device support ---> <*> SCSI device support [*] legacy /proc/scsi/ support <*> SCSI disk support [*] Probe all LUNs on each SCSI device USB support ---> <*> Support for Host-side USB [*] USB device filesystem <M> EHCI HCD (USB 2.0) support [*] Support for Freescale controller [*] Support for OTG host port on Freescale controller Select OTG transceiver (Philips ISP1504) ---> [*] Root Hub Transaction Translators (EXPERIMENTAL) <*> USB Mass Storage support USB Gadget Support ---> <M> Support for USB Gadgets USB Peripheral Controller (Freescale USB Device Controller) ---> [*] OTG Support [*] Support for OTG peripheral port on Freescale controller Select OTG transceiver (Philips ISP1504) ---> <M> Ethernet Gadget (with CDC Ethernet support)
Test in Linux
After startup of the kernel, we will load the required kernel modules, test the USB HOST mode with a USB flash disk, and test the USB DEVICE mode with the Ethernet gadget. You will need a PC featuring the Ethernet gadget driver (a Linux PC typically includes this driver).
- Boot Linux on the CM-i.MX27
- Load the kernel modules
root@btmxc27:~# modprobe isp1504_arc driver fsl_arc, Revision: 1.0 root@btmxc27:~# modprobe ehci-hcd fsl-ehci fsl-ehci.0: Freescale On-Chip EHCI Host Controller fsl-ehci fsl-ehci.0: new USB bus registered, assigned bus number 1 fsl-ehci fsl-ehci.0: irq 56, io mem 0x10024000 fsl-ehci fsl-ehci.0: USB 2.0 started, EHCI 1.00, driver 10 Dec 2004 usb usb1: Product: Freescale On-Chip EHCI Host Controller usb usb1: Manufacturer: Linux 2.6.22-btmxc27-v1.0 ehci_hcd usb usb1: SerialNumber: fsl-ehci.0 usb usb1: configuration #1 chosen from 1 choice hub 1-0:1.0: USB hub found hub 1-0:1.0: 1 port detected root@btmxc27:~# modprobe arcotg_udc ARC USBOTG Device Controller driver version 1 August 2005 init ARC USBOTG h/w ID=0x5 revision=0x42 root@btmxc27:~# modprobe g_ether ether gadget: using random self ethernet address ether gadget: using random host ethernet address usb0: Ethernet Gadget, version: May Day 2005 usb0: using arc_udc, OUT ep1out IN ep1in STATUS ep2in usb0: MAC 72:ec:9b:ab:9b:5d usb0: HOST MAC ea:21:c9:08:58:39 arcotg_udc: gadget arc_udc bound to driver ether root@btmxc27:~#
- Now connect a USB flash disk to the USB-OTG plug. You need a cable mini-USB-A plug to USB-A-jack. We will mount and unmount it:
usb 1-1: new high speed USB device using fsl-ehci and address 2 usb 1-1: Product: USB Mass Storage Device usb 1-1: Manufacturer: P Technology usb 1-1: SerialNumber: 200707a41934fc usb 1-1: device v1307 p0163 is not supported usb 1-1: configuration #1 chosen from 1 choice scsi0 : SCSI emulation for USB Mass Storage devices scsi 0:0:0:0: Direct-Access UT163 USB Flash Disk 0.00 PQ: 0 ANSI: 2 sd 0:0:0:0: [sda] 1974271 512-byte hardware sectors (1011 MB) sd 0:0:0:0: [sda] Write Protect is off sd 0:0:0:0: [sda] Assuming drive cache: write through sd 0:0:0:0: [sda] 1974271 512-byte hardware sectors (1011 MB) sd 0:0:0:0: [sda] Write Protect is off sd 0:0:0:0: [sda] Assuming drive cache: write through sda: sda1 sd 0:0:0:0: [sda] Attached SCSI removable disk FAT: invalid media value (0x01) VFS: Can't find a valid FAT filesystem on dev sda. mount /dev/sda1 /mnt/card root@btmxc27:~# ls /mnt/card testfile root@btmxc27:~# umount /mnt/card/ root@btmxc27:~#
- Unplug the cable from the OTG port.
usb 1-1: USB disconnect, address 2
- Now we will connect the i.MX board to your local PC. You need a cable mini-USB-B plug to USB-A plug.
usb0: high speed config #1: 8 mA, Ethernet Gadget, using CDC Ethernet
- Establish an Ethernet-over-USB connection to your PC. On the target, we assign the IP address 192.168.1.2:
root@btmxc27:~# ifconfig usb0 up 192.168.1.2 root@btmxc27:~# ifconfig usb0 usb0 Link encap:Ethernet HWaddr 72:EC:9B:AB:9B:5D inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:11 errors:0 dropped:0 overruns:0 frame:0 TX packets:15 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2024 (1.9 KiB) TX bytes:3390 (3.3 KiB)
- Your Linux PC should have detected the connection of the Ethernet gadget. The output of dmesg should contain:
[24772.520051] usb 1-6: new high speed USB device using ehci_hcd and address 7 [24772.663767] usb 1-6: configuration #1 chosen from 1 choice [24772.676846] usb0: register 'cdc_ether' at usb-0000:00:1a.7-6, CDC Ethernet Device, ea:21:c9:08:58:39
- On your Linux PC, assign the IP address 192.168.5.1 to network device usb0. We use sudo because we need root privileges for this.
harald@WS-HP4600-35:~/imx/oe/btmxc$ sudo ifconfig usb0 up 192.168.1.1 harald@WS-HP4600-35:~/imx/oe/btmxc$ ifconfig usb0 usb0 Link encap:Ethernet HWaddr ea:21:c9:08:58:39 inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::e821:c9ff:fe08:5839/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:21 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3513 (3.5 KB) TX bytes:4935 (4.9 KB)
- Now ping the target from your PC:
harald@WS-HP4600-35:~/imx/oe/btmxc$ ping -c 10 192.168.1.2 PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data. 64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=2.00 ms 64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=0.334 ms 64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.374 ms 64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=0.339 ms 64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=0.345 ms 64 bytes from 192.168.1.2: icmp_seq=6 ttl=64 time=0.331 ms 64 bytes from 192.168.1.2: icmp_seq=7 ttl=64 time=0.337 ms 64 bytes from 192.168.1.2: icmp_seq=8 ttl=64 time=0.337 ms 64 bytes from 192.168.1.2: icmp_seq=9 ttl=64 time=0.339 ms 64 bytes from 192.168.1.2: icmp_seq=10 ttl=64 time=0.335 ms --- 192.168.1.2 ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 9002ms rtt min/avg/max/mdev = 0.331/0.507/2.005/0.499 ms
- and vice versa:
root@btmxc27:~# ping -c 10 192.168.1.1 PING 192.168.1.1 (192.168.1.1): 56 data bytes 64 bytes from 192.168.1.1: seq=0 ttl=64 time=1.475 ms 64 bytes from 192.168.1.1: seq=1 ttl=64 time=1.319 ms 64 bytes from 192.168.1.1: seq=2 ttl=64 time=1.243 ms 64 bytes from 192.168.1.1: seq=3 ttl=64 time=1.312 ms 64 bytes from 192.168.1.1: seq=4 ttl=64 time=1.223 ms 64 bytes from 192.168.1.1: seq=5 ttl=64 time=1.242 ms 64 bytes from 192.168.1.1: seq=6 ttl=64 time=1.287 ms 64 bytes from 192.168.1.1: seq=7 ttl=64 time=1.403 ms 64 bytes from 192.168.1.1: seq=8 ttl=64 time=1.254 ms 64 bytes from 192.168.1.1: seq=9 ttl=64 time=1.287 ms --- 192.168.1.1 ping statistics --- 10 packets transmitted, 10 packets received, 0% packet loss round-trip min/avg/max = 1.223/1.304/1.475 ms root@btmxc27:~#
- Disconnect the cable. You have successfully tested USB-OTG functionality!