Search topics...
USBUSB Fundamentalsfoundational

Explain the USB enumeration process step by step. What happens from the moment you plug in a device?

0 upvotes
Practice with AISoon
Study the fundamentals first — USB topic page

USB enumeration is the process by which the host discovers, identifies, and configures a newly connected device. It is entirely host-driven — the device only responds to the host's requests. The process follows a strict sequence:

1. Connection detection: When a device is plugged in, it pulls one of the data lines high through a 1.5K pull-up resistor — D+ for full-speed and high-speed devices, D- for low-speed devices. The hub (or root hub in the host controller) detects this voltage change and reports a port status change to the host. 2. Reset: The host issues a USB reset by driving both D+ and D- low (SE0 state) for at least 10 ms. This puts the device in the Default state with address 0. 3. Get Device Descriptor (first 8 bytes): The host sends a GET_DESCRIPTOR request to address 0, endpoint 0, requesting only the first 8 bytes of the device descriptor. This reveals the maximum packet size for endpoint 0 (bMaxPacketSize0), which the host needs before it can send full-length control transfers. 4. Second reset: The host issues another reset (required by the USB specification to ensure clean state). 5. Set Address: The host assigns a unique address (1-127) using SET_ADDRESS. The device transitions to the Addressed state. 6. Get Full Device Descriptor: The host reads the complete 18-byte device descriptor at the new address, obtaining the VID, PID, device class, and number of configurations. 7. Get Configuration Descriptors: The host requests each configuration descriptor, which returns a hierarchy of configuration, interface, and endpoint descriptors. 8. Set Configuration: The host selects a configuration using SET_CONFIGURATION. The device transitions to the Configured state and is ready for data transfer.

The entire enumeration process takes 100 ms to several seconds depending on the OS. A common interview follow-up: "What happens if enumeration fails?" The host retries the reset and descriptor requests up to three times. If all attempts fail, the OS reports "Unknown USB device" or "Device descriptor request failed" — the most common symptom of incorrect descriptor data, a broken pull-up resistor, or signal integrity issues on the D+/D- lines.

Source: USB Q&A