cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly call USBX_Device_Process in standalone mode

ksi134340
Visitor

Hi. Last week I received my first STM32U5A5 board and tried to implement USBX HID standalone mode, following this tutorial. Guess what? I managed to make it work and It just works very well!

I should call 

USBX_Device_Process(NULL);

in the main loop so the STM32U5A5 serves as USB HID device. My question is that, is it appropriate to call USBX_Device_Process function in the main loop, while the USB polling rate is 1000 Hz (depending on settings)? When debugging, that function is called multiple times per milliseconds and I'm worrying about some malfunctioning due to the excess of USBX_Device_Process calling. 

Or is it totally fine repeating  the USBX_Device_Process function without carefully configured timers or fitting the timing into the polling rate?

Thanks in advance!

1 REPLY 1
FBL
ST Employee

Hi @ksi134340 & welcome to ST Community,

Calling USBX_Device_Process frequently is expected and normal:

  • USB device stack needs to be serviced continuously to handle USB events promptly.
  • The function is designed to be called often, typically in the main loop.
  • Calling USBX_Device_Process faster than the polling interval just means the stack is ready to respond immediately when the host polls.
  • From performance perspective and CPU load considerations, calling USBX_Device_Process in a tight loop can increase CPU usage. If you have other time-critical tasks, consider adding a small delay or using RTOS scheduling to balance CPU load if needed. Or you can adjust UX_PERIODIC_RATE  in ux_user.h.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.