Setup the Micro-B port to an HID device

I want to modify the Micro-B USB port on the board to make the board behave as an HID device. I can connect the NX board and the target host through the Micro-B USB port and let the target host recognize the NX as a gamepad. So that I can run the AI video program on the Xavier NX board to generate a gamepad signal and control the target host.
Note that the kernel default does not support the HID device. So I rebuild the kernel and set the HID support.
After that, I stop the " nv-l4t-usb-device-mode" so that I can make an HID gamepad usb_gadget. But I meet the “INVALIDARGUMENT” error when I try to bind “3550000.xudc” to the gamepad usb_gadget UDC.
Is there something wrong?
.

Hi,
The USB micro B port on Xavier NX default board works in device mode only. It does not support OTG. Your case may not work on the default board and need to use/design a custom board.

Sorry for the misslead. I revised my question to be more precise.
How can I bind the xudc to the custom usb_gadget?

You may find this useful:
https://www.kernel.org/doc/html/latest/usb/gadget_hid.html

A general URL on gadget:
https://www.kernel.org/doc/html/latest/search.html?q=gadget&check_keywords=yes&area=default

With that port already being in device mode the implication is that the ID pin is more or less doing what it should, but wired to always detect as device. What remains is the “gadget” setup. There is more or less a template of features for describing your virtual device, and the URL above should give you a starting point.

Keep in mind that you may need kernel features, but probably this is already set up. To see what is already enabled:
zcat /proc/config.gz | grep 'USB_GADGET'

Mainly you just need CONFIG_USB_GADGET, which should already be “=y”. You won’t need Xilinx, and although debug features can be useful, you don’t need those either. You can look up the individual kernel symbols from kernel.org if you are in doubt.

Thank you for your reply.
The "zcat /proc/config.gz | grep ‘USB_GADGET’ “ outputs:

CONFIG_USB_GADGET=y
CONFIG_USB_GADGET_VBUS_DRAW=2
CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2

Other lines start with “#”.

The Micro-B on the NX is always device mode
I try to set up the Micro-B to be HID device through "Kernel USB Gadget
Configfs Interface "
.
But I failed when " Attach the created gadget device to
the UDC driver. " Do I need to set a custom UDC driver?

Follow by this steps, I set the Micro-B to be recognized as a GamePad.
The ”INVALIDARGUMENT” error is because I do not set a function in the USB_GADGET.
I use "dmesg --follow " to find the error message. The next step is to send the control information. By the way, The target win10 host says the gamepad driver is wrong.

It is already set up as device mode on the NX and Nano. I don’t know if there might be some other required setting which is specific to Jetson hardware.

I know some about mouse and keyboard and joystick, and all of these, when using gadget, are standard class devices. What I don’t know is if a gamepad is just a name difference to a standard class HID, or if it has something “custom”. Gadget is only able to work as a framework to a subset of the standard class (non-custom) devices. I do not have a gamepad to test, but if you look at lsusb on a regular Linux host PC, it will have an “ID”. That ID will look something like “0123:4567”. Substitute your actual ID, but what does your host PC say from:
sudo lsusb -d 0123:4567 -vvv 2>&1 | tee log_gamepad.txt
(you can attach “log_gamepad.txt” to the forum)
…which should say more about its class.

Thank you.
The information about the gamepad:
log_gamepad.txt (1.9 KB)

Bus 001 Device 008: ID 0079:0011 DragonRise Inc. Gamepad
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x0079 DragonRise Inc.
  idProduct          0x0011 Gamepad
  bcdDevice            1.06
  iManufacturer           0 
  iProduct                2 USB Gamepad 
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode           33 US
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     101
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
Device Status:     0x0000
  (Bus Powered)

Pleae note that the bcdUSB is 1.00 so that it is a 1.0 USB. However, I can not set the bcdUSB value in the USB_GADGET. It’s a 2.1 USB port.

The information about the fake gamepad (by setting the Micro-B port on the NX ) information:

Bus 001 Device 009: ID 0079:0011 DragonRise Inc. Gamepad
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0079 DragonRise Inc.
  idProduct          0x0011 Gamepad
  bcdDevice            1.00
  iManufacturer           1 DragonRise Inc.
  iProduct                2 Gamepad
  iSerial                 3 0x0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           41
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               50mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              5 HID Interface
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength       9
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               4
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength           22
  bNumDeviceCaps          2
  USB 2.0 Extension Device Capability:
    bLength                 7
    bDescriptorType        16
    bDevCapabilityType      2
    bmAttributes   0x00000006
      Link Power Management (LPM) Supported
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x00
    wSpeedsSupported   0x000f
      Device can operate at Low Speed (1Mbps)
      Device can operate at Full Speed (12Mbps)
      Device can operate at High Speed (480Mbps)
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   1
      Lowest fully-functional device speed is Full Speed (12Mbps)
    bU1DevExitLat           1 micro seconds
    bU2DevExitLat         500 micro seconds
Device Status:     0x0001
  Self Powered

When I plug the real gamepad, the dmesg shows:

[88825.040543] usb 1-2.2: new low-speed USB device number 12 using tegra-xusb
[88825.064116] usb 1-2.2: New USB device found, idVendor=0079, idProduct=0011
[88825.064130] usb 1-2.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[88825.064136] usb 1-2.2: Product: USB Gamepad 
[88825.068453] input: USB Gamepad  as /devices/3610000.xhci/usb1/1-2/1-2.2/1-2.2:1.0/0003:0079:0011.0009/input/input10
[88825.069039] dragonrise 0003:0079:0011.0009: input,hidraw4: USB HID v1.10 Joystick [USB Gamepad ] on usb-3610000.xhci-2.2/input0

However, when I plug the Micro-B, the dmesg shows:


[88787.408882] usb 1-2.2: new high-speed USB device number 11 using tegra-xusb
[88787.429116] android_work: sent uevent USB_STATE=CONNECTED
[88787.430056] usb 1-2.2: New USB device found, idVendor=0079, idProduct=0011
[88787.430066] usb 1-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[88787.430071] usb 1-2.2: Product: Gamepad
[88787.430076] usb 1-2.2: Manufacturer: DragonRise Inc.
[88787.430080] usb 1-2.2: SerialNumber: 0x0
[88787.430855] configfs-gadget gadget: high-speed config #1: c
[88787.430881] tegra-xudc-new 3550000.xudc: ep 3 (type: 3, dir: in) enabled
[88787.430896] tegra-xudc-new 3550000.xudc: ep 2 (type: 3, dir: out) enabled
[88787.431023] android_work: sent uevent USB_STATE=CONFIGURED
[88787.431614] tegra-xudc-new 3550000.xudc: setup request failed: -95
[88787.432301] dragonrise 0003:0079:0011.0008: unbalanced collection at end of report description
[88787.432517] dragonrise 0003:0079:0011.0008: parse failed
[88787.432653] dragonrise: probe of 0003:0079:0011.0008 failed with error -22

There is something wrong with the report_desc. After I correct it, the target host recognizes the NX the same as the gamepad. Thank you all very much!

1 Like

Hi linuxdev, thank you very much for sharing guidance/suggestion.