DESK-MX6-L/Peripherals/USB OTG

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

2021/07/16

First DESK-MX6-L release

2022/03/03

DESK-MX6-L 3.0.0 release
2023/04/11 DESK-MX6-L 4.0.0 release


Peripheral USB OTG[edit | edit source]

The USB OTG feature can be easily tested using the Mass Storage Gadget, which lets the device export a file as a mass storage device to the connected PC.

Device tree configuration[edit | edit source]

Here below an example of device tree configuration used on standard DAVE's kit for the AXEL Lite SOM:

From imx6qdl-axelcommon.dtsi:


        reg_usb_otg_vbus: usb_otg_vbus {
                compatible = "regulator-fixed";
                regulator-name = "usb_otg_vbus";
                regulator-min-microvolt = <5000000>;
                regulator-max-microvolt = <5000000>;
                gpio = <&gpio4 14 0>;
                enable-active-high;
        };
...
...
&usbotg {
    vbus-supply = <&reg_usb_otg_vbus>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_usbotg_2>;
    disable-over-current;
    status = "okay";
};
...
...
&iomuxc {
...
...
    usbotg {
        pinctrl_usbotg_2: usbotggrp-2 {
            fsl,pins = <
                MX6QDL_PAD_ENET_RX_ER__USB_OTG_ID 0x17059
            >;
        };
    };
};

Accessing the peripheral[edit | edit source]

Usage with mass-storage[edit | edit source]

root@desk-mx6:~# 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, 8.63267 s, 31.1 MB/s
root@desk-mx6:~# mkfs.msdos mass_storage
mkfs.fat 4.2 (2021-01-31)
root@desk-mx6:~# mkdir loop
root@desk-mx6:~# mount -o loop mass_storage loop
[  176.970284] loop0: detected capacity change from 0 to 524288
root@desk-mx6:~# echo "Test USB OTG with mass storage device" > loop/usb.txt
root@desk-mx6:~# umount loop

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

root@desk-mx6:~# modprobe g_mass_storage removable=y file=mass_storage
root@desk-mx6:~# dmesg | tail -n 7
[  157.011126] Mass Storage Function, version: 2009/09/11
[  157.011146] LUN: removable file: (no medium)
[  157.011252] LUN: removable file: /home/root/mass_storage
[  157.011263] Number of LUNs=1
[  157.012243] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11
[  157.012263] g_mass_storage gadget: userspace failed to provide iSerialNumber
[  157.012272] g_mass_storage gadget: g_mass_storage ready

Once the USB cable is connected to the PC, the storage is mounted and the usb.txt file is available:

$ cat /media/user/0001-66DD/usb.txt 
Test USB OTG with mass storage device

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

Additional information[edit | edit source]

More information about Mass Storage Gadget driver is given in the kernel tree under Documentation/usb/mass-storage.rst