Format and meaning Cypress USB descriptors

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/snaking616/article/details/86229724

table of Contents

1. USB device descriptor: DeviceDscr

2. The apparatus defined descriptors: DeviceQualDscr

3. Configuration Descriptor: HighSpeedConfigDscr / FullSpeedConfigDscr

4. Interface Descriptor: Interface Descriptor

The endpoint descriptors: Endpoint Descriptor

6. string descriptor: StringDscr

7. References


    Cypress USB descriptor indicates characteristics for the USB device, the order of these descriptors in the field have a fixed, generally bLength the first field, the second field bDescriptorType. The Prefix field names indicates the length of the field, the following categories:

  • b represents a byte (8bit);
  • w represents a word (16bit);
  • bm represents bit addressing;
  • 10 bcd represents a binary coded decimal number;
  • i represents an index value;
  • id represents the identification code.

1. USB device descriptor: DeviceDscr

USB device descriptor consists of 14 fields, with a total fixed length of 18 bytes, formatted as shown in Table 1.

db    DSCR_DEVICE_LEN          ;; Descriptor length
db    DSCR_DEVICE              ;; Decriptor type
dw   0002H                     ;; Specification Version (BCD)
db    00H                      ;; Device class
db    00H                      ;; Device sub-class
db    00H                      ;; Device sub-sub-class
db    64                       ;; Maximum packet size
dw   0B404H                    ;; Vendor ID
dw   0410H                     ;; Product ID (Sample Device)
dw   0000H                     ;; Product version ID
db    1                        ;; Manufacturer string index
db    2                        ;; Product string index
db    0                        ;; Serial number string index
db    1                        ;; Number of configurations

Where: db double-byte size 16bit; dw represents a double-word size is 32bit.

Table 1. Device Descriptor

Offset

Field name

Length / byte

Explanation

0

bLength

1

Length of the descriptor (12H bytes)

1

bDescriporType

1

Descriptor type value: Device Descriptor = 01H

2

bcdUSB

2

USB Specification version number, code represented by bcd, 2 bytes. E.g. version 2.0, a value of 0200H, represented by bcd code, low byte first, high byte, as represented by 0002H; Similarly, version 1.1, is expressed as 1001H.

4

bDeviceClass

1

Indicates USB device belongs device classes:

(1) = 0, indicates that the USB interfaces operate independently from each other, unreasonable belong device class, the interface specific information described in the descriptor;

(2) = 1 ~ FEH, indicating that the USB device belonging to a specific class of device, such as that representing 04H display device;

(3) = FFH, manufacturer-defined device class.

5

bDeviceSubClass

1

Subclasses indicating device according to the USB device. Its value depends bDeviceClass.

(1) = 0, then 0 must first bDeviceClass;

(2) = 1 ~ FEH, detailed equipment subclass;

For example, if bDeviceClass = 04H, is a display device, the bDeviceSubClass = 01H, denotes a CRT display;

(3) = FFH, custom manufacturers.

 

6

bDevicePortcol

1

Specified USB device class protocol used. And its value depends bDeviceClass bDeviceSubClass.

= 0, indicates that the device does not use any device class protocol;

= 1 ~ FEH, the USB device must belong to a definite class and sub-class equipment. The video-based protocol (UVC), an audio-based protocol (UAC) and the like;

= FFH, custom manufacturers.

7

bMaxPacketSize0

1

Indicating the maximum packet length of the USB endpoint 0 control transmission device supported by the endpoint for the low-speed devices 0 maximum packet length is 8 support; full-speed device is 8,16,32,64; 64 is a high speed device.

8

idVendor

2

Vendor ID

10

idProduct

2

Product ID

12

bcdDevice

2

Indicates the version number of the USB device.

14

iManuFacture

1

Manufacturer Info string index value, there is no time to zero. 1 here, i.e., the following "Cypress" string.

15

iProduct

1

Product information string index value, there is no time to zero. Behind the "EZ-USB" string.

16

iSerial

1

USB device serial number information string index value, when no 0.

17

bNumConfigurations

1

Configure indicates the number of USB devices are supported. If the USB device supports two transmission rates, this field point out that the number of configurations in the rate, and the number of configuration and not the two rates.

2. The  apparatus defined descriptors: DeviceQualDscr

Only when the USB is a high-speed USB devices and equipment required to support both high-speed (High Speed) and the need to support full speed (Full), you need to use the device defined descriptors. For example, the high-speed USB device currently operates in the full speed mode, the descriptor contains general information about the high speed mode.

Device descriptor is defined, 9 fields, a total of 10 bytes. Device descriptor format defined in Table 2 below.

DeviceQualDscr:
db    DSCR_DEVQUAL_LEN      ;; Descriptor length
db    DSCR_DEVQUAL          ;; Decriptor type
dw   0002H                  ;; Specification Version (BCD)
db    00H                   ;; Device class
db    00H                   ;;Device sub-class
db    00H                   ;; Device sub-sub-class
db    64                    ;; Maximum packet size
db    1                     ;; Number of configurations
db    0                     ;; Reserved 
表2. 设备限定描述符

地址偏移量

字段名

长度/字节

说明

0

bLength

1

描述符的长度(0AH字节)

1

bDescriporType

1

描述符类型值:设备限定描述符=06H

2

bcdUSB

2

USB规范版本号(BCD码)

4

bDeviceClass

1

类代码

5

bDeviceSubClass

1

子类代码

6

bDeviceProtocol

1

该设备所使用的设备类协议

7

bMaxPacketSize0

1

端点0控制传输所支持的最大数据包长度,单位字节。

8

bNumConfigurations

1

另一速率所支持的配置数。

9

bReserved

1

保留,必须为0。

3. 配置描述符:HighSpeedConfigDscr/FullSpeedConfigDscr

配置描述符包含8个字段,共9字节。所有的USB设备至少包含一个配置描述符,例如这里包含两个配置描述符高速HighSpeedConfigDscr和全速FullSpeedConfigDscr。配置描述符格式如表3所示。

db    DSCR_CONFIG_LEN                                       ;; Descriptor length
db    DSCR_CONFIG                                           ;; Descriptor type
db    (HighSpeedConfigDscrEnd-HighSpeedConfigDscr) mod 256  ;; Total Length (LSB)
db    (HighSpeedConfigDscrEnd-HighSpeedConfigDscr)/256      ;; Total Length (MSB)
db    1                                                     ;; Number of interfaces
db    1                                                     ;; Configuration number
db    0                                                     ;; Configuration string
db    10000000b                       ;; Attributes (b7 - buspwr,b6 - selfpwr,b5 - rwu)
db    100                                                ;; Power requirement (div 2 ma)
表3. 配置描述符

地址偏移量

字段名

长度/字节

说明

0

bLength

1

描述符长度(09H字节)

1

bDescriporType

1

描述符类型值:配置描述符=02H

2

wTotalLength LSB

1

指明配置信息总长度,2字节表示。为配置描述符,接口描述符,端点描述符,设备类定义描述符,供应商自定义描述符长度的和。在这里只有配置、接口和端点描述符。

3

wTotalLength MSB

1

同上

4

bNumInterface

1

指明该配置所支持的接口数,最小为1。

5

bConfigurationValue

1

指明该配置的配置值。例如这里值为1,在重枚举时,主机发送Setconfiguration(x),当x=1时,就调用该配置。

6

iConfiguration

1

该配置的字符串索引值,没有时为0。

7

bmAttributes

1

指明该配置的特性,8位。

b0~b4,保留,必须为0;

b5:远程唤醒选择。=1,支持远程唤醒;=0,不支持远程唤醒;

b6:是否总线电源选择。如果该USB设备外加了电源,=1,使用总线电源;=0,使用自供的电源;

b7:必须为1。

在主机设备请求case SC_GET_STATUS,case GS_DEVICE中获得该信息。

8

bMaxPower

1

总线供电时,该USB设备可获得的最大电流。单位2mA,所以最大值为250。如果该电流得不到满足,USB将不能使用这个配置。

4. 接口描述符:Interface Descriptor

    接口描述符有9个字段,共9字节。注意,主机不能用SetDescription和GetDescription来设置和读取接口描述符,它只能作为配置描述符的一部分信息返回,在主机发送case SC_GET_DESCRIPTOR,且case GD_CONFIGURATION时一并读取。所以我们看到,在fw.c文件中并没有对接口描述符的判断。

;; Interface Descriptor
db    DSCR_INTRFC_LEN           ;; Descriptor length
db    DSCR_INTRFC               ;; Descriptor type
db    0                         ;; Zero-based index of this interface
db    0                         ;; Alternate setting
db    6                         ;; Number of end points
db    0ffH                      ;; Interface class
db    00H                       ;; Interface sub class
db    00H                       ;; Interface sub sub class
db    0                         ;; Interface descriptor string index
表4. 接口描述符

地址偏移量

字段名

长度/字节

说明

0

bLength

1

描述符长度(09H字节)

1

bDescriporType

1

描述符类型值:配置描述符=04H

2

bInterfaceNumber

1

指明该接口的接口号。

3

bAlternateSetting

1

指明接口的可替换设置值。

4

bNumberEndpoints

1

指明接口所使用的断点数,不包括端点0。

5

bInterfaceClass

1

指明接口所使用的设备类。

=0,保留;

=1~FEH,表明该接口属于某个明确的USB设备类;

=FFH,厂家自定义的设备类。

6

bInterfaceSubClass

1

该接口所属的USB设备子类。

7

bInterfaceProtocol

1

该接口所使用的设备类协议。

8

iInterface

1

接口字符串描述符的索引值,没有时为0。

5. 端点描述符:Endpoint Descriptor

端点描述符有6个字段,共7字节。和接口描述符一样,也不能由主机通过发送GetDedcription()请求读取,只能作为配置信息case GD_CONFIGURATION的一部分返回给主机。

;; Endpoint Descriptor
db    DSCR_ENDPNT_LEN         ;; Descriptor length
db    DSCR_ENDPNT             ;; Descriptor type
db    02H                     ;; Endpoint number, and direction
db    ET_BULK                 ;; Endpoint type
db    00H                     ;; Maximun packet size (LSB)
db    02H                     ;; Max packect size (MSB)
db    00H                     ;; Polling interval
表5. 端点描述符

地址偏移量

字段名

长度/字节

说明

0

bLength

1

描述符长度(07H字节)

1

bDescriporType

1

描述符类型值:配置描述符=05H

2

bEndpointAddress

1

指明端点的端点号及传输方向。

b0~b3:该端点的端点号。如0001端点1,0010端点2;

b4~b6:保留,必须为0;

b7:端点传输方向。1-IN传输;0-OUT传输

3

bmAttributes

1

指明端点的一些特性。

b0~b1:端点的传输类型。00-控制传输,01-同步传输,10-块传输,11-中断传输。

b2~b3:当该端点为同步端点时,这两位指出同步类型。00-非同步,01-异步,10-自适应,11-同步。

b4~b5:端点用法类型。00-数据端点,01-显示反馈端点,10-隐式反馈端点,11-保留。

b6~b7:保留,必须为0。

4

wMaxpacketSize LSB

1

指明端点所支持的最大数据包长度,共16位。

b0~b10:端点所支持的最大数据包长度。

b11~b12:当该端点为高速中断或同步端点时,这两位指出每小帧中最多传输的事务数。00-每小帧1次(默认),01-每小帧2次(附加一次),10-每小帧3次(附加2次),11-保留。

b13~b15:保留,必须为0。

5

wMaxpacketSize MSB

1

高8位。数据包大小为:0000 0010 0000 0000,取0~10位,还是0200,512字节。

6

bInterval

1

指明端点数据传输的访问间隔。

低速中断端点:=10~255ms;

全速中断端点:=1~255ms;

高速中断端点:=1~16,访问间隔为2(bInterval-1)(幂)×1us;

全速/高速同步端点:=1~16,访问间隔为2(bInterval-1)(幂)×1ms 和2(bInterval-1)(幂)×1us;

高速块/控制out端点:指明其最大NAK握手包发送速率。=0,表示该端点永远不会发出NAK握手包;=其他值,表示每个bInterval时间内,该端点最多只能发送一次NAK握手包。

其他类型端点:该字段无效。

6.  string descriptor: StringDscr

    String descriptor is optional, used to store some of the supplier name, product serial number and other text information. String descriptors formatted as shown in Table 6.

Table 6. string descriptor

Offset

Field name

Length / byte

Explanation

0

bLength

1

Descriptor length (N + 2 bytes)

1

bDescriporType

1

Descriptor Type Value: configuration descriptor = 03H

2

bString

N

Unicode string

    bString here is actually composed of two situations: bSTRING or wLANGID. For strings 0, one or more language identifiers (16BIT), such as US English (0409h); other string descriptors is a string of Unicode UTF-16 LE, this encoding format, most of the character is compiled 16BIT, this low byte is encoded in ASCII characters.

StringDscr:
StringDscr0:   
      db   StringDscr0End-StringDscr0      ;; String descriptor length
      db   DSCR_STRING
      db   09H,04H
StringDscr0End:
StringDscr1:   
      db   StringDscr1End-StringDscr1      ;; String descriptor length
      db   DSCR_STRING
      db   'C',00
      db   'y',00
      db   'p',00
      db   'r',00
      db   'e',00
      db   's',00
      db   's',00
StringDscr1End:
StringDscr2:   
      db   StringDscr2End-StringDscr2      ;; Descriptor length
      db   DSCR_STRING
      db   'E',00
      db   'Z',00
      db   '-',00
      db   'U',00
      db   'S',00
      db   'B',00
StringDscr2End:

Description: db 'C', 00 in the 'C' as the 8bit ASCII code, 'C', 00 to 16bit Unicode encoding for character encoding conversion!

7. References

[1]  Cypress USB firmware architecture thorough analysis and enumeration - walter's blog - with non-blog - and non-network

[2]  Tracking the basic firmware reading frame descriptor 1 - molake10344 - CSDN blog

Guess you like

Origin blog.csdn.net/snaking616/article/details/86229724