Linux USB OTG: Difference between revisions
No edit summary |
|||
(34 intermediate revisions by 7 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 | ||
--> {{# | --> {{INIT_RELEASE_PARAM|RELEASE_SUMO_V1.0_DART-MX8M}}<!-- | ||
--> {{#lst: | --> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!-- | ||
--> {{#lst:Android_Platform_Customization|{{#var:RELEASE_PARAM| | --> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!-- | ||
--> {{PageHeader|{{#var:HARDWARE_NAME}} USB OTG}} {{DocImage|category1=Yocto|category2=Android}}[[Category:DART-MX8M]][[Category:DART-MX8M- | --> {{#lst:Android_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!-- | ||
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!-- | |||
--> {{#vardefine:DEFAULT_DTS|{{#replace:{{#var:DEFAULT_DTB}}|.dtb|.dts}}}} <!-- | |||
--> {{#vardefine:DEFAULT_DTS_SOM|{{#replace:{{#var:DEFAULT_DTB_SOM}}|.dtb|.dts}}}} <!-- | |||
--> {{#vardefine:DTS_DIR|arch/{{#switch: {{#var:SOC_SERIES}}|imx8|imx9|am6=arm64|arm}}/boot/dts/{{#ifeq: {{#var:HARDWARE_NAME}}| | |||
DART-MX8M|{{#ifeq: {{#var:YOCTO_NAME}}|Morty|variscite/|freescale/}}|{{#switch: {{#var:SOC_SERIES}} | imx8|imx9=freescale/|am6=ti/}}}}}} <!-- | |||
--> {{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__ | |||
= 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 | By default, the USB OTG port is configured as OTG in the device tree, and a USB type-C receptacle is assembled on the {{#var:HARDWARE_NAME}} 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 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> | ||
Line 12: | Line 18: | ||
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> | ||
{{#switch: {{#var:HARDWARE_NAME}} | |||
|DART-MX8M={{#ifeq: {{#var:YOCTO_NAME}}|Morty|{{#var:DTS_DIR}}imx8m-var-dart-common.dtsi|{{#var:DTS_DIR}}{{#var:DEFAULT_DTS_SOM | fsl-imx8mq-var-dart-common.dtsi }}}} | |||
|DART-MX8M-MINI={{#var:DTS_DIR}}{{#var:DEFAULT_DTS|fsl-imx8mm-var-dart.dts }} for DART-MX8M-MINI, or {{#var:DTS_DIR}}{{#var:DEFAULT_DTS_SOM | fsl-imx8mm-var-som.dts }} for VAR-SOM-MX8M-MINI | |||
|DART-MX8M-PLUS={{#var:DTS_DIR}}{{#var:DEFAULT_DTS|fsl-imx8mp-var-dart.dts }} for DART-MX8M-PLUS, or {{#var:DTS_DIR}}{{#var:DEFAULT_DTS_SOM | fsl-imx8mp-var-som.dts }} for VAR-SOM-MX8M-PLUS | |||
|VAR-SOM-MX8M-NANO={{#var:DTS_DIR}}{{#if: {{#var:DEFAULT_DTS}} | {{#var:DEFAULT_DTS}}.dts | fsl-imx8mn-var-som.dts }} | |||
|#default={{#var:DTS_DIR}}{{#var:DEFAULT_DTS}} | |||
}} <br> | |||
{{# | {{#switch: {{#var:HARDWARE_NAME}} | ||
|DART-MX8M= | |||
<syntaxhighlight lang="diff"> | <syntaxhighlight lang="diff"> | ||
&usb_dwc3_0 { | |||
status = "okay"; | |||
extcon = <&typec_ptn5150>; | |||
- | - dr_mode = "otg"; | ||
+ | + dr_mode = "host"; | ||
}; | |||
</syntaxhighlight> | |||
|DART-MX8M-PLUS= | |||
<syntaxhighlight lang="diff"> | |||
&usb_dwc3_0 { | |||
status = "okay"; | |||
extcon = <&typec_ptn5150>; | |||
- dr_mode = "otg"; | |||
+ dr_mode = "host"; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| | |#default= | ||
<syntaxhighlight lang="diff"> | <syntaxhighlight lang="diff"> | ||
&usbotg1 { | &usbotg1 { | ||
- dr_mode = "otg"; | - dr_mode = "otg"; | ||
+ | + dr_mode = "host"; | ||
picophy,pre-emp-curr-control = <3>; | picophy,pre-emp-curr-control = <3>; | ||
picophy,dc-vol-level-adjust = <7>; | picophy,dc-vol-level-adjust = <7>; | ||
status = "okay"; | status = "okay"; | ||
}; | |||
</syntaxhighlight> | |||
|VAR-SOM-AM62= | |||
<syntaxhighlight lang="diff"> | |||
&usb0 { | |||
+ dr_mode = "host"; | |||
#address-cells = <1>; | |||
#size-cells = <0>; | |||
usb-role-switch; | |||
status="okay"; | |||
port@1 { | |||
reg = <1>; | |||
typec_hs: endpoint { | |||
remote-endpoint = <&usb_con_hs>; | |||
}; | |||
}; | |||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 38: | Line 78: | ||
<br> | <br> | ||
Note: You can read the current dr_mode value on a running target, by executing the following command: | Note: You can read the current dr_mode value on a running target, by executing the following command: | ||
{{# | {{#switch: {{#var:HARDWARE_NAME}} | ||
| DART-MX8M= | |||
<pre> | |||
# cat /sys/firmware/devicetree/base/usb@38100000/dwc3/dr_mode; | |||
</pre> | |||
| DART-MX8M-PLUS= | |||
<pre> | |||
# cat /sys/firmware/devicetree/base/usb@32f10100/dwc3@38100000/dr_mode; | |||
</pre> | |||
| VAR-SOM-MX93= | |||
<pre> | |||
# cat /sys/firmware/devicetree/base/soc@0/usb@4c100000/dr_mode | |||
</pre> | |||
| VAR-SOM-AM62= | |||
<pre> | |||
# cat /sys/firmware/devicetree/base/bus@f0000/dwc3-usb@f900000/usb@31000000/dr_mode | |||
</pre> | |||
| DART-MX95= | |||
<pre> | <pre> | ||
/sys/firmware/devicetree/base/soc/usb@4c010010/usb@4c100000/dr_mode | |||
</pre> | </pre> | ||
| | | #default= | ||
<pre> | <pre> | ||
# cat /sys/firmware/devicetree/base/usb@32e40000/dr_mode; | # cat /sys/firmware/devicetree/base/usb@32e40000/dr_mode; | ||
</pre> | </pre> | ||
}} | }} | ||
Line 58: | Line 115: | ||
Connect a type-C plug to Standard-A plug cable between the board and a PC <br> | Connect a type-C plug to Standard-A plug cable between the board and a PC <br> | ||
$ adb devices | $ adb devices | ||
You should see below output | |||
$ adb devices | |||
List of devices attached | |||
0a2299d4e6fe1111 device | |||
| | | | ||
In order to use the board as a peripheral, an appropriate module needs to be loaded.<br> | In order to use the board as a peripheral, an appropriate module needs to be loaded.<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> | 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> | ||
===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 | ||
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 | |||
}} | }} | ||
==== Ethernet Device ==== | |||
The following uses the g_ether to establish an ethernet link with a host computer over USB. | |||
First, connect a USB cable from a host computer to the USB OTG port of the target. Then run the following commands: | |||
On the target: | |||
Load the g_ether module, assigning the host mac address 02:00:00:00:00:01 | |||
Note: you may exclude the host_addr argument, it's used here because the host computer will rename usb0 to enx020000000001 | |||
# modprobe g_ether host_addr=02:00:00:00:00:01 | |||
Tell NetworkManager not to manage this interface (skip this step if NetworkManager is not running on the target) | |||
# nmcli dev set usb0 managed no | |||
Assign a static IP address of 192.168.10.2 | |||
# ip addr flush usb0; ip addr add 192.168.10.2/24 dev usb0; ip link set usb0 up | |||
On the host computer: | |||
Tell NetworkManager not to manage this interface (skip this step if NetworkManager is not running on the host) | |||
# nmcli dev set enx020000000001 managed no | |||
Assign a static IP address of 192.168.10.1 | |||
$ sudo ip addr flush enx020000000001; sudo ip addr add 192.168.10.1/24 dev enx020000000001; sudo ip link set enx020000000001 up | |||
Ping the target from the host: | |||
$ ping 192.168.10.2 -c 3 | |||
PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data. | |||
64 bytes from 192.168.10.2: icmp_seq=1 ttl=64 time=0.931 ms | |||
64 bytes from 192.168.10.2: icmp_seq=2 ttl=64 time=0.822 ms | |||
64 bytes from 192.168.10.2: icmp_seq=3 ttl=64 time=0.777 ms | |||
--- 192.168.10.2 ping statistics --- | |||
3 packets transmitted, 3 received, 0% packet loss, time 2032ms | |||
rtt min/avg/max/mdev = 0.777/0.843/0.931/0.064 ms | |||
== As OTG == | == As OTG == |
Latest revision as of 10:04, 16 July 2024
This page is using the default release RELEASE_SUMO_V1.0_DART-MX8M.
To view this page for a specific Variscite SoM and software release, please follow these steps:
- Visit variwiki.com
- Select your SoM
- Select the software release
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)
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
Ethernet Device
The following uses the g_ether to establish an ethernet link with a host computer over USB.
First, connect a USB cable from a host computer to the USB OTG port of the target. Then run the following commands:
On the target:
Load the g_ether module, assigning the host mac address 02:00:00:00:00:01 Note: you may exclude the host_addr argument, it's used here because the host computer will rename usb0 to enx020000000001 # modprobe g_ether host_addr=02:00:00:00:00:01 Tell NetworkManager not to manage this interface (skip this step if NetworkManager is not running on the target) # nmcli dev set usb0 managed no Assign a static IP address of 192.168.10.2 # ip addr flush usb0; ip addr add 192.168.10.2/24 dev usb0; ip link set usb0 up
On the host computer:
Tell NetworkManager not to manage this interface (skip this step if NetworkManager is not running on the host) # nmcli dev set enx020000000001 managed no Assign a static IP address of 192.168.10.1 $ sudo ip addr flush enx020000000001; sudo ip addr add 192.168.10.1/24 dev enx020000000001; sudo ip link set enx020000000001 up
Ping the target from the host:
$ ping 192.168.10.2 -c 3 PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data. 64 bytes from 192.168.10.2: icmp_seq=1 ttl=64 time=0.931 ms 64 bytes from 192.168.10.2: icmp_seq=2 ttl=64 time=0.822 ms 64 bytes from 192.168.10.2: icmp_seq=3 ttl=64 time=0.777 ms --- 192.168.10.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2032ms rtt min/avg/max/mdev = 0.777/0.843/0.931/0.064 ms
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.