Showing results for 
Search instead for 
Did you mean: 

stm32f4 usb packet length

Posted on November 04, 2016 at 20:00


I am using stm32f4 usb custom hid usb stack. For now i can send and receive just 64Byte packets. When i want to send or receive more packets like 512Byte, the stack crashes. I use the tx and rx packets length for 64Byte defines like this :

&sharpdefine CUSTOM_HID_EPOUT_SIZE                0x40

&sharpdefine CUSTOM_HID_EPIN_SIZE                 0x40

I use the send hid report function like this:


It works for 64Byte but i can not increase the packet length. Any advise??

#hid #usb #device
Posted on November 04, 2016 at 22:08

Is this a USB-FS device?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 05, 2016 at 08:45

Hi Clive,

This is USB-HS device configured by cubemx.
Posted on November 05, 2016 at 14:06

Hi rapid84,

On high-speed (HS) bus also, the MPS (Max Packet Size) of HID interrupt endpoint(s) is limited to 64 bytes, under current implementation of built-in HID driver on major OS (Windows, Mac and Linux).

By the USB 2.0 spec, HS interrupt endpoint may have MPS of greater than 64 bytes. But such an endpoint should be declared on an alternate interface, not on the default one. Unfortunately, current OS HID drivers don't have any API to switch to the alternate interface. And then, above limitation is applied.

Even under above limitation, you may declare ''report size'' of greater than 64 bytes on the report descriptor.

Such large reports are exchanged by splitting into 64 bytes packets on the bus. USBD_HID_SendReport() accepts such a large report in single call. The stack and the device hardware split the report into packets of MPS. On the host side, host controller hardware gathers the packets into single report. Your HID host application retrieves full-size report in single API call. In this way, you don't need to be aware of the MPS at all, except that each packet takes (micro-)frame to be carried over. (If the transfer speed would be in your concern for such a large-size report, apply Set_/Get_Report over the default endpoint, which should be faster than interrupt endpoints)


Posted on November 05, 2016 at 16:09

hi tsuneo,

Thank you for information. By the way i have one more question about USBD_CUSTOM_HID_SendReport function. When it is called, it does not send the Tx Buffer immediately because of the usb stack.  But i need an immediate function that sends the tx buffer when it is called like uart tx sending. If you have any information, share me..