[STM32F1] 虚拟串口+hid

[复制链接]
 楼主| yang4469 发表于 2014-3-29 18:16 | 显示全部楼层 |阅读模式
我参考这个帖子里面https://bbs.21ic.com/forum.php?mod=viewthread&tid=554720,想做一个vcp+hid复合设备
分开的两个hid和vcp都没问题,端点地址,端点设置都已经整合,能枚举出复合设备
驱动包INF文件对应+MI_01,PC端安装驱动后有感叹号。hid没问题,能够正常通信,vcp不行。
奇怪之处在于我将hid和vcp的配置顺序互换,pc驱动改为+MI_00后,vcp正常通信,hid不行
设备描述符
  1. const uint8_t Virtual_Com_Port_DeviceDescriptor[] =
  2.   {
  3.     0x12,   /* bLength */
  4.     USB_DEVICE_DESCRIPTOR_TYPE,     /* bDescriptorType */
  5.     0x00,
  6.     0x02,   /* bcdUSB = 2.00 */
  7.           
  8.           /*******************************/
  9.     0xef,   // bDeviceClass : each interface define the device class
  10.     0x02,   // bDeviceSubClass
  11.     0x01,   // bDeviceProtocol
  12.     0x40,   /* bMaxPacketSize0 */
  13.     0x83,
  14.     0x04,   /* idVendor = 0x0483 */
  15.     0x66,
  16.     0x75,   /* idProduct = 0x7564 */
  17.     0x00,
  18.     0x02,   /* bcdDevice = 2.00 */
  19.     1,              /* Index of string descriptor describing manufacturer */
  20.     2,              /* Index of string descriptor describing product */
  21.     3,              /* Index of string descriptor describing the device's serial number */
  22.     0x01    /* bNumConfigurations */
  23.   };
配置描述符
  1. const uint8_t Virtual_Com_Port_ConfigDescriptor[VIRTUAL_COM_PORT_SIZ_CONFIG_DESC] =
  2.   {
  3.     /*Configuration Descriptor*/
  4.     0x09,   /* bLength: Configuration Descriptor size */
  5.     USB_CONFIGURATION_DESCRIPTOR_TYPE,      /* bDescriptorType: Configuration */
  6.     VIRTUAL_COM_PORT_SIZ_CONFIG_DESC,       /* wTotalLength:no of returned bytes */
  7.     0x00,
  8.     0x03,   /* bNumInterfaces: 3interface */
  9.     0x01,   /* bConfigurationValue: Configuration value */
  10.     0x00,   /* iConfiguration: Index of string descriptor describing the configuration */
  11.     0xC0,   /* bmAttributes: self powered */
  12.     0x32,   /* MaxPower 0 mA */
  13.     /*Interface Descriptor*/
  14.           
  15.         0x08,        //描述符大小
  16.     0x0B,        //IAD描述符类型
  17.     0x00,        // bFirstInterface
  18.     0x01,        // bInterfaceCount
  19.     0x03,        // bFunctionClass:HID
  20.     0x00,        // bFunctionSubClass
  21.     0x00,        // bFunctionProtocol
  22.     0x05,        // iFunction
  23.           

  24.           
  25.     /************** Descriptor of Custom HID interface ****************/
  26.     /* 18*/
  27.     0x09,         /* bLength: Interface Descriptor size */
  28.     0x04,/* bDescriptorType: Interface descriptor type */
  29.     0x00,         /* bInterfaceNumber: Number of Interface */
  30.     0x00,         /* bAlternateSetting: Alternate setting */
  31.     0x02,         /* bNumEndpoints */
  32.     0x03,         /* bInterfaceClass: HID */
  33.     0x00,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
  34.     0x00,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
  35.     0,            /* iInterface: Index of string descriptor */
  36.        
  37.          /******************** Descriptor of Custom HID HID ********************/
  38.     /* 27 */
  39.     0x09,         /* bLength: HID Descriptor size */
  40.     0x21, /* bDescriptorType: HID */
  41.     0x00,         /* bcdHID: HID Class Spec release number */
  42.     0x01,
  43.     0x00,         /* bCountryCode: Hardware target country */
  44.     0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
  45.     0x22,         /* bDescriptorType */
  46.     CustomHID_SIZ_ReportDescriptor,/* wItemLength: Total length of Report descriptor */
  47.     0x00,
  48.     /******************** Descriptor of Custom HID endpoints ******************/
  49.     /* 34 */
  50.     0x07,          /* bLength: Endpoint Descriptor size */
  51.     0x05, /* bDescriptorType: */

  52.     0x81,          /* bEndpointAddress: Endpoint Address (IN) */
  53.     0x03,          /* bmAttributes: Interrupt endpoint */
  54.     0x08,          /* wMaxPacketSize: 2 Bytes max */
  55.     0x00,
  56.     0x20,          /* bInterval: Polling Interval (32 ms) */
  57.     /* 41 */
  58.            
  59.     0x07,        /* bLength: Endpoint Descriptor size */
  60.     0x05,        /* bDescriptorType: */
  61.                         /*        Endpoint descriptor type */
  62.     0x01,        /* bEndpointAddress: */
  63.                         /*        Endpoint Address (OUT) */
  64.     0x03,        /* bmAttributes: Interrupt endpoint */
  65.     0x08,        /* wMaxPacketSize: 2 Bytes max  */
  66.     0x00,
  67.     0x20,        /* bInterval: Polling Interval (20 ms) */

  68.           
  69.           
  70.         0x08,        // 描述符大小
  71.     0x0B,        // IAD描述符类型
  72.     0x01,        // bFirstInterface
  73.     0x02,        // bInterfaceCount
  74.     0x02,        // bFunctionClass: CDC Class
  75.     0x02,        // bFunctionSubClass
  76.     0x01,        // bFunctionProtocol
  77.     0x04,        // iFunction


  78.     0x09,   /* bLength: Interface Descriptor size */
  79.     USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: Interface */
  80.     /* Interface descriptor type */
  81.     0x01,   /* bInterfaceNumber: Number of Interface */
  82.     0x00,   /* bAlternateSetting: Alternate setting */
  83.     0x01,   /* bNumEndpoints: One endpoints used */
  84.     0x02,   /* bInterfaceClass: Communication Interface Class         CDC接口*/
  85.     0x02,   /* bInterfaceSubClass: Abstract Control Model */
  86.     0x01,   /* bInterfaceProtocol: Common AT commands */
  87.     0x00,   /* iInterface: */
  88.     /*Header Functional Descriptor*/
  89.     0x05,   /* bLength: Endpoint Descriptor size */
  90.     0x24,   /* bDescriptorType: CS_INTERFACE */
  91.     0x00,   /* bDescriptorSubtype: Header Func Desc */
  92.     0x10,   /* bcdCDC: spec release number */
  93.     0x01,
  94.     /*Call Management Functional Descriptor*/
  95.     0x05,   /* bFunctionLength */
  96.     0x24,   /* bDescriptorType: CS_INTERFACE */
  97.     0x01,   /* bDescriptorSubtype: Call Management Func Desc */
  98.     0x00,   /* bmCapabilities: D0+D1 */
  99.     0x02,   /* bDataInterface: 2 */
  100.     /*ACM Functional Descriptor*/
  101.     0x04,   /* bFunctionLength */
  102.     0x24,   /* bDescriptorType: CS_INTERFACE */
  103.     0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
  104.     0x02,   /* bmCapabilities */
  105.     /*Union Functional Descriptor*/
  106.     0x05,   /* bFunctionLength */
  107.     0x24,   /* bDescriptorType: CS_INTERFACE */
  108.     0x06,   /* bDescriptorSubtype: Union func desc */
  109.     0x01,   /* bMasterInterface: Communication class interface */
  110.     0x02,   /* bSlaveInterface0: Data Class Interface */
  111.     /*Endpoint 2 Descriptor*/
  112.     0x07,   /* bLength: Endpoint Descriptor size */
  113.     USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
  114.     0x82,   /* bEndpointAddress: (IN2) */
  115.     0x03,   /* bmAttributes: Interrupt */
  116.     VIRTUAL_COM_PORT_INT_SIZE,      /* wMaxPacketSize: */
  117.     0x00,
  118.     0xFF,   /* bInterval: */
  119.     /*Data class interface descriptor*/
  120.     0x09,   /* bLength: Endpoint Descriptor size */
  121.     USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: */
  122.     0x02,   /* bInterfaceNumber: Number of Interface */
  123.     0x00,   /* bAlternateSetting: Alternate setting */
  124.     0x02,   /* bNumEndpoints: Two endpoints used */
  125.     0x0A,   /* bInterfaceClass: CDC */
  126.     0x00,   /* bInterfaceSubClass: */
  127.     0x00,   /* bInterfaceProtocol: */
  128.     0x00,   /* iInterface: */
  129.     /*Endpoint 3 Descriptor*/
  130.     0x07,   /* bLength: Endpoint Descriptor size */
  131.     USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
  132.     0x03,   /* bEndpointAddress: (OUT3) */
  133.     0x02,   /* bmAttributes: Bulk */
  134.     VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
  135.     0x00,
  136.     0x00,   /* bInterval: ignore for Bulk transfer */
  137.     /*Endpoint 1 Descriptor*/
  138.     0x07,   /* bLength: Endpoint Descriptor size */
  139.     USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
  140.     0x84,   /* bEndpointAddress: (IN1) */
  141.     0x02,   /* bmAttributes: Bulk */
  142.     VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
  143.     0x00,
  144.     0x00,    /* bInterval */       
  145.   };

 楼主| yang4469 发表于 2014-3-31 10:43 | 显示全部楼层
当用官网的VID/PID,更新后驱动后蓝屏,泪奔。。。。
 楼主| yang4469 发表于 2014-4-1 13:10 | 显示全部楼层
解决了,原来是系统问题,重新装了个完整系统,vcp的驱动是调用系统文件安装
 楼主| yang4469 发表于 2014-4-2 11:33 | 显示全部楼层
更正:HID不需要添加IAD描述符
xiake26 发表于 2014-9-13 17:55 | 显示全部楼层
楼主能分享一下你最后用的驱动文件吗?我也改了一个,但是只能识别hid鼠标,串口不能正确识别。

stmcdc.zip

753 Bytes, 下载次数: 17

 楼主| yang4469 发表于 2014-9-16 15:09 | 显示全部楼层
xiake26 发表于 2014-9-13 17:55
楼主能分享一下你最后用的驱动文件吗?我也改了一个,但是只能识别hid鼠标,串口不能正确识别。 ...

我就用的官网的驱动,系统最好是msdn的原版非删减系统,更改vid、pid时,记得添加_MI00(如果虚拟串口的IAD序号为0)
zjwyczj 发表于 2014-10-16 10:40 | 显示全部楼层
本帖最后由 zjwyczj 于 2014-10-16 13:55 编辑

不错
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

267

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部