Help debugging a USB composite HID device
I'm trying to create a composite HID device, mouse+joystick. I'm using the HID mouse profile as a starting point and then add a second interface. I also used an already existing example as a guide: the Arduino core based on the HAL is maintained by ST, and implements a composite HID device mouse+keyboard, which is then used by the Arduino Mouse and Keyboard libraries https://github.com/stm32duino. For what is worth, I modified that code to implement a mouse+joystick device, and everything works as expected in Arduino. Unfortunately that code is not based on the latest HAL, so I cannot simply swap it.
I then tried to use the same USB description and init function to create my device in a standard STM32CubeIDE project (below). I can see that the device initializes properly, Windows recognizes it as a composite HID device with the right characteristics, and the mouse interface works perfectly. If on the other hand I try to send data via the joystick interface, it stops transmitting. I used USBpcap to capture the traffic on the PC side, and I see that the device sends all the right data, initializes 2 interfaces and then windows sends an interrupt request to get data from interface 1 and 2. Interface 1 (the mouse) sends a packet back (4 bytes, as expected), while interface 2 never responds.
By debugging the HAL code (which it's its own form of punishment, I guess :) I can see that the STM32 seems to get an interrupt, but somehow the USB_ReadDevInEPInterrupt() function doesn't seem to return a valid value when the interrupt is from the second interface. I can see that function returning 1 when called from HAL_PCD_IRQHandler() for the interface 1 IRQ, but never returning 1 for the second interface. SO the payload for interface 2 is never sent, leaving the device in HID_BUSY state, and getting blocked
I'm enclosing the relevant portion of my HID definition, hoping someone can spot the problem or suggest how to further debug it. I have been staring at this for hours with no real progress. The device is FS, and the rest of the code is identical to the standard HID HAL code
(code follows in next post to avoid errors from the forum software)
