Identification of HID+CDC Composite Devices in WIN10

1 Problem phenomenon

A customer uses the STM32F405 and refers to the HID+CDC sample code of the ST official USB standard library to create a product. The product is found to work well on WIN7 and can be put on WIN10. The CDC can recognize it for the first time and cannot be plugged in again. Recognition, and no matter how many times after that, can not be identified again, unless you re-power, will repeat the above phenomenon, only the first time the board can be correctly identified after power-up, follow-up will not work.

2 problem analysis

The customer uses the ST official sample code STM32_USB-Host-Device_Lib_V2.2.0\Project\USB_Device_Examples\Composite_Examples\CDC_HID_Composite. When I try to reproduce the customer’s problem using this sample code, I find this code runs OK on WIN7 but is different from the customer. The situation that I tested is that CDC can't be identified once under WIN10, but HID can always recognize it.

Below to analyze the problem, since WIN7 under the HID and CDC can be properly identified on WIN10 is not normal, then preliminary can be judged, this problem may be related to WIN10 operating system USB host driver implementation.

USB data enumeration abnormal data communication through USB analyzer under WIN10:

Figure 1 The first USB enumeration process

The above figure shows the communication data of the first normal enumeration of the client code. It can be seen from the figure that after the WIN10 USB host normally acquires the HID report descriptor, it will immediately acquire the virtual serial port status and set the baud rate, so that it is normal. Enumeration is over. Let's take a look at the abnormal USB enumeration process collected:

Figure 2 Exception enumeration process

The above figure is the abnormal enumeration process under WIN10. As can be seen from the figure, the USB host on the WIN10 system hangs the device directly after acquiring the device descriptor and configuration descriptor. Obviously, the USB host driver of the WIN10 system does not recognize the contents of the device descriptor or the configuration descriptor, and it will not be able to identify the HID+CDC composite device.

Let’s check the device descriptor in the client code:

Figure 3 Device descriptors obtained

Compound device class, subclass, protocol

Must be 0xef, 0x02, 0x01, here

VID=0x0483, PID=0x3256 (Cube library 0x5740, but this is not important), then look at the configuration descriptor:

Figure 4 Configuration descriptors that win10 does not recognize

Thus, the customer's descriptor is the HID interface + IAD + CDC interfaces structure. For WIN7, this structure can be identified, but for WIN10, this structure WIN10 may not be compatible, we try to add a layer of IAD structure outside the HID interface, making it an IAD1 + HID interface + IAD2 + CDC interfaces structure, The customer's problem is solved and can be correctly identified in WIN10. The modified descriptor structure is as follows:

Figure 5 Configuration descriptors that win10 can correctly identify

Before ending this actual combat experience, let us once again review the concept of IAD:

The IAD (Interface Association Descriptor) defines a standard for USB devices to describe the aggregation of multiple interfaces bundled in a logical function (such as the CDC virtual serial port here). The USB association allocates a device-level class code (ie, 0xEF in Figure 3), which must be used by devices that use IAD (such as the device descriptor in Figure 3); this makes it easy to identify when the device is enumerated. IAD equipment. The IAD descriptor is usually placed before the interface descriptors of the interfaces that it is bound to.

3 Conclusion

In the WIN10 system, it is recommended that an IAD descriptor be carried before the interface descriptor of each logical function of the composite device, regardless of whether the logical function is completed by a single interface descriptor (such as the HID function here) or by multiple interface descriptors. (such as the CDC function here).

Customized PVC Bluetooth Charger

Shenzhen Konchang Electronic Technology Co.,Ltd , https://www.konchang.com