NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.
USB Test Mode on DWC3
The USB2.0 Specs (Section 7.1.20) define five test modes to facilitate compliance testing.
- Test_SE0_NAK
- Test_J
- Test_K
- Test_Packet
- Test_Force_Enable
The DWC3 controller supports the test modes in both device and host mode. The following sections use AM437x EVM as an example to explain how to enter the test mode in DWC3 device or host mode in Linux. The AM437x EVM by default has USB0 port in device mode and USB1 port in host mode.
In Device Mode[edit]
The Linux DWC3 driver has the debugfs entry 'testmode' for each controller. Writing one of the following strings to 'testmode' entry enables corresponding test mode.
- test_se0_nak
- test_j
- test_k
- test_packet
- test_force_enable
For example, the steps to generate the test packet on USB0 port of AM437x EVM:
- load a gadget driver: # modprobe g_zero - connect the USB0 port to a USB host port - start test packet: # echo test_packet > /sys/kernel/debug/48390000.usb/testmode
The testmode debugfs entry for USB1 port is /sys/kernel/debug/483d0000.usb/testmode.
If the setup is not allowed to connect the DWC3 USB port to a host, the port could be configured to host mode using the following patch then use the instructions in the next section to enter the test mode in xHCI USB 2.0 host mode.
diff --git a/arch/arm/boot/dts/am4372.dtsi b/arch/arm/boot/dts/am4372.dtsi index 9f08e4d..88154b8 100644 --- a/arch/arm/boot/dts/am4372.dtsi +++ b/arch/arm/boot/dts/am4372.dtsi @@ -984,7 +984,7 @@ phys = <&usb2_phy1>; phy-names = "usb2-phy"; maximum-speed = "high-speed"; - dr_mode = "peripheral"; + dr_mode = "host"; }; };
In Host Hode[edit]
The Linux DWC3 driver does not have a user space interface for host port test mode yet as of now, but we could directly manipulate the registers to enter the test mode for the USB2.0 host port.
The xHCI Specs Section 4.19.6 describes the requirement for "Port Test Modes".
For exampe, the set of commands to trigger test packet mode for AM437x EVM USB1 port is
# devmem2 0x483D0420 w 0xA0 # devmem2 0x483D0020 w 0x04 # devmem2 0x483D0424 w 0x40000000
The bit[31:28] of the last register 0x483D0424 specifies the test modes. The folllowing lists the bit values and corresponding test modes. Refer to the xHCI Specs Section 5.4.9.2 for the register details.
value | Test Mode |
---|---|
0 | Test mode not enabled |
1 | Test J_STATE |
2 | Test K_STATE |
3 | Test SE0_NAK |
4 | Test Packet |
5 | Test FORCE_ENABLE |
6-14 | Reserved |
15 | Port Test Control Error |
The registers for USB0 port of AM437x are 0x48390420, 0x48390020, 0x48390424 respectively.