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?

Parents Reply Children
  • In one approach I tried calling app_usbd_hid_kbd_key_control on the next character as soon as I receive the APP_USBD_HID_USER_EVT_IN_REPORT_DONE event for the last character. In a second approach, I tried calling it in a 200ms app timer. In a third approach, I tried querying a "sent key" flag in a 200ms app timer (the atomic flag set after APP_USBD_HID_USER_EVT_IN_REPORT_DONE) and send the key after seeing the flag.

    In all three cases, I see about one dropped key event (key up or down) in about every 3 sent.

  • Some more questions for debugging:

    Can you provide detailed chip markings of the nRF52840?

    Is this your own hardware or nRF52840-DK?

    Do you experience the same if you use an nRF52840-DK with the nRF5 SDK example project as-is with no modifications?

  • This is the nRF52840 Dongle (pca10059) (I will provide chip markings when I get home). It is not the DK. I ported the example for pca10056 with minor changes in the config.h. The example code itself works (USB HID device enumerates and key press works).

    Unfortunately, I do not currently own a nRF52840-DK.

    EDIT: Markings NS2840 QIAAD0 1929AW

  • The chip markings are good.

    I recommend to get yourself an nRF52840-DK, then you will have a ready made hardware and software that work out of the box. I can't really think of anything that fails the way you describe.

    Best regards,
    Kenneth

  • 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