USB Protocol-USB Device enumeration process

Source: Internet
Author: User

The USB host will enumerate the devices after it detects that the USB device is plugged in. Why enumerate? Enumeration is to read the various descriptor information from the device, so that the host can load the appropriate driver according to this information, so as to know the device is what device, how to communicate and so on.

Enumeration process:

1, the USB host detects that the USB device is plugged in, it will reset the device first . The USB device has an address of 0after the bus reset so that the host can communicate through address 0 and those devices that have just been plugged in. The USB host sends a standard request to get the device descriptor for endpoint 0 of the device with the address 0 (this is the process of establishing a control transfer). After the device receives the request, the device descriptor is returned to the host in the data procedure, according to the parameters requested by the host. After the host successfully obtains a device descriptor for a packet and confirms that there is no error, it returns a 0-length acknowledgment packet (the state process) to the device, thus entering the next set address stage. It is important to note that the first time the host only reads a packet's device descriptor. The standard device Descriptor has 18 bytes, some USB devices have less than 18 bytes of endpoint 0 size (but at least 8 bytes), in which case the USB host sends only one data entry request, and the excess data will not be requested again . Therefore, if the device endpoint 0 size is less than 18 bytes, you need to be aware of this problem. That is, when you first get the device descriptor, you only need to return the data once, and no longer wait for the host to continue to get the remaining data (if there is one), because the host does not do so. When the host successfully obtains the first 8 bytes of the device descriptor (the USB protocol specifies that the endpoint 0 has a maximum packet length of at least 8 bytes), it knows the maximum packet length for endpoint 0, because the maximum packet length for endpoint 0 is exactly the 8th byte of the device descriptor.

2, the host to the device again reset. This is the time to go to the set address stage. The USB host sends a request to set the address to endpoint 0 of the device with the address 0 (Control the build process of the transfer), and the new device address is included in the data package for the build process. The specific address is managed by the USB host, and the host is assigned a unique address to the device that was just connected. After receiving this setup, the USB device goes directly to the state process because there is no data process for this control transmission. The device waits for the host request State to return (an input token package), and when the input token package is received, the device returns a 0-length status packet. If the host confirms that the status pack has been received correctly, it sends an ACK packet to the device, and after the device receives the ACK, the new device address is enabled. This allows the device to be assigned a unique device address that will be accessed by the host in the future.

3. The host obtains the device descriptor again . This time is a bit different from the last time, the first is the host no longer use the address to access the device, but the new device address , in addition, this time need to get all the 18-byte device descriptor. If your endpoint 0 Maximum packet length is less than 18 bytes, you will have to request data input multiple times (that is, send multiple in token packages).

4. The host gets the configuration descriptor . The configuration descriptor is 9 bytes in total. After the host obtains the configuration descriptor, it gets the configuration collection based on the configuration collection length as described in the configuration descriptor. The request to get the configuration descriptor and get a collection of device descriptors is similar, except that the specified length is not the same. Some hosts simply do not get the configuration descriptor alone, but instead use the maximum length to get the configuration descriptor collection, because the device actually returns less than the specified number of bytes. The configuration collection includes configuration descriptors, interface descriptions, class special descriptors (if any), endpoint descriptors, and so on. interface descriptors, class special descriptors, and endpoint descriptors cannot be obtained separately, and must be returned as a collection of configuration descriptors .

5. If there is a string descriptor, get the string descriptor as well. In addition, there are report descriptors such as HID devices, which are obtained separately.

USB Protocol-USB Device enumeration process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.