Trouble with USB gadget mode ACM devices on TX2

Hi.

I am having an issue where I see some very strange things when registering some ACM devices as a usb gadget on my TX2.

#!/bin/bash -e
 
modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir g && cd g
 
echo 0x1d6b > idVendor  # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB    # USB 2.0
 
echo 0xEF > bDeviceClass
echo 0x02 > bDeviceSubClass
echo 0x01 > bDeviceProtocol
 
mkdir -p strings/0x409
echo "deadbeef00115599" > strings/0x409/serialnumber
echo "Something"        > strings/0x409/manufacturer
echo "Something"        > strings/0x409/product
 
mkdir -p functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length

mkdir -p functions/acm.usb0
mkdir -p functions/acm.usb1
mkdir -p functions/acm.usb2
mkdir -p functions/acm.usb3
 
 
mkdir -p configs/c.1
echo 250 > configs/c.1/MaxPower

ln -s functions/rndis.usb0 configs/c.1/
ln -s functions/hid.usb0 configs/c.1/

ln -s functions/acm.usb0 configs/c.1/
ln -s functions/acm.usb1 configs/c.1/
ln -s functions/acm.usb2 configs/c.1/
ln -s functions/acm.usb3 configs/c.1/
 
 
# OS descriptors
echo 1       > os_desc/use
echo 0xcd    > os_desc/b_vendor_code
echo MSFT100 > os_desc/qw_sign
 
echo RNDIS   > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
echo 5162001 > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
 
ln -s configs/c.1 os_desc

udevadm settle -t 5 || :
ls /sys/class/udc/ > UDC

I am seeing some flakiness on my mac when connected to my Jetson through microUSB: If I register 1 or 2 devices, everything works fine (except for the strange group change (see below)), but with 3 or more, my laptop can’t always detect the USB devices registered. It works about 1 in 20 tries, and the cable used seem to make a difference (but it is still flaky).

Sample report from my mac when it doesn’t work:

$ls /dev/cu.*
/dev/cu.Bluetooth-Incoming-Port

$ system_profiler SPUSBDataType 
        Something:

          Product ID: 0x0104
          Vendor ID: 0x1d6b  (The Linux Foundation)
          Version: 1.00
--
          Manufacturer: Something
          Location ID: 0x14200000 / 30
          Current Available (mA): 500
          Extra Operating Current (mA): 0

Sample report when it works:

$ ls /dev/cu.*
/dev/cu.Bluetooth-Incoming-Port	/dev/cu.usbmodem1426		/dev/cu.usbmodem142A
/dev/cu.usbmodem1424		/dev/cu.usbmodem1428

$ system_profiler SPUSBDataType 
        Something:

          Product ID: 0x0104
          Vendor ID: 0x1d6b  (The Linux Foundation)
          Version: 1.00
--
          Manufacturer: Something
          Location ID: 0x14200000 / 8
          Current Available (mA): 500
          Current Required (mA): 250
          Extra Operating Current (mA): 0

Note that the currentRequired line is present on the report when it works. I tried changing the maxPower value in the script but that made no difference.

I have tried replacing the mac in question but got the same result (Linux laptops seem to work fine!), I have changed all the cables and rebooted everything after every attempt.

Something interesting is that after running the script, I see the group of the first device change after a few seconds:

nvidia@tegra-ubuntu:~$ sudo setup_usb.sh
nvidia@tegra-ubuntu:~$ ls -l /dev/ttyG*
crw-rw---- 1 root dialout 234, 0 Mar 23 16:36 /dev/ttyGS0
crw-rw---- 1 root dialout 234, 1 Mar 23 16:36 /dev/ttyGS1
crw-rw---- 1 root dialout 234, 2 Mar 23 16:36 /dev/ttyGS2
crw-rw---- 1 root dialout 234, 3 Mar 23 16:36 /dev/ttyGS3

But then, after a few seconds, it changes to

nvidia@tegra-ubuntu:~$ ls -l /dev/ttyG*
crw--w---- 1 root tty     234, 0 Mar 23 16:36 /dev/ttyGS0
crw-rw---- 1 root dialout 234, 1 Mar 23 16:36 /dev/ttyGS1
crw-rw---- 1 root dialout 234, 2 Mar 23 16:36 /dev/ttyGS2
crw-rw---- 1 root dialout 234, 3 Mar 23 16:36 /dev/ttyGS3

Any ideas on why this is happening or how to debug it?

Thanks a lot.

Hi seth.illgard,
Do you mean you connect mac to three TX2 devkits and the three TX2 cannot normally work in device mode? Are your TX2 on r28.1 or r28.2?

seth.illgard,

Do you want to configure TX2 as ACM devices or host?

Below link could work if you want to configure it as host.

As for rel-28.2, we’ve by default enabled ACM driver in kernel image.

Hi, sorry, let me clarify.

This is a single TX2. I am trying to configure it as a usb gadget and plug it in to a mac (host). The configuration is done in the script above, which registers multiple ACM devices as part of the same usb gadget.

My TX2 is on R28.2.

Thanks.

Hi seth.illgard,
Can you please share steps to reproduce the issue?

@DaneLLL
Do you want to configure TX2 as ACM devices or host?

i want TX2 on r28.1 as ACM devices ,do you have any suggest?

hello DaneLLL
And Can i use r28.2 kernel .config for build r28.1 kernel?

You can just enable that configuration in 28.1 kernel.
arch/arm64/configs/tegra18_defconfig

Many Thanks @WayneWWW