USB-OTG (SBC-i.MX51)

Aus BECOM Systems Support
Version vom 31. Oktober 2023, 09:03 Uhr von Peter (Diskussion | Beiträge) (1 Version importiert)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Generic information

The SBC-i.MX51 provides a USB-OTG port (mini-USB-A jack). See [1] for basic information about USB-OTG.

Which mode is actually chosen depends on the state of the ID pin of the USB-OTG cable. If the ID pin is grounded in the cable (mini-USB-A cable), the SBC works in USB host mode. If the ID pin is left open in the cable (mini-USB-B cable), the SBC works as a USB device.

In host mode, this port can source up to 100mA which is provided internally by the MC13892 power management IC (PMIC).

Kernel configuration

The Linux kernel differentiates between HOST mode (SBC is host and supplies current) and GADGET mode (SBC is device and draws current).

Host side configuration:

Device Drivers  --->
  [*] USB support  --->
    <*>   Support for Host-side USB
    [*]     USB Monitor
    <*>     EHCI HCD (USB 2.0) support
    [*]       Support for Freescale controller
    [*]         Support for DR host port on Freescale controller
    Select transceiver for DR port (Internal UTMI)  --->
      (X) Internal UTMI
    [*]   Root Hub Transaction Translators

For mass storage devices, like USB flash disks (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  --->
    <*>   USB Mass Storage support

For HIDs, like USB mouse and keyboard (Host mode):

Device Drivers  --->
  [*] HID Devices  --->  
    -*-   Generic HID support
    <*>   USB Human Interface Device (full HID) support  
    Special HID drivers  --->
      [*] Load all HID drivers on hid core load
      A4 tech
      <*> Apple
      <*> Belkin
      <*> Bright
      <*> Cherry
      <*> Chicony
      <*> Cypress
      <*> Dell
      <*> Ezkey
      <*> Gyration
      <*> Logitech
      <*> Microsoft
      <*> Monterey
      <*> Pantherlord devices support
      <*> Petalynx
      <*> Samsung
      <*> Sony
      <*> Sunplus

Gadget side configuration. We select the Ethernet gadget here, but others are available. The Ethernet gadget allows to establish an Ethernet connection with a PC over USB.

Device Drivers  --->
  [*] USB support  --->
    <*>   USB Gadget Support  --->
      (2)   Maximum VBUS Power usage (2-500 mA)
      USB Peripheral Controller (Freescale USB Device Controller)  --->
        Freescale USB Device Controller
      [*]   Support for DR peripheral port on Freescale controller
      Select transceiver for DR port (On-chip UTMI)  --->
        (X) On-chip UTMI
      [*]   OTG Support
      <*>   USB Gadget Drivers (Ethernet Gadget (with CDC Ethernet support))  --->
        (X) Ethernet Gadget (with CDC Ethernet support)
      [*]       RNDIS support
      <*>   USB OTG pin detect support for UTMI PHY

Test in Linux

What you will need:

  • SBC-i.MX51 with above configuration
  • Cable mini-USB-B-plug to USB-A-plug
  • Cable mini-USB-A-plug to USB-A-jack
  • USB flash disk
  • A Linux PC with the cdc_ether driver, that's for the Ethernet gadget. Most distributions have it included by default.

Let's start!

  • Connect a USB flash disk (cable mini-USB-A-plug to USB-A-jack). Linux will detect it automatically.
USB Gadget suspended
USB Host resumed
usb 2-1: new high speed USB device using fsl-ehci and address 3
usb 2-1: device v1b1c p1ab1 is not supported
usb 2-1: configuration #1 chosen from 1 choice
scsi2 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 3
usb-storage: waiting for device to settle before scanning
scsi 2:0:0:0: Direct-Access     Corsair  Flash Voyager    1100 PQ: 0 ANSI: 0 CCS
sd 2:0:0:0: [sda] 7831552 512-byte hardware sectors: (4.00 GB/3.73 GiB)
sd 2:0:0:0: [sda] Write Protect is off
sd 2:0:0:0: [sda] Mode Sense: 43 00 00 00
sd 2:0:0:0: [sda] Assuming drive cache: write through
sd 2:0:0:0: [sda] 7831552 512-byte hardware sectors: (4.00 GB/3.73 GiB)
sd 2:0:0:0: [sda] Write Protect is off
sd 2:0:0:0: [sda] Mode Sense: 43 00 00 00
sd 2:0:0:0: [sda] Assuming drive cache: write through
 sda: sda1
sd 2:0:0:0: [sda] Attached SCSI removable disk
usb-storage: device scan complete
FAT: invalid media value (0xb9)
VFS: Can't find a valid FAT filesystem on dev sda.
  • The OTG port is now in host mode. Linux will automatically mount partitions if it detects a valid file system on it. That's where the last messages in the listing above come from. You can check for mounts by typing mount:
root@sbc-imx51:~# mount
...
/dev/sda1 on /media/sda1 type vfat (rw,sync,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1)
root@sbc-imx51:~#
  • As you can see, our USB disk has one valid FAT partition, which was automatically mounted to /media/sda1. Now, unmount this partition
umount /media/sda1
  • We remove the USB disk now:
usb 2-1: USB disconnect, address 3
USB Host suspended
USB Gadget resumed
  • Next, we connect the USB-OTG port to a Linux PC (cable mini-USB-B-plug to USB-A-plug)
g_ether gadget: high speed config #1: CDC Ethernet (ECM)
  • Now, the OTG port works in device mode. The Ethernet gadget creates a new network device, which we can assign an IP address to:
root@sbc-imx51:~# ifconfig usb0 up 192.168.4.2
root@sbc-imx51:~# ifconfig usb0
usb0      Link encap:Ethernet  HWaddr 62:BD:18:D6:42:D9  
          inet addr:192.168.4.2  Bcast:192.168.4.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:404 (404.0 B)  TX bytes:3034 (2.9 KiB)
  • To enable Ethernet-over-USB, you have to assign also an IP address on your Linux PC:
harald@WS-HP4600-35:~$ sudo ifconfig usb0 up 192.168.4.1
[sudo] password for harald: 
harald@WS-HP4600-35:~$ ifconfig usb0
usb0      Link encap:Ethernet  HWaddr 86:62:99:a4:18:4d  
          inet addr:192.168.4.1  Bcast:192.168.4.255  Mask:255.255.255.0
          inet6 addr: fe80::8462:99ff:fea4:184d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3204 (3.2 KB)  TX bytes:4899 (4.8 KB)

harald@WS-HP4600-35:~$ 
  • Now you can ping your PC with the SBC-i.MX51:
root@sbc-imx51:~# ping 192.168.4.1
PING 192.168.4.1 (192.168.4.1): 56 data bytes
64 bytes from 192.168.4.1: seq=0 ttl=64 time=6.499 ms
64 bytes from 192.168.4.1: seq=1 ttl=64 time=1.113 ms
64 bytes from 192.168.4.1: seq=2 ttl=64 time=1.178 ms
64 bytes from 192.168.4.1: seq=3 ttl=64 time=1.044 ms
�
--- 192.168.4.1 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 1.044/2.458/6.499 ms
root@sbc-imx51:~#

That's it!