DESK-XZ7-L/Peripherals/USB OTG

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes

2024/01/23

DESK-XZ7-L-1.x.x release
2025/06/12 DESK-XZ7-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 BORA, BORA Xpress and BORA Lite:

From bora.dtsi:

...
...

/ {

...
...
    usb_phy0: phy0@e0002000{
        compatible = "ulpi-phy";
        #phy-cells = <0x00>;
        reg = <0xe0002000 0x1000>;
        view-port = <0x170>;
        drv-vbus;
    };

...
...

};

...
...

&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.)

[ 3649.090990] ci_hdrc ci_hdrc.0: EHCI Host Controller
[ 3649.091077] ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1
[ 3649.118348] ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
[ 3649.119094] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.06
[ 3649.119148] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 3649.119185] usb usb1: Product: EHCI Host Controller
[ 3649.119214] usb usb1: Manufacturer: Linux 6.6.40-xilinx-g2b7f6f70a62a ehci_hcd
[ 3649.119241] usb usb1: SerialNumber: ci_hdrc.0
[ 3649.121015] hub 1-0:1.0: USB hub found
[ 3649.121168] hub 1-0:1.0: 1 port detected
[ 3649.808344] usb 1-1: new high-speed USB device number 2 using ci_hdrc
[ 3650.010627] usb 1-1: New USB device found, idVendor=0781, idProduct=5591, bcdDevice= 1.00
[ 3650.010686] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3650.010723] usb 1-1: Product:  SanDisk 3.2Gen1
[ 3650.010752] usb 1-1: Manufacturer:  USB
[ 3650.010778] usb 1-1: SerialNumber: 0101c87a64b5cb45bccaae1bd784c1bad724ebe2453b86693086a660b9568077c3bd000000000000000000005c22d5f9ff81320091558107a1aaf0ca
[ 3650.013156] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 3650.015390] scsi host1: usb-storage 1-1:1.0
[ 3651.068638] usb 1-1: Get one byte OTG status failed
[ 3651.070809] scsi 1:0:0:0: Direct-Access      USB      SanDisk 3.2Gen1 1.00 PQ: 0 ANSI: 6
[ 3651.073643] sd 1:0:0:0: Attached scsi generic sg0 type 0
[ 3651.083081] sd 1:0:0:0: [sdb] 240353280 512-byte logical blocks: (123 GB/115 GiB)
[ 3651.084294] sd 1:0:0:0: [sdb] Write Protect is off
[ 3651.084361] sd 1:0:0:0: [sdb] Mode Sense: 43 00 00 00
[ 3651.085540] sd 1:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 3651.098041]  sdb: sdb1
[ 3651.098893] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[ 3652.215600] FAT-fs (sdb1): Volume was not properly unmounted. Some data may be corrupt. Please run 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@bora:~# mkdir -p /mnt/usb
root@bora:~# mount /dev/sda1 /mnt/usb
root@bora:~# 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@bora:~#

Accessing the device[edit | edit source]

Usage with mass-storage[edit | edit source]

root@bora:~# dd if=/dev/zero of=/tmp/mass count=16 bs=1M
16+0 records in
16+0 records out
16777216 bytes (17 MB, 16 MiB) copied, 0.111122 s, 151 MB/s
root@bora:~# mkfs.ext4 /tmp/mass
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 16384 1k blocks and 4096 inodes
Filesystem UUID: 03af7a9e-aa46-4041-8ef4-aa062ac8d1a8
Superblock backups stored on blocks:
        8193

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

root@bora:~# mkdir -p /tmp/loop
root@bora:~# mount /tmp/mass /tmp/loop
root@bora:~# echo "Hello from desk-xz7-l" > /tmp/loop/usb.txt
root@bora:~# umount /tmp/loop
root@bora:~#

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

root@bora:~# 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:

[  110.975128] Mass Storage Function, version: 2009/09/11
[  110.975153] LUN: removable file: (no medium)
[  110.975314] LUN: file: /var/volatile/tmp/mass
[  110.975333] Number of LUNs=1
[  110.975610] g_mass_storage gadget.0: Mass Storage Gadget, version: 2009/09/11
[  110.975632] g_mass_storage gadget.0: g_mass_storage ready

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