cancel
Showing results for 
Search instead for 
Did you mean: 

Sending a unique USB key press report for every 1 ms SOF

Ashun
Associate

TLDR:

I'd like to send 1000 key presses per second over USB to my PC, but USBD_HID_SendReport() blocks for at least 1 ms, so the best I can currently achieve is 500 reports per second.

More detail:

I'm using STM32CubeIDE with an STM32H750 board connected to my PC over USB, and I've managed to get an HID keyboard configured along with a repeating 1ms SOF interrupt. What I'd like to do is send a unique key press every single SOF, but I've run into the problem that USBD_HID_SendReport (or USBD_LL_Transmit or HAL_PCD_EP_Transmit, etc...) won't queue a keypress if the USB device is returning USBD_HID_BUSY.

So for example:

 

USBD_HID_SendReport(&hUsbDeviceFS, myKeyReportA, 8);
HAL_Delay(10); // Delay 10 ms
USBD_HID_SendReport(&hUsbDeviceFS, myKeyReportB, 8);

 

won't send the second report because the USB device is busy. If, however, the delay is set to 16 ms or longer, the USB device will report its state as USBD_HID_IDLE, and the key press will be sent.

The polling delay can be decreased by modifying HID_FS_BINTERVAL in usdb_conf.h (or adjusting it in the .ioc parameter settings), but the lowest this value goes is 1. So any report will block for two subsequent SOF events.

I'm porting a project over from a SAMD51 board in the Arduino IDE, and the USB libraries there will have a USB report block only until the very next SOF, so it's pretty easy to achieve 1000 unique reports.

stm32_vs_arduino_report.png

See the attached image for a comparison with the Arduino USB libraries.

fbar had a similar problem here:
https://community.st.com/t5/embedded-software-mcus/usb-hid-performance-optimization/td-p/237600

Anyone know of a way to send a report every 1 ms? Or clear the BUSY status? Thank you!

1 REPLY 1