Setup the USB device mode

Hi, I’m trying to set up the Rubik Pi in USB device mode. I need to connect two Rubik Pi boards via a USB cable. For this, one device must act as a “USB device” and the other as a “USB host.”

According to the official documentation, USB device mode can only be configured on the USB 2.0 Type-A port and the USB 3.0 Type-C port. Among these, the Type-C port can automatically switch between host and device modes. To avoid conflicts, I used a USB Type-C to Type-A cable and connected the 2.0 Type-A port configured as “USB device”, to the Type-C port configured as “USB host” on the two Rubik Pi boards.

However, nothing appears in sudo dmesg -w.

I also tried setting up the Rubik Pi in USB device mode with a mobile phone and a PC, but even in those setups, the Rubik Pi could not be detected by those devices.

Could you please share the specific test commands and steps you used?

Hi,
thanks for repying,

Here in first setup i use, USB type-C to type-A cable. Type-C goes to “HOST” config rubic and Type-A goes to “DEVICE” config rubic.

Configurations “DEVICE” side


root@tnn-service:/sys/kernel/config/usb_gadget# modprobe -r g_ether

root@tnn-service:/sys/kernel/config/usb_gadget# mkdir g1

root@tnn-service:/sys/kernel/config/usb_gadget# l

**g1**/

root@tnn-service:/sys/kernel/config/usb_gadget# cd g1/

root@tnn-service:/sys/kernel/config/usb_gadget/g1# ls
UDC bDeviceProtocol bMaxPacketSize0 bcdUSB **functions** idVendor **os_desc** **webusb**
bDeviceClass bDeviceSubClass bcdDevice **configs** idProduct max_speed **strings**

root@tnn-service:/sys/kernel/config/usb_gadget/g1# echo 0x1d6b > idVendor
echo 0x0104 > idProduct

root@tnn-service:/sys/kernel/config/usb_gadget/g1# mkdir strings/0x409

root@tnn-service:/sys/kernel/config/usb_gadget/g1# echo "1234567890" > strings/0x409/serialnumber
echo "Rubic" > strings/0x409/manufacturer
echo "MassStorage" > strings/0x409/product

root@tnn-service:/sys/kernel/config/usb_gadget/g1# mkdir configs/c.1/strings/0x409
mkdir: cannot create directory ‘configs/c.1/strings/0x409’: No such file or directory

root@tnn-service:/sys/kernel/config/usb_gadget/g1# mkdir configs/c.1

root@tnn-service:/sys/kernel/config/usb_gadget/g1# mkdir configs/c.1/strings/0x409

root@tnn-service:/sys/kernel/config/usb_gadget/g1# echo "Config 1" > configs/c.1/strings/0x409/configuration

root@tnn-service:/sys/kernel/config/usb_gadget/g1# 

root@tnn-service:/sys/kernel/config/usb_gadget/g1# mkdir functions/mass_storage.0

root@tnn-service:/sys/kernel/config/usb_gadget/g1# dd if=/dev/zero of=/tmp/test.iso bs=1M count=2048
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 1.87076 s, 1.1 GB/s
root@tnn-service:/sys/kernel/config/usb_gadget/g1# mkfs.ext4 /tmp/test.iso
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done                            
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: ef27c07b-5365-4a17-afe7-58e4a11b23bd
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

root@tnn-service:/sys/kernel/config/usb_gadget/g1# echo "/tmp/test.iso" > functions/mass_storage.0/lun.0/file

root@tnn-service:/sys/kernel/config/usb_gadget/g1# ln -s functions/mass_storage.0/ configs/c.1/f3

root@tnn-service:/sys/kernel/config/usb_gadget/g1# mount -t debugfs none /sys/kernel/debug/
mount: /sys/kernel/debug: none already mounted or mount point busy.
       dmesg(1) may have more information after failed mount system call.

root@tnn-service:/sys/kernel/config/usb_gadget/g1# echo "" > /sys/kernel/debug/usb/8c00000.usb/mode

root@tnn-service:/sys/kernel/config/usb_gadget/g1# echo "device" > /sys/kernel/debug/usb/8c00000.usb/mode

root@tnn-service:/sys/kernel/config/usb_gadget/g1# cat UDC

root@tnn-service:/sys/kernel/config/usb_gadget/g1# echo 8c00000.usb > UDC

root@tnn-service:/sys/kernel/config/usb_gadget/g1# cat /sys/kernel/debug/usb/8c00000.usb/mode
device

Configurations “HOST” side. Since we are using type C

root@rubikpi-0316:/home/ubuntu# cat /sys/kernel/debug/usb/a600000.usb/mode
device

root@rubikpi-0316:/home/ubuntu# echo "host" > /sys/kernel/debug/usb/a600000.usb/mode

root@rubikpi-0316:/home/ubuntu# cat /sys/kernel/debug/usb/a600000.usb/mode
host

Connect the USB cable and observer “sudo dmesg -w”

on “HOST” side

[ 1565.295508] xhci-hcd xhci-hcd.4.auto: xHCI Host Controller
[ 1565.295548] xhci-hcd xhci-hcd.4.auto: new USB bus registered, assigned bus number 4
[ 1565.297714] xhci-hcd xhci-hcd.4.auto: hcc params 0x0230fe65 hci version 0x110 quirks 0x0000008000000010
[ 1565.297788] xhci-hcd xhci-hcd.4.auto: irq 193, io mem 0x0a600000
[ 1565.297975] xhci-hcd xhci-hcd.4.auto: xHCI Host Controller
[ 1565.297994] xhci-hcd xhci-hcd.4.auto: new USB bus registered, assigned bus number 5
[ 1565.298013] xhci-hcd xhci-hcd.4.auto: Host supports USB 3.0 SuperSpeed
[ 1565.298399] usb usb4: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.08
[ 1565.298413] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1565.298421] usb usb4: Product: xHCI Host Controller
[ 1565.298442] usb usb4: Manufacturer: Linux 6.8.0-1057-qcom xhci-hcd
[ 1565.298451] usb usb4: SerialNumber: xhci-hcd.4.auto
[ 1565.299159] hub 4-0:1.0: USB hub found
[ 1565.299209] hub 4-0:1.0: 1 port detected
[ 1565.299676] usb usb5: We don't know the algorithms for LPM for this host, disabling LPM.
[ 1565.299800] usb usb5: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 6.08
[ 1565.299811] usb usb5: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1565.299836] usb usb5: Product: xHCI Host Controller
[ 1565.299843] usb usb5: Manufacturer: Linux 6.8.0-1057-qcom xhci-hcd
[ 1565.299849] usb usb5: SerialNumber: xhci-hcd.4.auto
[ 1565.300617] hub 5-0:1.0: USB hub found
[ 1565.300684] hub 5-0:1.0: 1 port detected
[ 1565.536097] usb 4-1: new full-speed USB device number 2 using xhci-hcd
[ 1575.750464] xhci-hcd xhci-hcd.4.auto: xHCI host not responding to stop endpoint command
[ 1575.770639] xhci-hcd xhci-hcd.4.auto: xHCI host controller not responding, assume dead
[ 1575.778775] xhci-hcd xhci-hcd.4.auto: HC died; cleaning up
[ 1575.784534] usb usb4-port1: couldn't allocate usb_device

on “DEVICE” side
nothing on dmesg logs.

check the “HOST” side lsusb

root@rubikpi-0316:/home/ubuntu# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 002: ID 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
root@rubikpi-0316:/home/ubuntu# cat /sys/kernel/debug/usb/a600000.usb/mode
host

We are currently syncing this issue internally.