你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

stm32f407 usb hid收发数据问题

[复制链接]
lanbu 提问时间:2019-1-19 15:51 /
求教,在做stm32f407 usb hid开发,根据官方例子修改而来,使用的是HS接口,FS模式,PC可以成功识别usb hid设备。现在通过Bus Hound给设备发送数据,stm32可以收到;但是通过调用USBD_CUSTOM_HID_SendReport()函数来向PC发送数据,Bus Hound始终收不到发送的数据,调试也不能进入USBD_CUSTOM_HID_DataIn()函数。
请问这是什么原因呢?

我的各种设备描述符的配置如下:
(1)设备描述符
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
{
  0x12,                       /*bLength */
  USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
  0x00,                       /*bcdUSB */
  0x02,
  0x00,                       /*bDeviceClass*/
  0x00,                       /*bDeviceSubClass*/
  0x00,                       /*bDeviceProtocol*/
  USB_OTG_MAX_EP0_SIZE,      /*bMaxPacketSize*/
  LOBYTE(USBD_VID),           /*idVendor*/
  HIBYTE(USBD_VID),           /*idVendor*/
  LOBYTE(USBD_PID),           /*idVendor*/
  HIBYTE(USBD_PID),           /*idVendor*/
  0x50,                       /*bcdDevice rel. 2.00*/
  0x10,
  USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
  USBD_IDX_PRODUCT_STR,       /*Index of product string*/
  USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
  USBD_CFG_MAX_NUM            /*bNumConfigurations*/
} ; /* USB_DeviceDescriptor */


(2)配置描述符
/* USB HID device Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09, /* bLength: Configuration Descriptor size */
  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
  USB_CUSTOM_HID_CONFIG_DESC_SIZ,
  /* wTotalLength: Bytes returned */
  0x00,
  0x01,         /*bNumInterfaces: 1 interface*/
  0x01,         /*bConfigurationValue: Configuration value*/
  0x00,         /*iConfiguration: Index of string descriptor describing
  the configuration*/
  0xE0,         /*bmAttributes: bus powered and Support Remote Wake-up */
  0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/

  /************** Descriptor of Custom HID interface ****************/
  /* 09 */
  0x09,         /*bLength: Interface Descriptor size*/
  USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
  0x00,         /*bInterfaceNumber: Number of Interface*/
  0x00,         /*bAlternateSetting: Alternate setting*/
  0x02,         /*bNumEndpoints*/
  0x03,         /*bInterfaceClass: HID*/
  0x00,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
  0x00,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
  0,            /*iInterface: Index of string descriptor*/
  /******************** Descriptor of Custom HID ********************/
  /* 18 */
  0x09,         /*bLength: HID Descriptor size*/
  CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
  0x11,         /*bcdHID: HID Class Spec release number*/
  0x01,
  0x00,         /*bCountryCode: Hardware target country*/
  0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/
  0x22,         /*bDescriptorType*/
  USBD_CUSTOM_HID_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
  0x00,
  /******************** Descriptor of Custom HID endpoints ***********/
  /* 27 */
  0x07,          /* bLength: Endpoint Descriptor size */
  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

  HID_IN_EP,     /* bEndpointAddress: Endpoint Address (IN) */
  0x03,          /* bmAttributes: Interrupt endpoint */
  HID_IN_PACKET, /* wMaxPacketSize: 2 Bytes max */
  0x00,
  0x20,          /* bInterval: Polling Interval (32 ms) */
  /* 34 */

  0x07,                 /* bLength: Endpoint Descriptor size */
  USB_ENDPOINT_DESCRIPTOR_TYPE,        /* bDescriptorType: */
  /*        Endpoint descriptor type */
  HID_OUT_EP,        /* bEndpointAddress: */
  /*        Endpoint Address (OUT) */
  0x03,        /* bmAttributes: Interrupt endpoint */
  HID_OUT_PACKET,        /* wMaxPacketSize: 2 Bytes max  */
  0x00,
  0x20,        /* bInterval: Polling Interval (20 ms) */
  /* 41 */
} ;


(3)报告描述符
__ALIGN_BEGIN static uint8_t CustomHID_ReportDesc[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
  0x05, 0x8c,                                      /* USAGE_PAGE (ST page) */                       
  0x09, 0x01,            /* USAGE (Demo Kit)               */   
  0xa1, 0x01,            /* COLLECTION (Application)       */            
  /* 5 */

  // The Input report
        0x09,0x03, // USAGE ID - Vendor defined
        0x15,0x00, // LOGICAL_MINIMUM (0)
        0x26,0x00, 0xFF, // LOGICAL_MAXIMUM (255)
        0x75,0x08, // REPORT_SIZE (8bit)
        0x95,0x40, // REPORT_COUNT (64Byte)
        0x81,0x02, // INPUT (Data,Var,Abs)
  /* 18 */

  // The Output report
        0x09,0x04, // USAGE ID - Vendor defined
        0x15,0x00, // LOGICAL_MINIMUM (0)
        0x26,0x00,0xFF, // LOGICAL_MAXIMUM (255)
        0x75,0x08, // REPORT_SIZE (8bit)
        0x95,0x40, // REPORT_COUNT (64Byte)
        0x91,0x02, // OUTPUT (Data,Var,Abs)
  /* 31 */

  0xc0                          /*     END_COLLECTION                     */
};


收藏 评论7 发布时间:2019-1-19 15:51

举报

7个回答
熊二在深圳 回答时间:2019-1-22 10:59:50
STM32能收到,PC不能收到数据,那是你的程序逻辑上出问题。因为枚举成功,那就是说例子里面的已经没有问题,问题出在你自己的程序。收到了PC的东西,是数据?指令?收到后怎么处理?检查一下就可以发现问题了。
胤幻1988 回答时间:2019-1-22 13:14:33
成功的例子,网上大把的,可以参考看下、
我的帖子:https://www.stmcu.org.cn/module/ ... p;page=1#pid2407368
lanbu 回答时间:2019-1-24 09:27:41
笨熊 发表于 2019-1-22 10:59
STM32能收到,PC不能收到数据,那是你的程序逻辑上出问题。因为枚举成功,那就是说例子里面的已经没有问题 ...

PC发给stm32的数据是在回调函数USBD_CUSTOM_HID_DataOut()直接串口输出查看的,我定义的数据长度是64字节的,用Bus Hound直接发送64字节数据,stm32收到后正常串口输出。
但是使用USBD_CUSTOM_HID_SendReport()函数进行数据发送的时候,Bus Hound无法收到数据。
lanbu 回答时间:2019-1-24 09:29:40
胤幻1988 发表于 2019-1-22 13:14
成功的例子,网上大把的,可以参考看下、
我的帖子:https://www.stmcu.org.cn/module/forum/forum.php?mod=v ...

谢谢,我看过你这个例子。也是对照着你的例子研究过,用法都一样。PC端确实收不到。
我还把你的那个程序里面的描述符直接复制替换到我的程序里面,还是不行。
lanbu 回答时间:2019-1-24 09:54:05
我将程序上传下,劳烦各位帮忙看看。感谢。
因为权限问题,不能上传那么大的文件。就附一个网盘链接。
链接:https://pan.baidu.com/s/1paJhWaIpN60CNvgKE-Sa-Q
提取码:h6sj

程序是根据st提供的例程,在stm32f407上面同时使用两个usb接口,两个usb接口都工作于FS模式。HS OTG接口用做Slave,FS接口用做Host。Slave已经在PC上枚举成功,Host也可正常的枚举鼠标键盘,并可打印鼠标做小信息。

1.png
hihi22 回答时间:2019-1-24 11:21:15
之前使用WinDriver驱动时,只有开启WinDriver软件,bus hound软件才能接受到in数据(发正常),你可以借鉴一下,或者直接上自己的驱动
lanbu 回答时间:2019-1-24 12:04:28
hihi22 发表于 2019-1-24 11:21
之前使用WinDriver驱动时,只有开启WinDriver软件,bus hound软件才能接受到in数据(发正常),你可以借鉴一 ...

感谢,我试试

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版