Work and Note

Usb

Follow me on GitHub

usb id https://hackaday.com/series_of_posts/all-about-usb-c/

usb

  • usb device works in master/slave arch
  • otg: device determines its role based on which end of cable it is on
    • master: A device, ID pin grounded
    • slave: B device, ID pin floating
    • device role can be changed later via SRP or HNP
  • usb c
    • A plug: downstream facing port (DFP)
    • B plug: upstream facing port (UFP)
    • dual role port (DRP)
      • otg is considered DRP in usb c’s term
    • CC: configuration pin, used to determine role
      • pull up resistor -> DFP
      • pull down resistor -> UFP
      • DRP will alternate its resistor setting
    • Vconn: power for active cable
  • Power domain
    • Source vs Sink
    • Host will assume the role of source
    • for otg, source is set via specific pull down resistance
    • for usb c, source is negotiated over USB PD

device classes

  • USB Video Class (UVC, 0Eh)
  • Media (MTP, 06h)
  • USB Mass Storage (08h)
  • USB CDC (02h), USB CDC-Data (0Ah)?
    • ACM - virtual com
    • NCM - Ethernet Adapter
  • RDNIS network

Linux USB Gadget (legacy)

First the device’s USB controller needs to support this in hardware. Search for “OTG mode” or “dwc2” together with your board’s model.

(As a general rule, full-size type-A ports will never be able to act as a device.)

Once you have enabled the necessary hardware (e.g. loaded drivers for the dwc2 controller) you can then load one of the “gadget” drivers in Linux. There is g_mass_storage for emulating a USB storage device, g_serial for emulating a USB-to-serial converter, g_ether for emulating a USB-Ethernet adapter, and quite a few others.

configfs usb gadget

https://developer.toradex.com/linux-bsp/application-development/peripheral-access/usb-device-mode-linux/

https://developer.ridgerun.com/wiki/index.php/How_to_create_USB_Ethernet_gadget_for_Jetson_through_configfs

# Mount configfs
mount -t configfs none /sys/kernel/config
cd /sys/kernel/config/usb_gadget/

# Create gadget
mkdir g2
cd g2

# Use Toradex vendor and product id
echo 0x1b67 > idVendor
echo 0x400c > idProduct

# English language strings...
mkdir strings/0x409
cat /proc/device-tree/serial-number > strings/0x409/serialnumber
echo "Toradex" > strings/0x409/manufacturer
cat /proc/device-tree/model > strings/0x409/product

# Create configuration
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo "USB CDC Ethernet config" > configs/c.1/strings/0x409/configuration

# functions/<name>.<instance name>
# name: acm, gser, obex, rndis, ecm, eem, ncm, ffs, mass_storage, hid
# Create CDC Ethernet (ECM) config
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0 configs/c.1

# enable gadget by bounding to a UDC, usb device controller
UDC_DEV=`ls /sys/class/udc`
echo "$UDC_DEV" > UDC

libusbgx, gadget-import, gadget-export, usbg.service /opt/nvidia/l4t-usb-device-mode/nv-l4t-usb-device-mode.service

libcomposite

tegra

tegra XUSB OTG

https://lwn.net/Articles/807622/

https://www.kernel.org/doc/Documentation/devicetree/bindings/usb/nvidia%2Ctegra-xudc.yaml