USB OTG

USB On-The-Go, usually abbreviated as USB OTG, is a supplementary standard to the USB 2.0 specification. It enables USB devices, such as players or mobile phones, to transform from USB peripheral devices into USB hosts and communicate with other USB devices. Under normal circumstances, these USB devices that support OTG and USB hosts (such as desktops or laptops) still function as USB peripheral devices.

Devices that support OTG, such as USB printers, can directly connect to a USB flash drive to read files from the device for printing without being connected to a computer; or a tablet can directly connect to a USB storage disk, keyboard or mouse to expand external hardware functions.

Hardware interface

Basic Functionality

Set USB Operating Mode

Use the qusb command to configure the USB operating mode. The parameters supported by qusb are as follows:

init              Initialize USB configuration (mount configfs, create device nodes, load default PID)
bind              Bind the USB device to the configuration (activate the current configuration)
unbind            Unbind the USB device (stop the current configuration)
setpid <PID>      Switch to the specified PID USB composite mode (e.g., setpid 901D enables DIAG+ADB)
setpid -p <PID>   Set the PID as the default mode (persist to /etc/usb/usb_pid, effective after reboot)
showpid           Display all supported PIDs and their corresponding function combinations
persist <PID>     Persist the PID only (do not switch immediately)

Simulate a Network Card via USB

  • View all USB supported functions:

    root@qcm6490-idp:/# qusb showpid
    A4A1: NCM
    4EE7: ADB
    900E: DIAG
    901C: DIAG,UAC2
    901D: DIAG,ADB
    9015: MASS_STORAGE,ADB
    9024: RNDIS,ADB
    902A: RNDIS,MASS_STORAGE
    902B: RNDIS,ADB,MASS_STORAGE
    902C: RNDIS,DIAG
    902D: RNDIS,DIAG,ADB
    902F: RNDIS,DIAG,MASS_STORAGE
    908C: NCM,ADB
    90CA: DIAG,UAC2,ADB
    90CB: DIAG,UVC,ADB
    90CC: DIAG,UAC2,UVC,ADB
    90DF: DIAG,UVC
    90E0: DIAG,UAC2,UVC
    9135: DIAG,QDSS,ADB
    9136: DIAG,QDSS
    F000: MASS_STORAGE
    F00E: RNDIS
    
  • Switch USB mode: qusb setpid 908C — Enables NCM+ADB. At this point, running ifconfig -a in the device’s shell will show the usb0 interface.

  • Connect the board’s Type-C port to the PC’s USB port (PC system is Linux).

  • Set the IP address for the board’s usb0 interface: ip addr add dev usb0 192.168.0.5/24

  • Set the IP address for the newly detected USB network interface on the PC: ip addr add dev enp0s20f0u13 192.168.0.6/24 — here, enp0s20f0u13 should be replaced with the actual interface name.

  • Test the network: In the PC shell, run ping 192.168.0.5 — you should see successful ping responses indicating network connectivity.