embeddedusbwindows-driver

Custom USB device - configuration error in Windows


I'm developing a USB device based on STM32 microcontroller. Nothing fancy, one configuration with one interface, that uses no endpoints (except the default Endpoint 0). The device enumerates fine on Ubuntu, the problem happens when I attach the device to a Windows machine. It doesn't work, and I could not find more information than it's something due to configuration descriptor:

enter image description here

Here is the screenshot of the configuration descriptor, as seen on the Ubuntu machine:

Configuration descriptor - Ubuntu

The Wireshark on the Windows machine doesn't see the communication with this device, for some reason (communication with other devices are shown just fine). The logs on the device indicate that the device accepts an address and sends the configuration descriptor, but never receives the SET CONFIGURATION command.

Please suggest how I can find some more descriptive error message in Windows or what may be wrong with my device.


Solution

  • Figured that out.

    My device was sending wrong length for the configuration descriptor.

    My Linux machine has first asked for 9 bytes of the descriptor to figure out its total length, then asked for the descriptor again, requesting the <total_length> number of bytes. Well, my device was programmed to send back the exact number of bytes the host has requested, namely:

    HAL_PCD_EP_Transmit(hpcd, 0x00, configuration_descriptor, requested_length);
    

    While my Windows machine have asked for the configuration descriptor only once, requesting 255 bytes. Let aside that it was more than my buffer have contained, my device is only able to send one packet. Since max packet size was configured to be 64 bytes, the host was expecting more packets after receiving the whole descriptor. Long story short, the fix was the following:

            if (requested_length > sizeof(configuration_descriptor)) {
                requested_length = sizeof(configuration_descriptor);
            }
            HAL_PCD_EP_Transmit(hpcd, 0x00, configuration_descriptor, requested_length);