CH32V203 USB通信问题

我修改了官方的CompositeKM例程,在其中添加了一个端点用于通信,但是修改后的程序在使用bushound分析通信时发现主机一直在获取字符串描述符,端点上传数据正常,但是隔一段时间就会发送一条命令获取字符串描述符,设备返回后还是继续发送,是什么原因?

这是我修改后的配置描述符

/* Configuration Descriptor Set */
const uint8_t MyCfgDescr[ ] =
{
    /* Configuration Descriptor */
    0x09,                                                   // bLength
    0x02,                                                   // bDescriptorType
    0x5B, 0x00,                                             // wTotalLength
    0x03,                                                   // bNumInterfaces
    0x01,                                                   // bConfigurationValue
    0x00,                                                   // iConfiguration
    0xA0,                                                   // bmAttributes: Bus Powered; Remote Wakeup
    0x32,                                                   // MaxPower: 100mA

    /* Interface Descriptor (Keyboard) */
    0x09,                                                   // bLength
    0x04,                                                   // bDescriptorType
    0x00,                                                   // bInterfaceNumber
    0x00,                                                   // bAlternateSetting
    0x01,                                                   // bNumEndpoints
    0x03,                                                   // bInterfaceClass
    0x01,                                                   // bInterfaceSubClass
    0x01,                                                   // bInterfaceProtocol: Keyboard
    0x00,                                                   // iInterface

    /* HID Descriptor (Keyboard) */
    0x09,                                                   // bLength
    0x21,                                                   // bDescriptorType
    0x11, 0x01,                                             // bcdHID
    0x00,                                                   // bCountryCode
    0x01,                                                   // bNumDescriptors
    0x22,                                                   // bDescriptorType
    0x3E, 0x00,                                             // wDescriptorLength

    /* Endpoint Descriptor (Keyboard) */
    0x07,                                                   // bLength
    0x05,                                                   // bDescriptorType
    0x81,                                                   // bEndpointAddress: IN Endpoint 1
    0x03,                                                   // bmAttributes
    0x08, 0x00,                                             // wMaxPacketSize
    0x0A,                                                   // bInterval: 10mS

    /* Interface Descriptor (Mouse) */
    0x09,                                                   // bLength
    0x04,                                                   // bDescriptorType
    0x01,                                                   // bInterfaceNumber
    0x00,                                                   // bAlternateSetting
    0x01,                                                   // bNumEndpoints
    0x03,                                                   // bInterfaceClass
    0x01,                                                   // bInterfaceSubClass
    0x02,                                                   // bInterfaceProtocol: Mouse
    0x00,                                                   // iInterface

    /* HID Descriptor (Mouse) */
    0x09,                                                   // bLength
    0x21,                                                   // bDescriptorType
    0x10, 0x01,                                             // bcdHID
    0x00,                                                   // bCountryCode
    0x01,                                                   // bNumDescriptors
    0x22,                                                   // bDescriptorType
    0x34, 0x00,                                             // wDescriptorLength

    /* Endpoint Descriptor (Mouse) */
    0x07,                                                   // bLength
    0x05,                                                   // bDescriptorType
    0x82,                                                   // bEndpointAddress: IN Endpoint 2
    0x03,                                                   // bmAttributes
    0x08, 0x00,                                             // wMaxPacketSize
    0x01,                                                    // bInterval: 1mS

    /* Interface Descriptor (EP3) */
    0x09,                                                   // bLength
    0x04,                                                   // bDescriptorType
    0x02,                                                   // bInterfaceNumber
    0x00,                                                   // bAlternateSetting
    0x02,                                                   // bNumEndpoints
    0x03,                                                   // bInterfaceClass
    0x00,                                                   // bInterfaceSubClass
    0x00,                                                   // bInterfaceProtocol: Mouse
    0x00,                                                   // iInterface

    /* HID Descriptor (EP3) */
    0x09,                                                   // bLength
    0x21,                                                   // bDescriptorType
    0x00, 0x01,                                             // bcdHID
    0x00,                                                   // bCountryCode
    0x01,                                                   // bNumDescriptors
    0x22,                                                   // bDescriptorType
    0x22, 0x00,                                             // wDescriptorLength

    /* Endpoint Descriptor (EP3) */
    0x07,                                                   // bLength
    0x05,                                                   // bDescriptorType
    0x83,                                                   // bEndpointAddress: IN Endpoint 3
    0x03,                                                   // bmAttributes
    0x40, 0x00,                                             // wMaxPacketSize
    0x01,                                                    // bInterval: 1mS

    /* Endpoint Descriptor (EP3) */
    0x07,                                                   // bLength
    0x05,                                                   // bDescriptorType
    0x03,                                                   // bEndpointAddress: OUT Endpoint 3
    0x03,                                                   // bmAttributes
    0x40, 0x00,                                             // wMaxPacketSize
    0x01,                                                    // bInterval: 1mS


};

这是通过bushound获取的通信数据

QQ截图20230930221133.png

你好,从抓包数据看,80 06 02 03 09 04 0a 02,最后两个数据不太正常,默认是ff 00,0a 02表示希望获取的长度是0x2a0,可能是代码逻辑问题,之前告诉主机,这个描述符的长度是0x2a0。

可以留个邮箱,有KM+HID的例程,节后发给你。


好的,我的邮箱是个人信息保护,已隐藏,多谢回复


老哥,别忘了给我发一份例程


有USBD的键鼠加hid的例程可以一块发我一份吗


邮箱已回复


只有登录才能回复,可以选择微信账号登录