How USB device is detected, identified and ready to use for applications?

What is USB device enumeration?

USB device enumeration is the process of detecting, identifying and loading drivers for USB device. 

USB host controller queries the device in order to decide what type of device it is in order to attempt to assign an appropriate driver for it. 

Some of the basic commands issued by the host to the device are:
  • Set Address – Instructs the device change it’s current address settings
  • Get Device Descriptor – Overall information about the device (manufacture, firmware version …)
  • Get Configuration Descriptor – How the endpoints will be used
  • Get Interface Descriptor – Various different interface that the device may use
  • Get String Descriptor – Unicode strings for Manufacture and Product

This process is a crucial for every USB device and without it the device would never be able to be used by the OS.


We will go step by step to understand the whole process.


Detection of device
As you may know that USB interface has 4 wires.
  1. Power
  2. Ground
  3. D+
  4. D-
USB host port with no device connected uses 15kohm resistors to connect D+ and D- to GND.


Whenever an USB device is attached to an USB host port, there is status change on these data lines and this status change is used to detect a device by USB host. This change also helps USB host to determine speed of device.

Determining the device speed 
Low speed(1.5Mbps) uses 1.5k pull-up register to Vcc on the D- line 
Full speed(12Mbps) uses 1.5k pull-up register to Vcc on the D+ line 

A high speed USB device (480Mbps) will initially appear as a full speed device to the host. The first thing the USB host does is to attempt to send /receive packets at high speed to the USB device. This is known as J and K chirp and if communication is successful it will be assumed that the USB device is a high speed device. If this initial communication fails then the USB host assumes that the device is a full speed device.

This means a high speed device has a 1k5 pull up resistor on USB DP that can be switched in / out of circuit.

A J state is defined as a differential signal on USBD+ and USB D- >= +300mV.
A K state is defined as a differential signal on USBD+ and USB D- >= -300mV. 


Identification of device
Devices are identified by device descriptor.

Once the USB host has determined that device is connected and at what speed it should communicate, USB host resets the device and try to read the device descriptors to identify the device. 

Device descriptor has following fields: 
  • bLength
  • bDescriptorType
  • bcdUSB
  • bDeviceClass
  • bDeviceSubClass
  • bDeviceProtocol
  • bMaxPacketSize
  • idVendor
  • idProduct
  • bcdDevice
  • iManufacturer
  • iProduct
  • iSerialNumber
  • bNumConfigurations
After receiving device descriptor information USB host will ask for configuration and interface descriptor. I am not covering these in this post.

Loading the driver
When the USB device has been fully identified by the USB host, then the host PC needs a driver to control the USB device. Matching the USB device to the driver is usually done by matching up the VID and PID.

When the driver has been loaded, then the USB device is available for applications to access.

References:

Comments

Post a Comment

Popular posts from this blog

MBR partitioning with 'parted' utility

Disk Partitioning: MBR vs GPT

Replace default splash screen in Yocto