DESK-XZU-L/Peripherals/USB OTG

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2026/06/25 DESK-XZU-L-2.x.x release



Peripheral USB OTG[edit | edit source]

Device tree configuration[edit | edit source]

Here below an example of device tree configuration used on standard DAVE's kit for the ONDA and ONDA Plus:

From onda.dtsi:

...
...

/ {
...
...

&usb0 {
    dr_mode = "otg";
    usb-phy = <&usb_phy0>;

};

...
...

Accessing the peripheral[edit | edit source]

Linux messages in host mode[edit | edit source]

When a USB2.0 peripheral is inserted, in the following example a memory mass storage device, the kernel recognizes the device (i.e. class, vendor id, product id, etc.)

[    9.828956] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[    9.831376] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 1
[    9.831554] xhci-hcd xhci-hcd.1.auto: hcc params 0x0238f625 hci version 0x100 quirks 0x0000008002000010
[    9.831650] xhci-hcd xhci-hcd.1.auto: irq 48, io mem 0xfe200000
[    9.831860] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[    9.831883] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 2
[    9.831904] xhci-hcd xhci-hcd.1.auto: Host supports USB 3.0 SuperSpeed
[    9.869780] usb usb1: Product: xHCI Host Controller
[    9.869792] usb usb1: Manufacturer: Linux 6.6.40-xilinx-g2b7f6f70a62a xhci-hcd
[    9.869803] usb usb1: SerialNumber: xhci-hcd.1.auto
[   10.297637] usb usb2: Product: xHCI Host Controller
[   10.297649] usb usb2: Manufacturer: Linux 6.6.40-xilinx-g2b7f6f70a62a xhci-hcd
[   10.297661] usb usb2: SerialNumber: xhci-hcd.1.auto
[   12.185581] usb 1-1: new high-speed USB device number 2 using xhci-hcdrun fsck.

Additional information[edit | edit source]

If the root file system configuration does not automatically mount the partition, it is possible to mount the device using the following command:

root@onda:~# mkdir -p /mnt/usb
root@onda:~# mount /dev/sda1 /mnt/usb
root@onda:~# ls -la /mnt/usb/
total 110916
drwxrwx--- 3 root disk     32768 Jan  1  1970 .
drwxr-xr-x 5 root root      4096 Jun 12 11:47 ..
-rwxrwx--- 1 root disk 104857600 Jun 12 10:21 linux_testfile.txt
-rwxrwx--- 1 root disk        13 Mar  9  2018 uboot_testfile.txt
root@onda:~#

Accessing the device[edit | edit source]

Usage with mass-storage[edit | edit source]

root@onda:~# dd if=/dev/zero of=mass_storage count=256 bs=1M
256+0 records in
256+0 records out
268435456 bytes (268 MB, 256 MiB) copied, 16.4612 s, 16.3 MB/s
root@onda:~# mkfs.ext4 mass_storage
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 262144 1k blocks and 65536 inodes
Filesystem UUID: 8aee7461-4968-44ec-a363-c3b1ca08bb37
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185

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

root@onda:~# mkdir loop
mkdir: cannot create directory 'loop': File exists
root@onda:~# mount -o loop mass_storage loop
root@onda:~# echo "Test USB OTG with mass storage device" > loop/usb.txt
root@onda:~# umount loop
root@onda:~#

then insert the g_mass_storage kernel module driver enabling an Windows PC to see it as a removable device

root@onda:~# modprobe --first-time g_mass_storage file=/tmp/mass iSerialNumber=USBOTGCHECK

Once the USB cable is connected to the PC, the kernel prints the following messages:

root@onda:~# modprobe g_mass_storage removable=y file=mass_storage
[   87.753088] Mass Storage Function, version: 2009/09/11
[   87.758277] LUN: removable file: (no medium)
[   87.762689] LUN: removable file: /root/mass_storage
[   87.767591] Number of LUNs=1
[   87.770668] g_mass_storage gadget.0: Mass Storage Gadget, version: 2009/09/11
[   87.777967] g_mass_storage gadget.0: userspace failed to provide iSerialNumber
Jun 24 13:51:25 onda kernel: g_mass_storage gadget.0: userspace [   87.785202] g_mass_storage gadget.0: g_mass_storage ready
failed to provide iSerialNumber
root@onda:~#

and the Windows PC activate the driver and the disk is available as a Drive Unit (with the usb.txt file available).