Showing results for 
Search instead for 
Did you mean: 

STM32F302C8T6: CubeMX generated custom HID can only receive two packets if "USBD_CUSTOM_HID_SendReport" is used to send data back

Associate II

I have a custom board with STM32F302C8T6. I generated a custom HID project by CubeMX(STM32Cube_FW_F3_V1.11.3), and found that only two packets could be received if "USBD_CUSTOM_HID_SendReport" is used to send data back to host.

Here are some more details:

1. is the original code generated by CubeMX. is the modified version. You can compare to see the difference. Also, you could see diff.diff to difference.

2. In windows10 x64, I use a modified version of hid_test to test custom HID read/write. Please see "test.c" for details.

3. In CUSTOM_HID_OutEvent_FS, if "USBD_CUSTOM_HID_SendReport" is called, the first two hid_write and hid_read_timeout will succeed. The following hid_write will fail. Also CUSTOM_HID_OutEvent_FS will be called only twice.

4. If "USBD_CUSTOM_HID_SendReport" is not called, hid_write from host will always succeed (and CUSTOM_HID_OutEvent_FS will be called successfully also).

5. So it looks that if USBD_CUSTOM_HID_SendReport is called, USB will be stuck.

6. I generated a similar project for STM32F103C8T6, everything will be fine, regardless of whether "USBD_CUSTOM_HID_SendReport" is called.

Please help to figure out the issue. Thanks.

Associate II

I can see USTS c0000004 when two packets are sent and received.


Associate II

Currently "USBD_LL_PrepareReceive" is called in "USBD_CUSTOM_HID_DataOut". I think it should be called in "USBD_CUSTOM_HID_DataIn" if data needs to be sent "USBD_CUSTOM_HID_SendReport" called in "CUSTOM_HID_OutEvent_FS".