打印

STM32F103 USB 实现双接口(Keypad+Mouse)的问题!!

[复制链接]
7774|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
利用STM USB固件库 单独实现多端点HID传输、Mouse 或Keypad均没有任何问题!
在实现双接口设备时总线挂起!!!!!
/* USB Configuration Descriptor */如下
/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */

const u8 CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
  {
    0x09,                                                                             /* bLength: Configuation Descriptor size */
    USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
    CUSTOMHID_SIZ_CONFIG_DESC,                      /* wTotalLength: Bytes returned */
    0x00,
    0x02,         /* bNumInterfaces: 2 interface */
    0x01,         /* bConfigurationValue: Configuration value */
    0x00,         /* iConfiguration: Index of string descriptor describing the configuration*/
    0x80,         /* bmAttributes: Bus powered */
    0x32,         /* MaxPower 100 mA: this current is used for detecting Vbus */
   
    /************** Descriptor of Custom HID mouse  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 */
    0x01,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
    0x02,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
    0,            /* iInterface: Index of string descriptor */
    /******************** Descriptor of Custom HID HID ********************/
    /* 18 */
    0x09,         /* bLength: HID Descriptor size */
    HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
    0x10,         /* bcdHID: HID Class Spec release number */
    0x01,
    0x00,         /* bCountryCode: Hardware target country */
    0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
    0x22,         /* bDescriptorType */
    CUSTOMHID_SIZ_REPORT_Mouse_DESC,/* wItemLength: Total length of Report descriptor */
    0x00,
    /******************** Descriptor of Custom HID Mouse endpoints ******************/
    /* 27 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
    0x81,          /* bEndpointAddress: Endpoint Address (IN) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x05,          /* wMaxPacketSize: 5 Bytes max */
    0x00,
    0x0A,          /* bInterval: Polling Interval (10 ms) */
    /* 34 */
   /************** Descriptor of Custom HIDKeypad  interface ****************/
    0x09,         /* bLength: Interface Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
    0x01,         /* bInterfaceNumber: Number of Interface */
    0x00,         /* bAlternateSetting: Alternate setting */
    0x01,         /* bNumEndpoints */
    0x03,         /* bInterfaceClass: HID */
    0x01,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
    0x01,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
    0,            /* iInterface: Index of string descriptor */
    /******************** Descriptor of Custom HID HID ********************/
    /* 43 */
    0x09,         /* bLength: HID Descriptor size */
    HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
    0x10,         /* bcdHID: HID Class Spec release number */
    0x01,
    0x00,         /* bCountryCode: Hardware target country */
    0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
    0x22,         /* bDescriptorType */
    CUSTOMHID_SIZ_REPORT_Keypad_DESC,/* wItemLength: Total length of Report descriptor */
    0x00,
    /******************** Descriptor of Custom HID endpoints ******************/
    /* 52*/
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
    0x82,          /* bEndpointAddress: Endpoint Address (IN) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x08,          /* wMaxPacketSize: 8 Bytes max */
    0x00,
    0x0a,          /* bInterval: Polling Interval (10 ms) */
    /*59 */
  }; /* CustomHID_ConfigDescriptor */
在USB 协议分析仪测试发现在在取得字符串后又一次取得完整ConfigDescriptor 后总线就挂起了!!
实在找到不到原因所,问题还是在于没有完全搞懂USB固件库,请教各位高手指点!!!!
Email :gwb_2@163.com
沙发
香水城| | 2010-5-29 17:20 | 只看该作者
ConfigDescriptor 有问题!!

为什么第1个interface descriptor中bNumEndpoints = 2?

使用特权

评论回复
板凳
32777221| | 2010-5-30 10:56 | 只看该作者
我是jackguoMCU但是没办法登录,只好换一个ID了!!
谢谢香水城主的回复,你提到的地方是我贴上来的时候写错了!!

为什么第1个interface descriptor中bNumEndpoints = 2?

应该是interface descriptor中bNumEndpoints = 1

使用特权

评论回复
地板
香水城| | 2010-5-30 12:12 | 只看该作者
那么你再好好看看,程序中还有哪里写错的地方。

使用特权

评论回复
5
32777221| | 2010-6-1 21:01 | 只看该作者
唉!!为啥没人帮忙解答呢!!!

:dizzy:

期待ST高手指点!!!!

使用特权

评论回复
6
香水城| | 2010-6-1 21:28 | 只看该作者
唉!!为啥没人帮忙解答呢!!!

:dizzy:

期待ST高手指点!!!!
32777221 发表于 2010-6-1 21:01


发帖时应该是直接从程序中拷贝出来的,这样也能够有错,所以我在4楼才会让你再好好看看,程序中还有哪里写错的地方。

如果要人帮忙,你总要提供足够的信息呀,我们是没有本事仅凭现象而知道根源。

使用特权

评论回复
7
lxyppc| | 2010-6-1 23:33 | 只看该作者
除了改Descriptor
你还需要更改usb_prop.c中的一些代码

顺便打个广告,下面的工程用一片STM32实现了键盘,鼠标,游戏杆和摄像头
https://bbs.21ic.com/icview-166274-1-1.html

使用特权

评论回复
8
32777221| | 2010-6-5 13:03 | 只看该作者
多谢 lxyppc  对比了一下你的程序,顺利实现了 Keypad+Mouse 功能!!
主要修改了以下二个地方:

1):
if ((RequestNo == GET_DESCRIPTOR)
      && (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
      )
      //&& (pInformation->USBwIndex0 == 0))
  {
    if (pInformation->USBwValue1 == REPORT_DESCRIPTOR)
      CopyRoutine = CustomHID_GetReportDescriptor;
    else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE)
      CopyRoutine = CustomHID_GetHIDDescriptor;
  } /* End of GET_DESCRIPTOR */

2);
u8 *CustomHID_GetReportDescriptor(u16 Length)
{                       
  u8 wIndex0 = pInformation->USBwIndex0;
  if (wIndex0 ==0)
   return Standard_GetDescriptorData(Length, &CustomHID_Hid_Mouse_Descriptor);
  else
   return Standard_GetDescriptorData(Length, &CustomHID_Hid_Keypad_Descriptor);
}

使用特权

评论回复
9
lsj9383| | 2013-1-20 14:04 | 只看该作者
32777221 发表于 2010-6-5 13:03
多谢 lxyppc  对比了一下你的程序,顺利实现了 Keypad+Mouse 功能!!
主要修改了以下二个地方:

楼主,可以分享下您的工程吗?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

1

粉丝