Linux USB OTG: Difference between revisions

From Variscite Wiki
No edit summary
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<!-- Set release according to "release" parameter in URL and use RELEASE_SUMO_V1.0_DART-MX8M as default
<!-- Set release according to "release" parameter in URL and use RELEASE_SUMO_V1.0_DART-MX8M as default
--> {{#vardefine:RELEASE_PARAM|{{#urlget:release}}}} <!--
--> {{#vardefine:RELEASE_PARAM|{{#urlget:release|RELEASE_SUMO_V1.0_DART-MX8M}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM|RELEASE_SUMO_V1.0_DART-MX8M}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Android_Platform_Customization|{{#var:RELEASE_PARAM|RELEASE_N7.1.1_1.0.0_VAR-SOM-MX6}}}} <!--
--> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Android_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{PageHeader|{{#var:HARDWARE_NAME}} USB OTG}} {{DocImage|category1=Yocto|category2=Android}}[[Category:Debian]][[Category:DART-MX8M-MINI]][[Category:DART-MX8M]][[Category:DART-MX8M-PLUS]] __toc__
--> {{PageHeader|{{#var:HARDWARE_NAME}} USB OTG}} {{DocImage|category1=Yocto|category2=Android}}[[Category:Debian]][[Category:DART-MX8M-MINI]][[Category:DART-MX8M]][[Category:DART-MX8M-PLUS]] __toc__


Line 12: Line 13:
For example:<br>
For example:<br>
Follow either the "Build the Linux kernel from source code" or "Customizing the Linux kernel" Wiki pages and edit the following device tree file:<br>
Follow either the "Build the Linux kernel from source code" or "Customizing the Linux kernel" Wiki pages and edit the following device tree file:<br>
{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M|{{#ifeq: {{#var:YOCTO_NAME}}|Morty|arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi|arch/arm64/boot/dts/freescale/fsl-imx8mq-var-dart-common.dtsi}}|{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M-MINI|arch/arm64/boot/dts/freescale/fsl-imx8mm-var-dart.dts for DART-MX8M-MINI, or arch/arm64/boot/dts/freescale/fsl-imx8mm-var-som.dts for VAR-SOM-MX8M-MINI|
{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M|{{#ifeq: {{#var:YOCTO_NAME}}|Morty|arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi|arch/arm64/boot/dts/freescale/{{#if: {{#var:DTB_PREFIX}} | {{#var:DTB_PREFIX}}.dtsi | fsl-imx8mq-var-dart-common.dtsi }}}}|{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M-MINI|arch/arm64/boot/dts/freescale/{{#if: {{#var:DTB_PREFIX}} | {{#var:DTB_PREFIX}}.dts | fsl-imx8mm-var-dart.dts }} for DART-MX8M-MINI, or arch/arm64/boot/dts/freescale/{{#if: {{#var:DTB_PREFIX}} | {{#var:DTB_PREFIX}}.dts | fsl-imx8mm-var-som.dts }} for VAR-SOM-MX8M-MINI|
{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M-PLUS|arch/arm64/boot/dts/freescale/imx8mp-var-dart.dts for DART-MX8M-PLUS, or arch/arm64/boot/dts/freescale/imx8mp-var-som.dts for VAR-SOM-MX8M-PLUS|
{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M-PLUS|arch/arm64/boot/dts/freescale/imx8mp-var-dart.dts for DART-MX8M-PLUS, or arch/arm64/boot/dts/freescale/imx8mp-var-som.dts for VAR-SOM-MX8M-PLUS|
{{#ifeq: {{#var:HARDWARE_NAME}}|VAR-SOM-MX8M-NANO|freescale/fsl-imx8mn-var-som.dts}}}}}}}} <br>
{{#ifeq: {{#var:HARDWARE_NAME}}|VAR-SOM-MX8M-NANO|freescale/{{#if: {{#var:DTB_PREFIX}} | {{#var:DTB_PREFIX}}.dts | fsl-imx8mn-var-som.dts }}}}}}}}}} <br>


{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M |
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M |
Line 52: Line 53:
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M |
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M |
<pre>
<pre>
# cat /sys/firmware/devicetree/base/usb@38100000/dwc3/dr_mode; echo
# cat /sys/firmware/devicetree/base/usb@38100000/dwc3/dr_mode;
</pre>
</pre>
|
|
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M-PLUS |
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M-PLUS |
<pre>
<pre>
# cat /sys/firmware/devicetree/base/usb@32f10100/dwc3@38100000/dr_mode; echo
# cat /sys/firmware/devicetree/base/usb@32f10100/dwc3@38100000/dr_mode;
</pre>
</pre>
|
|
<pre>
<pre>
# cat /sys/firmware/devicetree/base/usb@32e40000/dr_mode; echo
# cat /sys/firmware/devicetree/base/usb@32e40000/dr_mode;
</pre>
</pre>
}}}}
}}}}
Line 84: Line 85:
For example, there is an Ethernet gadget module called g_ether, a mass storage gadget called g_mass_storage, a serial gadget called g_serial, etc.<br>
For example, there is an Ethernet gadget module called g_ether, a mass storage gadget called g_mass_storage, a serial gadget called g_serial, etc.<br>
<br>
<br>
Example using the g_mass_storage module to expose the root partition on eMMC to a PC while booting from recovery SD card:<br>
===Examples===
Connect a type-C plug to Standard-A plug cable between the board and a PC, and run the following on the board:
 
Connect a type-C plug to Standard-A plug cable between the board and a host PC, and run the following examples on the target board:  
 
==== Mass Storage Device ====
The following uses the g_mass_storage module to expose the root partition on eMMC to a PC while booting from recovery SD card:<br>
  # umount /dev/{{#var:EMMC_ROOTFS_DEV}}p1
  # umount /dev/{{#var:EMMC_ROOTFS_DEV}}p1
  # modprobe g_mass_storage file=/dev/{{#var:EMMC_ROOTFS_DEV}}p1
  # modprobe g_mass_storage file=/dev/{{#var:EMMC_ROOTFS_DEV}}p1
</pre>
 
The partition should be loaded on the PC as a mass storage device.
The partition should be loaded on the PC as a mass storage device.
==== USB Debug Console ====
The following uses the g_serial module to spawn a new debug console over USB:
On target:
# echo g_serial > /etc/modules-load.d/g_serial.conf      # Load g_serial module on boot
# sudo systemctl enable getty@ttyGS0.service              # Spawn a new tty session on ttyGS0
# reboot                                                  # Reboot to take effect
On Host:
$ minicom -D /dev/ttyACM0                                # Launch minicom on Host computer to login to target tty console
}}
}}



Revision as of 19:59, 9 June 2022

DART-MX8M USB OTG

Configuring the USB OTG port under Linux

By default, the USB OTG port is configured as OTG in the device tree, and a USB type-C receptacle is assembled on the DART-MX8M custom board.
To use it as host only or peripheral only you need to change the value of the dr_mode property under the USB node in the device tree.
dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"

For example:
Follow either the "Build the Linux kernel from source code" or "Customizing the Linux kernel" Wiki pages and edit the following device tree file:
arch/arm64/boot/dts/freescale/fsl-imx8mq-var-dart-common.dtsi

&usb_dwc3_0 {
	status = "okay";
	extcon = <&typec_ptn5150>;
-	dr_mode = "otg";
+	dr_mode = "host";
};

If you build the kernel manually from source code, you should build only the device trees and copy them to your SD card or eMMC.

Note: You can read the current dr_mode value on a running target, by executing the following command:

# cat /sys/firmware/devicetree/base/usb@38100000/dwc3/dr_mode;

Using the USB OTG port under Linux

As host (default)

USB host

As peripheral

In order to use the board as a peripheral, an appropriate module needs to be loaded.
For example, there is an Ethernet gadget module called g_ether, a mass storage gadget called g_mass_storage, a serial gadget called g_serial, etc.

Examples

Connect a type-C plug to Standard-A plug cable between the board and a host PC, and run the following examples on the target board:

Mass Storage Device

The following uses the g_mass_storage module to expose the root partition on eMMC to a PC while booting from recovery SD card:

# umount /dev/mmcblk0p1
# modprobe g_mass_storage file=/dev/mmcblk0p1

The partition should be loaded on the PC as a mass storage device.

USB Debug Console

The following uses the g_serial module to spawn a new debug console over USB:

On target:

# echo g_serial > /etc/modules-load.d/g_serial.conf       # Load g_serial module on boot
# sudo systemctl enable getty@ttyGS0.service              # Spawn a new tty session on ttyGS0
# reboot                                                  # Reboot to take effect

On Host:

$ minicom -D /dev/ttyACM0                                 # Launch minicom on Host computer to login to target tty console

As OTG

With OTG, the board can be either a host, or a peripheral.
In order to use it as a host and connect a peripheral (e.g. a USB flash drive) to it, either use a peripheral with type-C connector or use type-C to type-A adapter.
In order to use it as a peripheral and connect it to a PC, for example, a cable with a type-C plug on one end and a Standard-A plug on the other is needed.