STM32G0B1 as USB composite device - Page 1
Forum section: electronics / general

author: katagia
author_rank: Newbie
timestamp: October 09, 2023, 07:27:41 am
content: HiI try to configure a STM32G0B1 as USB composite device for CDC and HID.I use STM32 Cube IDE 1.13.2.The basic configuration is done with CubeMX.I connect the microcontroller to a windows 11 based computer.I tried to use the composite build which is part of the firmware package.The ST exmaples for CDC and HID are working idependently.My version with the composite build is not working. Enumeration is not working, I get a code 10 error for CDC and a wrong device is shown with code 28.I used USBpcap to trace the problem. The pcap files are viewable with wireshark. For me it looks like the configuration descirptor is put together the right way:1 Configuration3 Interfaces (2 are CDC, one is HID)followed by all 3 interface descriptions.I compared them, they are identical to the working versions.What I don't understand is that when I compare the CDC with the composite dump, my Windows 11 computeris sending a URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR (0x002a).For the CDC is sends an interface request instead.I have attached the pcap files. I had to zip them as 7z for upload.HID and CDC are dumps of the CubeMX examples. Composite is my try to build a composite device.Maybe someone has an idea what might be wrong?Thank you very much

author: ataradov
author_rank: Super Contributor
timestamp: October 09, 2023, 04:11:37 pm
content: I don't know how things are configured in Cube, but combining CDC with anything else is not as easy as putting them all in a sequence. Because CDC uses multiple interfaces, you need to have an interface association descriptor (IAD) that would tell the system how to properly combine interfaces into multiple devices.Here is an example of a composite device that has HID and CDC (also bulk, but you can ignore that) -https://github.com/ataradov/free-dap/blob/master/platform/samd11/usb_descriptors.c

author: katagia
author_rank: Newbie
timestamp: October 10, 2023, 05:00:25 am
content: Hello AlexThank you very much for support.You are right, it was IAD. I was not aware of such a thing.It was already prepared in the code, I had to set an additional define to make it work.I don't really understand why there is an additional define in code that is only meant to get used in a composite device.There is not much documentation for this.That also explained the additional device in windows device manager. Both interfaces of CDC were detected separat. The IAD ties them together.Detection in device manager is fine now. CDC seems to work. I still have some troubke with HID.The default in the ST exmaples is a HID mouse with 4byte packetsize.Regardless of what I want to sent, USBPcap/wireshark always shows "58000a00" as HID data:I asume those should be the 4bytes payload right?Again, thank you for your support!

author: ataradov
author_rank: Super Contributor
timestamp: October 10, 2023, 05:15:37 am
content: That I don't know. Never used ST code, never used HID for actual human interface devices.

author: katagia
author_rank: Newbie
timestamp: October 10, 2023, 04:14:18 pm
content: Just for the records (In case someone else is facing the same problem):Yes, The USB package should be identical to the HID data.The problem was a shared sram region which is used as buffer and for endpoint configuration.The example of ST starts with an buffer for EP0 at 0x18. The same address is used for EP3 configuration (which I used).The solution is to let the buffers start at 0x40 which avoids conflicts.I don't understand why they do that in the examples. The buffer has a size of 2048 bytes so saving some bytes in the lower area wouldn't make a big difference.

author: Faizan
author_rank: Newbie
timestamp: November 11, 2023, 10:57:43 am
content: Could you share your example of setting up CDC + HID? I am trying to setup CDC + WEBUSB but I don't see any request being made to the BOS descriptor that contains the platform capability for the webusb

author: ataradov
author_rank: Super Contributor
timestamp: November 11, 2023, 03:56:13 pm
content: For the host to request BOS descriptor, it is important to set bcdUSB field of the device descriptor to the value 0x0210. Operating systems check that field and don't send that request to plain USB 2.0 devices.

author: Faizan
author_rank: Newbie
timestamp: November 11, 2023, 04:50:17 pm
content: bcdUSB field is set to 0x201 which should be USB version 2.01

author: ataradov
author_rank: Super Contributor
timestamp: November 11, 2023, 05:13:40 pm
content: This is not how USB does it. 0x0210 indicates USB 2.1. Change it, and I bet the host will ask for the BOS descriptor.Although, it looks like BOS was added in 2.01. In any case, I think 0x0210 was necessary to actually make it work.There is nothing you can really do wrong for the BOS other than set bcdUSB incorrectly, so it is worth trying other values just to see if it helps.