Descritores USB e seus tipos (Parte 3/6)

USB descriptors and their types (Part 3/6)

Now that we've discussed the basic details of the USB protocol, covering USB packet types and transfers, the next topic in the series is USB Descriptors. In the context of the USB interface, descriptors are formatted blocks of information through which the host device learns about the peripheral. Helps with peripheral device identification and configuration.

A descriptor contains information such as device type, vendor ID, supported USB version, number of configurations supported by the device, number of endpoints, etc. The USB peripheral must respond with descriptors when requested by the host. During enumeration, the host uses control transfer to request descriptors from the device.

Types of descriptors

There are mainly five types of descriptors

• Device descriptors

• Configuration descriptors

• Interface Descriptors

• Endpoint descriptors

• String descriptors

During enumeration, the host requests the top-level descriptors. As the enumeration progresses, the higher-level descriptors inform the host about the lower-level descriptors (if any). Descriptors contain several fields and most of them use a prefix to indicate the format or type of content. Common prefixes are: b = byte (8 bits), c = word (16 bits), BCD = binary coded decimal, bm = bitmap (bit array), l = index, id = identifier.

Each descriptor contains a series of fields and follows a common format. The first byte specifies the length of the descriptor while the second byte indicates the descriptor type.

Tipos de descritores

Length – This field provides the length of the descriptor in bytes.

bDescriptionType – This field indicates the type of descriptor.

tipo de descritor.

Device descriptors

The device descriptor provides basic information about the device. It represents the entire USB device. It is the first descriptor read by the host. The host receives this descriptor after sending the Get_Descriptor request.

The descriptor contains fields containing device-specific information such as USB version, device class, product ID, vendor ID, number of configurations supported by the device, etc. Check out the table below to learn more about common fields included in device descriptors.

descritores de dispositivos

Device_qualifier descriptors

USB devices that support full and high speed modes must have a device_qualifier descriptor. When the USB device changes speed modes, the values ​​in some fields change in the device descriptor. The device_qualifier descriptor provides information only about the values ​​of fields that change when the device switches to an alternate speed mode. This descriptor contains the following fields, of which the first two are common, while others are changed specifically for the device.

Descritores Device_qualifier

Configuration descriptors

A USB device can have one or more configurations. Most devices only have one setting. The configuration provides information related to power source, power consumption, and number of interfaces.

The bNumConfigurations in the device descriptor informs the host about the number of possible configurations. The host uses Set_Configuration request to select a configuration and Get_Configuration request to read the currently selected configuration.

The configuration descriptor contains the following fields.

Descritores de configuração

Other_speed_configuration descriptors

This descriptor is for devices that support full and high speed modes. Returns the currently inactive speed mode setting. The structure is the same as the configuration descriptor, except for the field value for bDescriptor type, which is 0x07.

Interface descriptors

A configuration can have one or more interfaces that can be considered resources or functions implemented by the device. The interface descriptor provides information related to specific device features, such as class, subclass, protocol, and number of uses of the endpoint interface.

The bNumInterfaces in the configuration descriptor tells the host about the number of possible interfaces. After selecting a configuration, the host uses Set_Interface request to select an interface and Get_Interface request to read the currently selected interface.

It is possible to activate multiple interfaces at the same time for one configuration. Devices in which multiple interfaces are active are known as composite devices.

Descritores de interface

Endpoint descriptors

The Endpoint Descriptor describes the endpoints associated with an interface. There is no descriptor for the default zero endpoint. Endpoint zero is the control endpoint and is configured even before any descriptor is requested. The information contained in this descriptor is used to determine the bandwidth required by the USB bus.

This descriptor includes the following fields –:

Descritores de endpoint

String descriptors

String descriptors contain human-readable text. They are generally used to provide information. Other descriptors contain index values ​​that point to strings containing manufacturer, product, serial number, configuration, interface information. Other descriptors like Class and Vendor Specific can contain indexes to string descriptors

Strings are encoded in Unicode format and multiple languages ​​are supported. The host can get the list of supported languages ​​using Get_Descriptor request with 0 in wIndex field. The device returns the String descriptor containing codes for different languages. The first 2 fields are mandatory and the other fields contain language codes.

Descritores de string

After that, all subsequent string descriptors (beyond index 0) will have string content and must conform to the following format.

Formato do descritor de string

Other standard descriptors

According to the USB 2.0 specifications, there are additional descriptors for other specific purposes. They are the following:

interface_association descriptor: This applies to composite devices that have more than one interface for a single function or feature.

Interface_power descriptor: It was proposed by Microsoft in 1998, but was not implemented. The goal in proposing this descriptor was to give interfaces the ability to manage their own power consumption individually.

OTG Descriptor: This descriptor is required for devices that support OTG Host Negotiation Protocol (HNP) or Session Request Protocol.

Debug descriptors: The debug descriptor is used by debug devices for debugging purposes.

In the next part of the USB series, we will discuss USB requests and control transfer stages.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.