cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F373 usb custom hid. I have encountered a problem.

Daniil Zotkin
Associate
Posted on December 20, 2017 at 13:50

STM32F373 slow usb custom hid cubemx. I have encountered a problem. I can easily configure usb custom hid to work but I can't achieve acceptable speed of usb. I am trying to send array of 1200 bytes. The array should be divided into 64 bytes (bits?) packets. The fact is that the array is transmitted for 20 seconds. It's only 60 bytes per second. It's too far from maximum 1.5 mb/sec. What should I do?

There is my Report descriptor.

__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
 /* USER CODE BEGIN 0 */ 
 0x06, 0x00, 0xff, //USAGE_PAGE (Vendor Defined Page 1)
 0x09, 0x01, //USAGE (Vendor Usage 1)
 0xa1, 0x01, //COLLECTION (Application)
 0x85, 0x01, //REPORT_ID (1)
 0x09, 0x01, //USAGE (Vendor Usage 1)
 0x75, 0x08, //REPORT_SIZE (8)
 0x96, 0x04, 0xb0, //REPORT_COUNT (1200)
 0x81, 0x82, //INPUT (Data,Var,Abs,Vol)
 /* USER CODE END 0 */ 
 0xC0 /* END_COLLECTION */
}; 
�?�?�?�?�?�?�?�?�?�?�?�?�?�?

AndI am using FREERTOS and there is my sending thread.

uint8_t dataToSend[0x4b1];
void StartMainT(void const * argument)
{
 /* init code for USB_DEVICE */
 MX_USB_DEVICE_Init();
 /* USER CODE BEGIN 5 */
 TickType_t xLastWakeTime;
 TickType_t xIncrement = 100;
 xLastWakeTime = xTaskGetTickCount();
 /* Infinite loop */
 for(;;)
 {
 vTaskDelayUntil(&xLastWakeTime, xIncrement);
 
 dataToSend[0] = 1;
 
 USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, dataToSend, 0x4b1);
 }
 /* USER CODE END 5 */ 
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I am sure that FREERTOS has no influence on usb, becauseI have tried that config without it and there are no differences.

I have tried to send 21 bytes earlier. Only 2.5 packets/sec were transmitted. It seems that hhid->state is almost always is equal to CUSTOM_HID_BUSY. #stm32-f3 #custom-hid #stm32cubemx
1 REPLY 1
Ben K
Senior III
Posted on December 25, 2017 at 12:16

HID class uses interrupt endpoints, which are meant for regular transfer of small data, not for multi-packet payloads.So this class selection may not fit your application's needs the best.

But I digress, what you need to do is to set the bInterval field of your endpoint descriptor to the minimal 1, and the wMaxPacketSize to 64. The default interval setting in the library is 0x20, which means the endpoint is read in every 32th frame, while the MPS is 2 by default, which result in 2 bytes transfer in every 32 ms at full speed. Changing bInterval to 1 and wMaxPacketSize to 64 brings the transfer speed up to 64 bytes / ms.