Some notes on USB Device Driver development and debugging
The USB protocol is quite complex. Luckily (for those of us developing USB device drivers) there are drivers in the kernel designed specifically to test USB drivers.
These can be used to test both Host Controller Drivers (HCDs) and USB Device Controllers (UDCs). To run the tests, you need the “USB testing driver” on the USB host. This driver can be found at
Device drivers -> USB support -> USB testing driver (CONFIG_USB_TEST)
For the device, there are several options, but the simplest seem to be to find some hardware capable of being a USB Device (“Gadget”) and of running Linux (of course, if you are developing a driver for a UDC, then the test gadget is the gadget you are writing the UDC driver for). The gadget kernel should then be configured with
Device drivers -> USB support -> USB Gadget Support -> USB Gadget Drivers -> Gadget Zero (CONFIG_USB_ZERO)
You then need to visit http://www.linux-usb.org/usbtest/ and download the testusb.c program and the test.sh shell script. For a simple test, build testusb.c on your host and hook up your gadget. Then run
./testusb -a
… and wait a few minutes. (Test 14 might fail due to a bug in the test itself; you may need to specify the “vary” parameter for this test to pass.)
If everything seems fine, well, it’s too soon to congratulate yourself. The usbtest homepage above explains how to use the test.sh script to really excercise your hardware and software.
If you DO find problems, you need to start looking into the source code of the test program and kernel to find out what goes wrong.
A great help in finding out what goes wrong is the usbmon interface, with in-kernel documentation at
Documentation/usb/usbmon.txt
Also, don’t forget the Linux USB maillist, where you can ask incredibly knowledgeable people (the people who wrote the code
) what is going on. Information about the linux-usb maillist can be found at
http://vger.kernel.org/vger-lists.html#linux-usb
Arvid Brodin
Linux developer
Enea Experts Stockholm