[USB接口] 好象USB可以枚举成两个VID/PID啊?

[复制链接]
john_lee 发表于 2017-12-15 18:26 | 显示全部楼层
一骑红尘追梦中 发表于 2017-12-15 17:45
现在需要将其做成复合设备,因为AP与BP之间的通信数据有音频数据、网络数据等等,考虑到传输时尽量互不干 ...

如果没有特殊需求,比如多个PID/VID之类,一般不建议做成compound,而应该做成composite,用device中的各种interface来实现各种相应的功能。
一骑红尘追梦中 发表于 2017-12-15 21:13 | 显示全部楼层
john_lee 发表于 2017-12-15 18:26
如果没有特殊需求,比如多个PID/VID之类,一般不建议做成compound,而应该做成composite,用device中的各 ...

一个USB接口实现多个设备,坦白说,对USB复合设备和组合设备分的不是特别的清楚,在设备框架高速和全速结构体中都有IAD描述符,查资料有说USB复合设备一般用IAD实现...就像我上面所说,最终的USB设备具有多路复用的功能,传输各种数据信息,您觉得该设计成哪一种呢?还有,方便的话能加您的联系方式咨询一下吗?真的很急需这方面的帮助,等你的回复
一骑红尘追梦中 发表于 2017-12-15 22:17 | 显示全部楼层
john_lee 发表于 2017-12-15 18:24
如果没有特殊需求,比如多个PID/VID之类,一般不建议做成compound,而应该做成composite,用device中的各种 ...

一个USB接口实现多个设备,坦白说,对USB复合设备和组合设备分的不是特别的清楚,在设备框架高速和全速结构体中都有IAD描述符,查资料有说USB复合设备一般用IAD实现...就像我上面所说,最终的USB设备具有多路复用的功能,传输各种数据信息,您觉得该设计成哪一种呢?还有,方便的话能加您的联系方式咨询一下吗?真的很急需这方面的帮助,等您的回复
一骑红尘追梦中 发表于 2017-12-18 11:28 | 显示全部楼层
本帖最后由 一骑红尘追梦中 于 2017-12-19 17:28 编辑
zhs2007 发表于 2017-8-24 15:48
首选像说明一下,USB复合设备,是指一个配置Configuration下,通过多个接口Interface实现多个独立设备协议 ...

您好!想向您咨询一下问题,就是我的目标平台上有USB OTG接口与串口接口,其中串口接口上接WindowsPC,而由于目标平台将USB定义成CDC_ACM类,WindowsPC缺少相应的驱动,故将USB OTG接口上接LinuxPC进行调试,现在的情况是在Linux主机下可以建立高速模式的通信:
[  409.972173] usb 2-4: new high-speed USB device number 5 using ehci-pci
[  410.105181] usb 2-4: config 1 interface 0 altsetting 0 endpoint 0x84 has an invalid bInterval 255, changing to 11
[  410.105195] usb 2-4: config 1 interface 1 altsetting 0 bulk endpoint 0x1 has invalid maxpacket 64
[  410.105204] usb 2-4: config 1 interface 1 altsetting 0 bulk endpoint 0x82 has invalid maxpacket 64
[  410.106414] usb 2-4: New USB device found, idVendor=xxxx, idProduct=xxxx
[  410.106422] usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  410.106428] usb 2-4: Product: EL Composite device
[  410.106434] usb 2-4: Manufacturer: Expres Logic
[  410.106441] usb 2-4: SerialNumber: 0001
[  410.140701] cdc_acm 2-4:1.0: ttyACM0: USB ACM device
[  410.141131] usbcore: registered new interface driver cdc_acm
[  410.141134] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
此上为USB OTG接口与主机建立通信后的打印信息。在源码中定义了设备框架高速描述符结构体和全速描述符结构体,且都具有IAD描述符,想请教的是:
1、若想将设备接入时默认为低速模式,是不是添加Linux系统下USB低速模式设备的描述符即可(当然还需要修改控制器的寄存器配置)?
2、基于现况,是实现复合设备还是组合设备呢?两者有点混...
希望能得到您的帮助,谢谢!
xcvista 发表于 2017-12-22 01:31 | 显示全部楼层
USB 复合设备其实只有一个 VID/PID,但是在其内部通过 Interface 或 Interface Aggregation 的方式实现了若干不同的设备类。举个例子,如下的设备描述符(截取的 DAP42 源代码,项目本身开源):
  1. static const struct usb_device_config_descriptor usb_device_config_desc =
  2. {
  3.                 .config_descriptor =
  4.                 {
  5.                                 .bLength             = sizeof(struct usb_config_descriptor),
  6.                                 .bDescriptorType     = USB_DTYPE_CONFIGURATION,
  7.                                 .wTotalLength        = sizeof(struct usb_device_config_descriptor),
  8.                                 .bNumInterfaces      = 3,
  9.                                 .bConfigurationValue = 1,
  10.                                 .iConfiguration      = NO_DESCRIPTOR,
  11.                         .bmAttributes        = USB_CFG_ATTR_RESERVED | USB_CFG_ATTR_SELFPOWERED,
  12.                         .bMaxPower           = USB_CFG_POWER_MA(450)
  13.                 },

  14.                 .hid_iad_descriptor =
  15.                 {
  16.                             .bLength             = sizeof(struct usb_iad_descriptor),
  17.                             .bDescriptorType     = USB_DTYPE_INTERFASEASSOC,
  18.                             .bFirstInterface     = 0,
  19.                             .bInterfaceCount     = 1,
  20.                             .bFunctionClass      = USB_CLASS_HID,
  21.                             .bFunctionSubClass   = USB_HID_SUBCLASS_NONBOOT,
  22.                             .bFunctionProtocol   = USB_HID_PROTO_NONBOOT,
  23.                             .iFunction           = 3
  24.                 },
  25.                 .hid_interface_descriptor =
  26.                 {
  27.                             .bLength             = sizeof(struct usb_interface_descriptor),
  28.                             .bDescriptorType     = USB_DTYPE_INTERFACE,
  29.                             .bInterfaceNumber    = 0,
  30.                             .bAlternateSetting   = 0,
  31.                             .bNumEndpoints       = 2,
  32.                             .bInterfaceClass     = USB_CLASS_HID,
  33.                             .bInterfaceSubClass  = USB_HID_SUBCLASS_NONBOOT,
  34.                             .bInterfaceProtocol  = USB_HID_PROTO_NONBOOT,
  35.                             .iInterface          = 3
  36.                 },
  37.                 .hid_descriptor =
  38.                 {
  39.                                 .bLength             = sizeof(struct usb_hid_descriptor),
  40.                                 .bDescriptorType     = USB_DTYPE_HID,
  41.                                 .bcdHID              = VERSION_BCD(1, 1, 1),
  42.                                 .bCountryCode        = USB_HID_COUNTRY_US,
  43.                                 .bNumDescriptors     = 1,
  44.                                 .bDescriptorType0    = USB_DTYPE_HID_REPORT,
  45.                                 .wDescriptorLength0  = sizeof(usb_hid_report_descriptor)
  46.                 },
  47.                 .hid_ep_in_descriptor =
  48.                 {
  49.                         .bLength             = sizeof(struct usb_endpoint_descriptor),
  50.                         .bDescriptorType     = USB_DTYPE_ENDPOINT,
  51.                         .bEndpointAddress    = USB_HID_IN_EP,
  52.                         .bmAttributes        = USB_EPTYPE_INTERRUPT,
  53.                         .wMaxPacketSize      = USB_PKT_SIZE,
  54.                         .bInterval           = 1
  55.                 },
  56.                 .hid_ep_out_descriptor =
  57.                 {
  58.                         .bLength             = sizeof(struct usb_endpoint_descriptor),
  59.                         .bDescriptorType     = USB_DTYPE_ENDPOINT,
  60.                         .bEndpointAddress    = USB_HID_OUT_EP,
  61.                         .bmAttributes        = USB_EPTYPE_INTERRUPT,
  62.                         .wMaxPacketSize      = USB_PKT_SIZE,
  63.                         .bInterval           = 1
  64.                 },

  65.                 .cdc_iad_descriptor =
  66.                 {
  67.                             .bLength             = sizeof(struct usb_iad_descriptor),
  68.                             .bDescriptorType     = USB_DTYPE_INTERFASEASSOC,
  69.                             .bFirstInterface     = 1,
  70.                             .bInterfaceCount     = 2,
  71.                             .bFunctionClass      = USB_CLASS_CDC,
  72.                             .bFunctionSubClass   = USB_CDC_SUBCLASS_ACM,
  73.                             .bFunctionProtocol   = USB_CDC_PROTO_V25TER,
  74.                             .iFunction           = 4
  75.                 },
  76.                 .cdc_ctrl_interface_descriptor =
  77.                 {
  78.                             .bLength             = sizeof(struct usb_interface_descriptor),
  79.                             .bDescriptorType     = USB_DTYPE_INTERFACE,
  80.                             .bInterfaceNumber    = 1,
  81.                             .bAlternateSetting   = 0,
  82.                             .bNumEndpoints       = 1,
  83.                             .bInterfaceClass     = USB_CLASS_CDC,
  84.                             .bInterfaceSubClass  = USB_CDC_SUBCLASS_ACM,
  85.                             .bInterfaceProtocol  = USB_CDC_PROTO_V25TER,
  86.                             .iInterface          = 4
  87.                 },
  88.                 .cdc_header_descriptor =
  89.                 {
  90.                         .bFunctionLength     = sizeof(struct usb_cdc_header_desc),
  91.                         .bDescriptorType     = USB_DTYPE_CS_INTERFACE,
  92.                         .bDescriptorSubType  = USB_DTYPE_CDC_HEADER,
  93.                         .bcdCDC              = VERSION_BCD(1,1,0)
  94.                 },
  95.                 .cdc_call_management_descriptor =
  96.                 {
  97.                         .bFunctionLength     = sizeof(struct usb_cdc_call_mgmt_desc),
  98.                         .bDescriptorType     = USB_DTYPE_CS_INTERFACE,
  99.                         .bDescriptorSubType  = USB_DTYPE_CDC_CALL_MANAGEMENT,
  100.                         .bmCapabilities      = 0,
  101.                         .bDataInterface      = 2
  102.                 },
  103.             .cdc_acm_descriptor =
  104.             {
  105.                 .bFunctionLength         = sizeof(struct usb_cdc_acm_desc),
  106.                 .bDescriptorType         = USB_DTYPE_CS_INTERFACE,
  107.                 .bDescriptorSubType      = USB_DTYPE_CDC_ACM,
  108.                 .bmCapabilities          = USB_CDC_CAP_LINE,
  109.             },
  110.             .cdc_union_descriptor =
  111.             {
  112.                 .bFunctionLength         = sizeof(struct usb_cdc_union_desc),
  113.                 .bDescriptorType         = USB_DTYPE_CS_INTERFACE,
  114.                 .bDescriptorSubType      = USB_DTYPE_CDC_UNION,
  115.                 .bMasterInterface0       = 1,
  116.                 .bSlaveInterface0        = 2,
  117.             },
  118.                 .cdc_ep_ctrl_descriptor =
  119.                 {
  120.                         .bLength             = sizeof(struct usb_endpoint_descriptor),
  121.                         .bDescriptorType     = USB_DTYPE_ENDPOINT,
  122.                         .bEndpointAddress    = USB_CDC_CTRL_EP,
  123.                         .bmAttributes        = USB_EPTYPE_INTERRUPT,
  124.                         .wMaxPacketSize      = USB_PKT_SIZE,
  125.                         .bInterval           = 1
  126.                 },
  127.                 .cdc_data_interface_descriptor =
  128.                 {
  129.                             .bLength             = sizeof(struct usb_interface_descriptor),
  130.                             .bDescriptorType     = USB_DTYPE_INTERFACE,
  131.                             .bInterfaceNumber    = 2,
  132.                             .bAlternateSetting   = 0,
  133.                             .bNumEndpoints       = 2,
  134.                             .bInterfaceClass     = USB_CLASS_CDC_DATA,
  135.                             .bInterfaceSubClass  = USB_SUBCLASS_NONE,
  136.                             .bInterfaceProtocol  = USB_PROTO_NONE,
  137.                             .iInterface          = 4
  138.                 },
  139.                 .cdc_ep_data_rx_descriptor =
  140.                 {
  141.                         .bLength             = sizeof(struct usb_endpoint_descriptor),
  142.                         .bDescriptorType     = USB_DTYPE_ENDPOINT,
  143.                         .bEndpointAddress    = USB_CDC_DATA_OUT_EP,
  144.                         .bmAttributes        = USB_EPTYPE_BULK,
  145.                         .wMaxPacketSize      = USB_PKT_SIZE,
  146.                         .bInterval           = 1
  147.                 },
  148.                 .cdc_ep_data_tx_descriptor =
  149.                 {
  150.                         .bLength             = sizeof(struct usb_endpoint_descriptor),
  151.                         .bDescriptorType     = USB_DTYPE_ENDPOINT,
  152.                         .bEndpointAddress    = USB_CDC_DATA_IN_EP,
  153.                         .bmAttributes        = USB_EPTYPE_BULK,
  154.                         .wMaxPacketSize      = USB_PKT_SIZE,
  155.                         .bInterval           = 1
  156.                 },
  157. };
这个设备描述符通过 IAD 的方式复合了一个 HID 和一个 CDC 串口设备。CDC 本身因为使用了两个 Interface 因此需要 IAD,如果是譬如 HID 这种只需要一个 Interface 的通信协议的话可以不用 IAD。(这个设备其实我计划了 CDC+HID+MSC 的三路复合设备,就是希望 STM32F042K6 能放得下这点代码。)
sipodev 发表于 2022-10-17 19:55 | 显示全部楼层
有做出来了吗?
sipodev 发表于 2022-10-17 19:56 | 显示全部楼层
就算你配置好了HUB, 一个普通的USB设备不可能处理多个USB地址的数据,怎么处理多个地址的问题呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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