在USB2.0 spec的7.1.20
章节规定了USB必须支持以下几种模式的Test Mode。本文将结合USB2.0 spec来实现Linux下的Test Mode做USB认证使用。
7.1.20 Test Mode Support
为了便于符合性测试,主机控制器,集线器和高速功能必须支持以下测试模式:
Test_SE0_NAK
Test mode Test_SE0_NAK: Upon command, a port transceiver must enter the high-speed receive modeand remain in that mode until the exit action is taken. This enables the testing of output impedance, lowlevel output voltage, and loading characteristics.
In addition, while in this mode, upstream facing ports (andonly upstream facing ports) must respond to any IN token packet with a NAK handshake (only if the packet CRC is determined to be correct) within the normal allowed device response time. This enables testing ofthe device squelch level circuitry and, additionally, provides a general purpose stimulus/response test for basic functional testing.Test_J
Test mode Test_J: Upon command, a port’s transceiver must enter the high-speed J state and remain in thatstate until the exit action is taken. This enables the testing of the high output drive level on the D+ line.
Test_K
Test mode Test_K: Upon command, a port’s transceiver must enter the high-speed K state and remain inthat state until the exit action is taken. This enables the testing of the high output drive level on the D- line.
Test_Packet
Test mode Test_Packet: Upon command, a port must repetitively transmit the following test packet untilthe exit action is taken. This enables the testing of rise and fall times, eye patterns, jitter, and any other dynamic waveform specifications.
Test_Force_Enable
Test mode Test_Force_Enable: Upon command, downstream facing hub ports (and only downstreamfacing hub ports) must be enabled in high-speed mode, even if there is no device attached. Packets arriving at the hub’s upstream facing port must be repeated on the port which is in this test mode.
This enablestesting of the hub’s disconnect detection; the disconnect detect bit can be polled while varying the loadingon the port, allowing the disconnect detection threshold voltage to be measured.
Test Mode的进入和退出
使用设备标准请求SetFeature(TEST_MODE)
,向上端口,该定义在9.4.9
章节或者使用hub类请求SetPortFeature(PORT_TEST)
,向下端口,该定义在11.24.2.13
章节。
SetPortFeature(PORT_TEST)
在11.24.2.13 Set Port Feature
章节详细讲述了通过Set Port Feature
进入Test Mode的方法,现摘录如下:
Linux USB Test Mode测试接口
将下面的代码添加到<Kernel_Dir>/drivers/usb/core/sysfs.c
文件中,在sysfs中新增一个port_testmode
节点用于Test Mode使用。
1 |
|
NXP提供了i.MX6DQ的USB Test Mode代码,在https://community.nxp.com/docs/DOC-94460 网站上有详细的记录。里面的patch可以参考一下,整合到自己的项目中。