DESK-MX6UL-L/Peripherals/USB OTG

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

2021/07/20

First DESK-MX6UL-L release

2022/03/16

DESK-MX6UL-L 3.0.0 release

2023/05/04

DESK-MX6UL-L 4.0.0 release
2024/08/07 DESK-MX6UL-L 4.2.x release


Peripheral USB OTG[edit | edit source]

The USB OTG ports can be configured as Host or Device mode depending on the device tree configuration. In OTG mode they 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.


200px-Emblem-important.svg.png

The USB OTG peripheral is NOT available - as default option - on AXEL ULite EVK. Please contact Sales department for this option.
This peripheral is available on the i.MX6UL standard product RIALTO SBC

Device tree configuration[edit | edit source]

RIALTO SBC[edit | edit source]

Here below is an example of device tree configuration used on standard DAVE's kit for the AXEL ULite SOM where USB OTG1 is configured as otg while the USB OTG2 port is configured in host mode:

From imx6ul-lynx-som0022.dtsi:

...
...
		reg_usb_otg2_vbus: regulator@3 {
			compatible = "regulator-fixed";
			reg = <3>;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_usb_otg2>;
			regulator-name = "usb_otg2_vbus";
			regulator-min-microvolt = <5000000>;
			regulator-max-microvolt = <5000000>;
			gpio = <&gpio2 12 GPIO_ACTIVE_HIGH>;
			enable-active-high;
		};

...
...
&usbotg2 {
	vbus-supply = <&reg_usb_otg2_vbus>;
	dr_mode = "host";
	status = "disabled";
};

...
...
&iomuxc {
...
...
		pinctrl_usb_otg2: usbotg2grp {
			fsl,pins = <
				MX6UL_PAD_ENET2_TX_DATA1__GPIO2_IO12    0x17059 /* OTG2_PWR */
				MX6UL_PAD_ENET2_TX_EN__USB_OTG2_OC       0x17059 /* OTG2_OC */
			>;
		};

		pinctrl_usb_otg2_1: usbotg2grp-1 {
			fsl,pins = <
				MX6UL_PAD_UART3_CTS_B__GPIO1_IO26	0x17059 /* OTG2_PWR */
				MX6UL_PAD_UART3_RTS_B__GPIO1_IO27	0x17059 /* OTG2_OC */
			>;
		};
...
...
};

From imx6ul-lynx-som0022-cb0090.dts:

...
...
&reg_usb_otg2_vbus {
	pinctrl-0 = <&pinctrl_usb_otg2_1>;
	gpio = <&gpio1 26 GPIO_ACTIVE_HIGH>;
};
...
...
&usbotg2 {
	disable-over-current;		// only GPIO support for OVERCURRENT in this board
	status = "okay";
};
...
...

Accessing the peripheral in RIALTO SBC[edit | edit source]

Linux messages at boot time[edit | edit source]

...
...
[ 3822.510915] ci_hdrc ci_hdrc.0: EHCI Host Controller
[ 3822.511081] ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 2
[ 3822.538895] ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
[ 3822.540643] usb usb2: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.15
[ 3822.540746] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 3822.540812] usb usb2: Product: EHCI Host Controller
[ 3822.540858] usb usb2: Manufacturer: Linux 5.15.71-desk-mx6ul-l-4.2.0-rc1+g09351f1d762a ehci_hcd
[ 3822.540907] usb usb2: SerialNumber: ci_hdrc.0
[ 3822.561551] hub 2-0:1.0: USB hub found
[ 3822.561824] hub 2-0:1.0: 1 port detected
...
...

Usage in Host mode[edit | edit source]

When a USB 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.)

[ 3999.798783] usb 2-1: new high-speed USB device number 2 using ci_hdrc
[ 4000.000961] usb 2-1: New USB device found, idVendor=0781, idProduct=557d, bcdDevice= 1.00
[ 4000.009839] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4000.026275] usb 2-1: Product: Cruzer Force
[ 4000.034961] usb 2-1: Manufacturer: SanDisk
[ 4000.043548] usb 2-1: SerialNumber: 03021401121621082422
[ 4000.070921] usb-storage 2-1:1.0: USB Mass Storage device detected
[ 4000.109120] scsi host1: usb-storage 2-1:1.0
[ 4001.131262] scsi 1:0:0:0: Direct-Access     SanDisk  Cruzer Force     1.00 PQ: 0 ANSI: 6
[ 4001.155899] sd 1:0:0:0: [sdb] 60088320 512-byte logical blocks: (30.8 GB/28.7 GiB)
[ 4001.180363] sd 1:0:0:0: [sdb] Write Protect is off
[ 4001.207039] sd 1:0:0:0: [sdb] Mode Sense: 43 00 00 00
[ 4001.218222] sd 1:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 4001.270832]  sdb: sdb1
[ 4001.295366] sd 1:0:0:0: [sdb] Attached SCSI removable disk

Usage with mass-storage[edit | edit source]

root@desk-mx6ul-rialto:~# dd if=/dev/zero of=mass_storage count=32 bs=1M
32+0 records in
32+0 records out
33554432 bytes (34 MB, 32 MiB) copied, 0.570367 s, 58.8 MB/s
root@desk-mx6ul-rialto:~# mkfs.msdos mass_storage
mkfs.fat 4.2 (2021-01-31)
root@desk-mx6ul-rialto:~# mkdir loop
root@desk-mx6ul-rialto:~# mount -o loop mass_storage loop
[ 4130.830326] loop0: detected capacity change from 0 to 65536
root@desk-mx6ul-rialto:~# echo "Test USB OTG with mass storage device" > loop/usb.txt
root@desk-mx6ul-rialto:~# umount loop/

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

root@desk-mx6ul-rialto:~# modprobe g_mass_storage removable=y file=mass_storage
[ 4215.960825] Mass Storage Function, version: 2009/09/11
[ 4215.966024] LUN: removable file: (no medium)
[ 4215.981660] LUN: removable file: /home/root/mass_storage
[ 4215.987023] Number of LUNs=1
[ 4215.999126] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11
[ 4216.006139] g_mass_storage gadget: userspace failed to provide iSerialNumber
[ 4216.015682] g_mass_storage gadget: g_mass_storage ready
root@desk-mx6ul-rialto:~#

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

$ cat /media/tomzy/42D5-CBA5/usb.txt 
Test USB OTG with mass storage device

The Windows PC also activates 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