cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID keyboard: Windows & Linux send LED reports twice?

Nickelgrass
Senior II

Hello,

I made a simple USB HID keyboard with a STM32F042 in bare metal (no HAL, no LL). Everything works great. Including LEDs and media key support. 

The only strange thing I am observing is that windows and linux are both sending the LED report twice in a row (the second one comes directly after the minimum poll ~10ms later). The first report is always 0x01 and the second one is the actual state of the LEDs. Now I could implement a "filter" but I was wondering if this is normal behavior? Or could I have an issue in my descriptor?

Thanks 

Kind regards

1 ACCEPTED SOLUTION

Accepted Solutions
Nickelgrass
Senior II

So it seems this is a normal behaviour if there is more than one interface on the device. The first report is always the ID. Simple workaround is to assign an ID outside/higher than the LEDs (like ID 0x80 for the standard keyboard keys) and only set the LEDs if the report is lower.

View solution in original post

3 REPLIES 3
Nickelgrass
Senior II

So it seems this is a normal behaviour if there is more than one interface on the device. The first report is always the ID. Simple workaround is to assign an ID outside/higher than the LEDs (like ID 0x80 for the standard keyboard keys) and only set the LEDs if the report is lower.

Grant Bt
Senior II

Interesting. Any chance you could attach a capture from a bus analyzer?

Hello,

here is a Saleae Logic 2 capture. You will see the USB lines and two debug lines (If the USB is not decoded right away just go to analyzers and then in the three dot menu of the USB analyzer click restart to trigger the decoding). DB2 gets a pulse each time a LED packet is received to make it easier to find the right packets. I have set the ID to 0x80. You can clearly see two packets sent to endpoint 1 directly after each other (7ms). One has the content 0x80 and the second one the LED status. If I change the ID the content of the packet changes accordingly. I tried to put the ID and the LED data in one report which did not work.

Maybe anyone could elaborate on this. If you cannot open the capture you can either install Logic 2 or drop me a note and I can export it as text. Am interested in any feedback.

Regards