MCU用的是STM32F103C8T6
用cube生成了一个CUSTOM_HID工程,配置为鼠标、键盘复合设备(但是实验中只发送了鼠标的报告),USB配置如下图
报告描述符如下:
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x01, // REPORT_ID (1)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
/* 54 */
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x85, 0x02, // REPORT_ID (2)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x03, // REPORT_COUNT (3)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x05, // REPORT_SIZE (5)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x09, 0x38, // USAGE (Wheel)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x06, // INPUT (Data,Var,Rel)
0xc0, // END_COLLECTION
0xC0 /* END_COLLECTION */
然后在while循环中只写了如下代码:
//等待USB空闲
while(((USBD_CUSTOM_HID_HandleTypeDef *)(&hUsbDeviceFS)->pClassData)->state == CUSTOM_HID_BUSY){
;
}
HID_Buffer[0] = 0x02;
HID_Buffer[1] = 0x08;
HID_Buffer[2]++;
if(HID_Buffer[2] > 127){
HID_Buffer[2] = 0;
}
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, HID_Buffer, 5);//鼠标测试
通过不断发送递增的HID_Buffer[2] 来判断是否有丢包。
用bus hound抓包现象是:
1、数据发送正常,无丢包
2、数据发送非常慢,可以看到,每两次发送间隔在95ms左右,如下图:
3、如果删除这句:
while(((USBD_CUSTOM_HID_HandleTypeDef *)(&hUsbDeviceFS)->pClassData)->state == CUSTOM_HID_BUSY){
;
}
然后直接10ms发送一次数据,会出现严重的丢包现象。
想问一下各位大神,这个是什么问题呢?因为工程中除了USB没有做其他任何的事情,是哪里配置有问题,还是HAL库的效率本来就这么低?有没有什么办法优化呢?
|
|