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

[  456.139975] ci_hdrc ci_hdrc.0: EHCI Host Controller
[  456.140014] ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1
[  456.165598] ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
[  456.165904] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.10
[  456.165921] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[  456.165932] usb usb1: Product: EHCI Host Controller
[  456.165941] usb usb1: Manufacturer: Linux 5.10.0-xilinx-v2021.2 ehci_hcd
[  456.165951] usb usb1: SerialNumber: ci_hdrc.0
[  456.166730] hub 1-0:1.0: USB hub found
[  456.166800] hub 1-0:1.0: 1 port detected
[  457.115612] usb 1-1: new high-speed USB device number 2 using ci_hdrc
[  457.316438] usb 1-1: New USB device found, idVendor=0781, idProduct=557d, bcdDevice= 1.00
[  457.316454] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  457.316465] usb 1-1: Product: Cruzer Force
[  457.316474] usb 1-1: Manufacturer: SanDisk
[  457.316483] usb 1-1: SerialNumber: 03021401121621082422
[  457.317184] usb-storage 1-1:1.0: USB Mass Storage device detected
[  457.318430] scsi host0: usb-storage 1-1:1.0
[  458.336628] scsi 0:0:0:0: Direct-Access     SanDisk  Cruzer Force     1.00 PQ: 0 ANSI: 6
[  458.338116] sd 0:0:0:0: Attached scsi generic sg0 type 0
[  458.338359] sd 0:0:0:0: [sda] 60088320 512-byte logical blocks: (30.8 GB/28.7 GiB)
[  458.339341] sd 0:0:0:0: [sda] Write Protect is off
[  458.339358] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[  458.340543] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[  458.401467]  sda: sda1
[  458.409036] sd 0:0:0:0: [sda] Attached SCSI removable disk
[  458.416048] usb 1-1: Get one byte OTG status failed

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 116
drwxr-xr-x 4 root root 65536 Jan  1  1970 .
drwxr-xr-x 3 root root  4096 Mar 12 16:05 ..
drwxr-xr-x 2 root root 16384 Feb  3  2023 System Volume Information
drwxr-xr-x 3 root root 16384 Aug  1  2023 phytool
-rwxr-xr-x 1 root root    13 Oct  6  2022 uboot_testfile.txt

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.0903981 s, 186 MB/s
root@bora:~# mkfs.ext4 /tmp/mass
mke2fs 1.45.6 (20-Mar-2020)
Discarding device blocks: done
Creating filesystem with 16384 1k blocks and 4096 inodes
Filesystem UUID: 3f0fa651-33af-4001-b6c0-8774cf2d2f56
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
Mar 12 16:08:24 bora kernel: [  659.854210] ext4 filesystem being mounted at /var/volatile/tmp/loop supports timestamps until 2038 (0x7fffffff)
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:

[   34.208769] Mass Storage Function, version: 2009/09/11
[   34.208790] LUN: removable file: (no medium)
[   34.208929] LUN: file: /var/volatile/tmp/mass
[   34.208940] Number of LUNs=1
[   34.209181] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11
[   34.209194] g_mass_storage gadget: 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).