This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 USB HID Keyboard dropping keys

I've been using the USB HID Composite example along with the advice from this thread https://devzone.nordicsemi.com/f/nordic-q-a/38271/writing-words-to-usb-composite-keyboard-in-usbd_hid_composite/147826#147826 to develop a virtual keyboard.

I am able to run the example fine (pressing the button on the nRF Dongle creates a key press), but as soon as I try to send many characters, I notice key events get dropped. For example, if I try to send "hello" every time the key is pressed, I notice that only 1/10 times all 5 key-down and all 5 key-up events are sent (I have a USB logger running on the VM the dongle is connected to).

I've tried both sending a new key on APP_USBD_HID_USER_EVT_IN_REPORT_DONE as well as using an app_timer with a period set to 200ms. Both experience dropped events.

Another thread with a similar problem https://devzone.nordicsemi.com/f/nordic-q-a/53692/hid-keyboard-and-central-ble-missing-keyboard-presses/217411#217411 was resolved because "USBD is being saturated" and the solution was to turn off CLI and logging. I do not have CLI and my logging is through UART, so I don't think this affects me. But what other possibilities could lead to USBD being saturated? Is there any way I can detect this in code?

  • So to clarify, what's the expected behavior of app_usbd_hid_kbd_key_control()?

    If I call it multiple times (< 8) then all the keys should show up in the same report right?

    If I call it after APP_USBD_HID_USER_EVT_IN_REPORT_DONE, it should send a new report? Is there another way to force a new HID report other than waiting for that event?

    I'm not too familiar with USB HID but I noticed when connected to a Mac (OSX), APP_USBD_HID_USER_EVT_IN_REPORT_DONE is seen at an interval even without any calls to app_usbd_hid_kbd_key_control. On Linux and Windows (VM), I see it only after I call app_usbd_hid_kbd_key_control.

Related