【问题标题】:HID terminal for windows用于 Windows 的 HID 终端
【发布时间】:2019-03-27 11:02:30
【问题描述】:

我已经为我的 STM32 设备开发了一个固件。在这个设备中,我定义了一个 CUSTOM 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 上测试了我的设备的发送/接收字符串,它工作得很好(一个简单的回显字符串到 hidraw 设备)。 现在我正在尝试在 Windows 中开发一个简单的程序(尝试使用 v7x64 和 v10x64)。我已经测试了很多库:

在我的测试中,我发送这样的消息:

0x00 (Report ID)
0x41 (Report payload) (A)
...

但在我的所有测试中,我发现并非所有消息都发送到设备。例如,我需要在设备收到消息之前发送 10 次或更多次相同的字符串。 如何改善 Windows 和设备之间的通信?

【问题讨论】:

  • 如果它适用于 Linux 而不是 windows,则问题通常是字符串的终止字符。您使用什么字符来终止消息?您是否发送二进制数据。如果是这样,您需要在发送数据之前添加消息的长度。
  • 在 windows 中,字符串以回车和 NL 结束。在 Linux 中它只是 NL。
  • 我在每个环境中都使用 NL

标签: c# c++ c stm32 wdk


【解决方案1】:

经过大量调试,我发现了问题。

在 STM32 库上可以定义 HID 缓冲区大小

#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE ...

Unix 系统忽略了这个缓冲区大小的控制,但是 Windows 没有! 就我而言,我定义了一个 1024 字节的缓冲区(在 USB FS 版本中)。当我尝试发送消息时,Windows 发送一个 64 字节的块,并且它无法从 USB 接收任何字节,直到缓冲区未满。

将缓冲区大小更改为正确的值(64 字节)后,在 Windows 上也可以正常通信。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 2021-08-27
    • 2021-09-02
    • 1970-01-01
    • 2022-07-23
    • 2020-10-11
    相关资源
    最近更新 更多