我已经为我的STM32设备开发了一个固件。在这个设备中,我通过这个接口为发送/接收字符串定义了一个自定义HID接口。我的USB接口描述向量:
/**** Descriptor of CUSTOM HID interface ****/
0x09, /*bLength: Interface Descriptor size*/
0x04, /*bDescriptorType: Interface descriptor type*/
0x00, /*bInterfaceNumber: Number of Interface*/
0x00, /*bAlternateSetting: Alternate setting*/
0x02, /*bNumEndpoints*/
0x03, /*bInterfaceClass: CUSTOM_HID*/
0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
0x00, /*iInterface: Index of string descriptor*/
/**** Descriptor of CUSTOM_HID ****/
0x09, /*bLength: CUSTOM_HID Descriptor size*/
0x21, /*bDescriptorType: CUSTOM_HID*/
0x11, /*bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of CUSTOM_HID class descriptors to follow*/
0x22, /*bDescriptorType*/
0x33,/*wItemLength: Total length of Report descriptor*/
0x00,
/**** Descriptor of Custom HID endpoints ****/
0x07, /* bLength: Endpoint Descriptor size */
0x05, /* bDescriptorType: */
0x04, /*bEndpointAddress: Endpoint Address (OUT)*/
0x03, /* bmAttributes: Interrupt endpoint */
0x40, /* wMaxPacketSize (64 bytes) */
0x00,
0x0A, /* bInterval: Polling Interval (10 ms) */
0x07, /*bLength: Endpoint Descriptor size*/
0x05, /*bDescriptorType:*/
0x81, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
0x40, /*wMaxPacketSize (64 bytes) */
0x00,
0x0A, /*bInterval: Polling Interval (10 ms)*/我已经在Linux上测试了我的设备的发送/接收字符串,它工作得很好(一个简单的回显设备)。现在,我正试图在Windows中开发一个简单的程序(尝试使用v7x64和v10x64)。我测试了很多图书馆:
在我的测试中,我发出这样的信息:
0x00 (Report ID)
0x41 (Report payload) (A)
...但在我所有的测试中,我发现并非所有的消息都被发送到设备上。例如,在设备接收消息之前,我需要发送10倍或更多的相同字符串。如何改善Windows与设备之间的通信?
发布于 2019-01-08 16:38:18
经过多次调试,我发现了这个问题。
在STM32库中,可以定义HID缓冲区大小
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE ...Unix系统忽略了这个缓冲区大小的控制,但是Windows没有!在我的例子中,我定义了一个1024字节的缓冲区(在USB版本中)。当我试图发送消息时,windows发送了64个字节的块,在缓冲区未满之前,它无法从USB接收任何字节。
在用正确的值( 64字节)更改缓冲区大小后,通信在Windows上也能很好地工作。
https://stackoverflow.com/questions/52945126
复制相似问题