Linux USB OTG: Difference between revisions

From Variscite Wiki
(Created page with "{{PageHeader|DART-MX8M - USB OTG}} {{DocImage|category1=DART-MX8M|category2=Yocto}} __toc__ = Configuring the USB OTG port under Linux = By default, the USB OTG port is config...")
 
No edit summary
Line 1: Line 1:
{{PageHeader|DART-MX8M - USB OTG}} {{DocImage|category1=DART-MX8M|category2=Yocto}} __toc__
<!-- Set release according to "release" parameter in URL and use RELEASE_MORTY_V1.0_DART-MX8M as default
--> {{#vardefine:RELEASE_PARAM|{{#urlget:release}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM|RELEASE_MORTY_V1.0_DART-MX8M}}}} <!--
--> {{PageHeader|DART-MX8M - USB OTG}} {{DocImage|category1=DART-MX8M|category2=Yocto}} __toc__
 
= Configuring the USB OTG port under Linux =
= 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.<br>
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.<br>
To use it as host only or peripheral only you need to change the value of the dr_mode property under the usb_dwc3_0 node in the device tree.<br>
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.<br>
dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"<br>
dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"<br>
<br>
<br>
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>
arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi<br>
arch/arm64/boot/dts/{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M | {{#ifeq: {{#var:YOCTO_NAME}} | Morty |variscite/imx8m-var-dart-common.dtsi|freescale/fsl-imx8mq-var-dart-common.dtsi}} | freescale/fsl-imx8mm-var-dart.dts}} <br>
 
{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M |
<syntaxhighlight lang="diff">
<syntaxhighlight lang="diff">
  &usb_dwc3_0 {
  &usb_dwc3_0 {
Line 15: Line 21:
+      dr_mode = "host";
+      dr_mode = "host";
};
};
</syntaxhighlight>
|
<syntaxhighlight lang="diff">
&usbotg1 {
- dr_mode = "otg";
+      dr_mode = "host";
picophy,pre-emp-curr-control = <3>;
picophy,dc-vol-level-adjust = <7>;
status = "okay";
};
</syntaxhighlight>
}}


</syntaxhighlight>
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.<br>
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.<br>
<br>
<br>
Line 32: Line 49:
Example using the g_mass_storage module to expose the root partition on eMMC to a PC while booting from recovery SD card:<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>
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 PC, and run the following on the board:
<pre>
 
# umount /dev/mmcblk0p1
# umount /dev/{{#var:EMMC_ROOTFS_DEV}}p1
# modprobe g_mass_storage file=/dev/mmcblk0p1
# 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.



Revision as of 12:04, 27 February 2019

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-imx8mm-var-dart.dts

&usbotg1 {
-	dr_mode = "otg";
+       dr_mode = "host";
	picophy,pre-emp-curr-control = <3>;
	picophy,dc-vol-level-adjust = <7>;
	status = "okay";
};

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; echo

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.

Example using the g_mass_storage module to expose the root partition on eMMC to a PC while booting from recovery SD card:
Connect a type-C plug to Standard-A plug cable between the board and a PC, and run the following on the board:

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

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

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.