USB Device port configuration

Some background to help…

One end of the USB connection is always one and only one of “device” or “host”. A type-C connection actually has extra wiring, and so although it appears to be either, it isn’t really…it is just splitting up wiring. The Jetsons (such as the Nano) which you are seeing with this feature are using the micro-OTG port. That port accepts either a type-A connector (making the Nano a host, e.g., the port can have a keyboard plugged in) or a type-B connector (making it a device, e.g., pretending to be mass storage or a virtual network device). The ID pin on the connector knows which type was inserted, and the Nano uses that ID to switch modes (and you are talking about device mode). An actual type-A socket cannot function as a device, and an actual type-B socket cannot function as a host.

If this were the most trivial case, then you’d have to write a driver for the device you are talking about creating. However, this is something of a “standardized” setup since USB has several “standard” USB device APIs. A custom device (such as a recovery mode Jetson) would still need a custom driver to create a device mode, and that custom device would require a custom driver on the host side as well (this is why the flashing software which actually performs the device mode flash is called the “driver package”…it understands the custom device the Jetson becomes in recovery mode).

Devices which follow a standard API (e.g., a mouse or keyboard, or a video device with no custom features) can use the standard driver which every host has. Linux provides a framework to fill in details such that you don’t have to build the entire driver. The driver just reads your details and then runs the standard API. So it is not just setting up device mode (which is the starting prerequisite), it is also setting up the USB details of that device type. The framework for this is called the “gadget” API.

This might also require something like RTSP for web streaming, but I’m not the one to ask about that. Someone here can probably give you information on RTSP streaming (which might be a better way of working with this, although it is networking and not just a USB device).

For the Jetson’s virtual USB network device and mass storage, you can look at the files in:
/opt/nvidia/l4t-usb-device-mode

Those are human readable scripts, and are setting up those device modes via the gadget interface (and putting that setup into a systemd service, which is something else you’d probably want to do). The “nv-l4t-usb-device-mode.service” is what Linux uses for automatic service setup. The scripts with “stop” or “start” in their names are just utilities to stop or start (either manually or via systemd using them).

Note that those scripts are for more than one device, and that several devices can share the same USB cable.

You might find these commands interesting:

  • systemctl list-units | grep 'nv-l4t'
  • systemctl status nv-l4t-usb-device-mode.service
    (you might see messages about the service as a whole, or about subcomponents of the service)
  • systemctl stop nv-l4t-usb-device-mode.service
  • systemctl start nv-l4t-usb-device-mode.service