cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 high latency with usb hid game controller

BPoko
Associate

Hi, I'm using an stm32f102 for making usb game controller (custom hid) with 29 buttons. The problem is, that the latency if I check on PC is feelable, too high. I made some tests to figure out the problem, but I don't have any idea yet. If I just report continiusly in the main while with 50ms delays, the indicator led on game controller window on pc just blinks with ~1s. So, seems, don't receive all of the data. If I increase this delay to 100ms it looks almost fine. I tried also to measure latency with camera (measure the time between click sound and the indicator on pc screen). For STM32 was around 5-6 frame with 30fps. I tried also with a good working game controller, it is 2-3 frame. If I report with every 1ms from systick, it's not better. I looked into the send report function and experienced, that the function sometimes returns with busy, even if data send is with 50ms interval. Why? :o In the MCU runs everything on 48MHz and in the test is just a gpio read and report. Any idea?

3 REPLIES 3
BPoko
Associate

I found finally the "bInterval" in the USB descriptor. If I change it to 1, the polling interval will be 10ms (checked with usb analyzer). But why not 1ms? It's not possible? Earlier was 64ms.

Pavel A.
Evangelist III

Polling interval for full speed devices (the case for STM32F0) is in milliseconds. So, value 1 means 1 ms.

However, the host can ignore your interval value and use any other.

-- pa

MSchu.13
Associate

As I recall, the USB HID device class uses primarily "Interrupt" type USB transactions/endpoints. Interrupt endpoints have a guaranteed polling rate that is specified by the bInterval field in the device descriptor, as you noted. The minimum bInterval as stated in the USB specification (for low and full speed devices, at least) is 10mS.

A 10mS polling/update rate works out to a maximum latency of 3.3 frames @ 30 FPS, which is consistent with the response you measured when using your "good working game controller".

I'm not sure how HID-compatible (gaming) devices that claim to support update rates in excess of 100x/s achieve this; I can only guess as I've never put any such on a USB analyzer, but I suspect that they support alternate configurations or interfaces that are non-HID and vendor specific, as using bulk or isochronous endpoints would be the only way I know of to achieve that sort of update rate.