How to call MX_USB_HOST_Process() on HID host projects with large main loop?
Hello,
I followed the ST training example to get an HID host working to interface a USB keyboard. Keys are correctly decoded on the USBH_HID_EventCallback() function. But, when having a main loop that lasts more than the milliseconds specified on the USB keyboard endpoint descriptor boot mode (i.e. bInterval = 8 or 10 ms), MX_USB_HOST_Process() is not called enough often and the class HID state machine stucks in HID_GET_DATA.
(see post https://community.st.com/s/question/0D53W00000qvJqOSAU/whats-the-problem-with-usb-host-hid)
So, how to call periodically MX_USB_HOST_Process() if the main loop needs let's say 30ms to run? Should I call MX_USB_HOST_Process() manually on different parts of the code being executed on the loop? That wouldn't be the desired solution... If this is the case, is there any restriction about how often can I call it?
I tried to call MX_USB_HOST_Process() using a background 3ms timer 2 interrupt, but if the HAL library calls USBH_Delay() function, the program gets hang inside it. I solved this setting a lower priority to the TIM2 interrupt to let HAL base tick timer higher priority and now it works and MX_USB_HOST_Process() is being called every 3 ms.
Inside HAL_Init():
· HAL_InitTick(TICK_INT_PRIORITY);
· HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
TIM2 config:
· HAL_NVIC_SetPriority(TIM2_IRQn, 7, 7);
· NVIC_EnableIRQ(TIM2_IRQn);
Any other suggestion better than a periodic Timer interrupt?
BTW, if the keyboard is unplugged from the USB connector and then plugged again, a reset condition happens on the USB stack and a HALDelay(200) + HALDelay(100) is executed prior USB enumeration, leaving the whole program hang for such amount of time of 300ms. This can have side effects on the main loop execution freezed for 300ms.
