Troubleshooting Basic USB Enumeration Problems
IntroductionIt is very common to have problems that prevent a USB device from successfully enumerating on a PC. These problems can be due to firmware bugs or a configuration problem on the host. We recommend that developers working on USB firmware start with the closest USB example that is known to enumerate and work correctly. Next modify the USB descriptors and device configuration for your target application. It is very easy to break USB enumeration by modifying USB descriptors incorrectly. Fortunately, there are several tools available on Windows that help track down problems with enumeration. As always, refer to the latest USB specification for exact descriptor formats.
Hardware USB Analyzer with PC Software
Perhaps the most useful tool for debugging USB enumeration problems is a good hardware or software USB analyzer. Please see KB311205 for a list of USB analyzers. Most analyzer software will decode USB transfers and point out any warnings or errors during the enumeration process.
The screenshot below shows a USB trace for a successful device enumeration using the Ellisys Visual USB software. As you can see, there is a warning due to a USB reset at the start of the enumeration process and another during the first GetDescriptor request. This warning is normal because on Windows, the host controller asks for the first 8 bytes of the device descriptor and then sends a request for the full device descriptor. An easy way to know that the device has finished enumerating correctly is to look for the SetConfiguration(1) request. This is the last step that the host controller performs before the PC host driver can open pipes to the device.
Ellisys Visual USB - Successful Enumeration
In the next screenshot, you will see another USB trace where the USB device descriptor length is invalid in the firmware. In this case, the length field is set to 16, when it should be 18 bytes. Notice how the analyzer software marks the GetDescriptor(Device) request with a warning and indicates that the bLength field is invalid. The PC USB host controller tries four times to enumerate the device, but ends up failing and aborts the enumeration process.
Ellisys Visual USB - Invalid Descriptor Length
USB Device Viewer
Another useful tool that can help debug USB enumeration problems is a free program from Microsoft called USB Device Viewer. This software can be downloaded as a part of the Windows WDK (previously DDK). This software is very useful for viewing USB descriptors and for debugging minor enumeration problems.
The screenshot below displays USB descriptors and information for devices plugged into a Windows machine. Note that the 'Silicon Labs WinUSB Interrupt Device' has enumerated successfully and all descriptors are displayed in the right hand side. We know that the device has enumerated successfully because there are open pipes. In this case, there are two. This means that a driver has been loaded for the device and it has opened two USB pipes successfully.
USB Device Viewer - Successful Enumeration
The next screenshot shows the same problem exhibited in the section above. The device descriptor length field is set to an invalid value of 16 instead of 18 bytes. Notice that USB Device Viewer has decoded the USB descriptors and has reported several errors. The first indicates that there are no open pipes. This means that the device either failed enumeration, or there is no driver loaded for the device. The next error describes the source of the enumeration problem, the device descriptor bLength field is incorrect! Finally the last error indicates that device enumeration has failed.
USB Device Viewer - Invalid Descriptor Length
Enumeration Problems Due to a Bad Configuration on the Host
Another common source of problems isn't actually an enumeration problem at all. During the course of USB firmware development, developers will change USB descriptors and fields such as Vendor ID/Product ID. After several attempts to enumerate the same USB hardware with different descriptors, many times Windows will make some assumptions about the device that are wrong. For every device that enumerates, there is a corresponding registry key entry that contains the VID, PID, serial string, and information about the device. In order to clear out incorrect information about a USB device, it's sometimes necessary to delete the registry key altogether. There are two main methods to delete this key, using the registry editor and using USBDeview.
Deleting USB Device Registry Keys:
The most straightforward method to delete a USB device registry key is to use the built in Registry Editor tool provided by Microsoft. Windows stores USB device information under the following key:
HKLM\CurrentControlSet\Enum\USB\VID_vvvv&PID_ppppsssssss, where vvvv is the vendor ID in hexadecimal, pppp is the product ID in hexadecimal, and sssssss is the serial string (or unique string provided by Windows if the device doesn't have a serial string descriptor).
HID registry keys are located in:
Note that newer versions of Windows don't allow users to delete these registry keys. It may be necessary to run redgedit.exe from another software tool that grants elevated access to the registry. For example, users can run the following command from the command line to run regedit using the System account:
psexec -i -d -s c:\windows\regedit.exe
PsExec is a part of PSTools available from Microsoft at:
Uninstalling USB Devices using USBDeview
USBDeview is a useful software tool that displays all currently connected USB devices as well as any devices that were previously connected.
USBDeview can be used to remove registry keys for old USB devices. Filter the device list by Vendor ID, find the old device entry, right click on the device, and select 'Uninstall Selected Devices' to remove the registry keys for the selected devices.
USBDeview - Uninstall Device