Topics / Communication Protocols / Q28
What happens during USB enumeration?
Short answer: When a device is plugged in, the host detects it, resets it, reads its device descriptor at address 0 to learn the control endpoint's maximum packet size, assigns it a unique address, reads all its descriptors (device, configuration, interfaces, endpoints, strings), chooses a driver based on class or vendor/product ID, and selects a configuration. Only then can the device's other endpoints be used.
Step by step
- Attach: the device connects a pull-up on D+ (full/high speed) or D− (low speed); the host sees the line change.
- Reset: the host drives SE0 for at least 10 ms; a high-speed-capable device performs the chirp handshake to switch to 480 Mbps.
- GET_DESCRIPTOR (device) to address 0, often only the first 8 bytes, to learn
bMaxPacketSize0. - SET_ADDRESS: the device must switch to the new address after the status stage of this request (a common firmware bug).
- GET_DESCRIPTOR (device) again (full 18 bytes): VID, PID, class, number of configurations.
- GET_DESCRIPTOR (configuration): first 9 bytes for
wTotalLength, then the full configuration with all interface and endpoint descriptors. - String descriptors (manufacturer, product, serial number), optionally.
- Driver binding: the host OS matches class/subclass/protocol or VID/PID to a driver.
- SET_CONFIGURATION: the device becomes "configured" and its endpoints active. Class-specific requests follow (e.g. HID report descriptor, CDC line coding).
Common failure causes
- Descriptor errors (wrong lengths,
wTotalLengthmismatch, wrong endpoint addresses). - Slow responses to control requests (the host has timeouts, e.g. 500 ms for some stages).
- Wrong USB clock accuracy (full speed needs ±0.25%; internal RC oscillators need clock recovery via SOF packets).
- Missing pull-up or VBUS sensing configuration.
Debugging: dmesg and lsusb -v on Linux, USBView on Windows, Wireshark with usbmon, or a hardware USB protocol analyser.