打印

基于USB AUDIO2.0写得描述符,不能正常枚举,求大佬帮忙看下

[复制链接]
3000|38
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xuqingli123|  楼主 | 2019-4-16 08:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
IO, USB, TE, des, ip
本帖最后由 xuqingli123 于 2019-11-12 13:10 编辑

static uint8_t usbd_audio_CfgDesc[AUDIO_CONFIG_DESC_SIZE] =
{
  0x09,                                 /* bLength */
  0x02,                                 /* bDescriptorType */
  LOBYTE(AUDIO_CONFIG_DESC_SIZE),       /* wTotalLength */
  HIBYTE(AUDIO_CONFIG_DESC_SIZE),      
  0x03,                                 /* bNumInterfaces */
  0x01,                                 /* bConfigurationValue */
  0x00,                                 /* iConfiguration */
  0xC0,                                 /* bmAttributes BUS Powered*/
  0x32,                                 /* bMaxPower = 100 mA*/
  /* 09 byte*/

        /* Standard Interface Association Descriptor */
  0x08,
  0x0B,
  0x00,
  0x03,
  0x01,
  0x00,
  0x20,
  0x00,
  /* 08 byte */

  /* Standard AC Interface Descriptor */
  9,                                    /* bLength */
  0x04,                                 /* bDescriptorType */
  0x00,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x01,                                 /* bInterfaceSubClass */
  0x20,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* Class-specific AC Interface Descriptor */
  9,                                    /* bLength */
  0x24,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptorSubtype */
  0x00,                                 /* bcdADC */
  0x02,                                 /* 2.00 */
  0x0b,                                 /* bCategory */
  0x6F,                                 /* wTotalLength */
  0x00,
  0x00,                                 /* bmControls */
  /* 09 byte*/


  /* USB Speaker Clock Source Descriptor */
  0x08,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x0A,                                 /* bDescriptorSubtype */
  0x04,                                 /* bClockID */
  0x03,                                 /* bmAttributes */
  0x07,                                 /* bmControls TODO */
  0x00,                                 /* bAssocTerminal */
  0x00,                                 /* iClockSource */
  /* 08 byte*/
       

  /* USB Speaker Input Terminal Descriptor */
  0x11,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x01,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType AUDIO_TERMINAL_USB_STREAMING   0x0101 */
  0x01,
  0x00,                                 /* bAssocTerminal */
  0x04,                                 /* bCSourceID*/
  0x02,                                 /* bNrChannels */
  0x03,                                 /* wChannelConfig 0x00000003  Stereo */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iChannelNames */
  0x00,                                 /* bmControls */
  0x00,
  0x00,                                 /* iTerminal */
  /* 17 byte*/

  /* USB Speaker Audio Feature Unit Descriptor */
  0x12,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x06,                                 /* bDescriptorSubtype */
  0x02,                                 /* bUnitID */
  0x01,                                 /* bSourceID */
  AUDIO_20_CTL_MUTE(CONTROL_BITMAP_PROG)/* bmaControls(0) */
  | AUDIO_20_CTL_VOLUME(CONTROL_BITMAP_PROG),
  0x00,
  0x00,
  0x00,
  0x00,                                 /* bmaControls(1) */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* bmaControls(2) */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iFeature */
  /* 18 byte*/

  /*USB Speaker Output Terminal Descriptor */
  0x0C,                                                   /* bLength */
  0x24,                                 /* bDescriptorType */
  0x03,                                 /* bDescriptorSubtype */
  0x03,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType  0x0301: Speaker, 0x0302: Headphone*/
  0x03,
  0x00,                                 /* bAssocTerminal */
  0x01,                                 /* bSourceID */
  0x04,                                 /* bCSourceID */
  0x00,                                 /* bmControls */
  0x00,
  0x00,                                 /* iTerminal */
  /* 12 byte*/

        /* USB Microphone Input Terminal Descriptor */
  0x11,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x05,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType AUDIO_TERMINAL_USB_STREAMING   0x0201 */
  0x02,
  0x00,                                 /* bAssocTerminal */
  0x04,                                 /* bCSourceID*/
  0x02,                                 /* bNrChannels */
  0x03,                                 /* wChannelConfig 0x00000003  Stereo */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iChannelNames */
  0x00,                                 /* bmControls */
  0x00,
  0x00,                                 /* iTerminal */
  /* 17 byte*/

  /* USB Microphone Audio Feature Unit Descriptor */
  0x12,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x06,                                 /* bDescriptorSubtype */
  0x06,                                 /* bUnitID */
  0x05,                                 /* bSourceID */
  AUDIO_20_CTL_MUTE(CONTROL_BITMAP_PROG)/* bmaControls(0) */
  | AUDIO_20_CTL_VOLUME(CONTROL_BITMAP_PROG),
  0x00,
  0x00,
  0x00,
  0x00,                                 /* bmaControls(1) */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* bmaControls(2) */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iFeature */
  /* 18 byte*/

  /*USB Microphone Output Terminal Descriptor */
  0x0C,                                                    /* bLength */
  0x24,                                 /* bDescriptorType */
  0x03,                                 /* bDescriptorSubtype */
  0x07,                                 /* bTerminalID */
  0x01,                                 /* wTerminalType  0x0101*/
  0x01,
  0x00,                                 /* bAssocTerminal */
  0x05,                                 /* bSourceID */
  0x04,                                 /* bCSourceID */
  0x00,                                 /* bmControls */
  0x00,
  0x00,                                 /* iTerminal */
  /* 12 byte*/
       
  /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwidth */
  /* Interface 1, Alternate Setting 0                                              */
  9,                                                      /* bLength */
  0x04,                                 /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x00,                                 /* bAlternateSetting */
  0x00,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x02,                                 /* bInterfaceSubClass */
  0x20,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* USB Speaker Standard AS Interface Descriptor - Audio Streaming Operational */
  /* Interface 1, Alternate Setting 1                                           */
  9,                                                      /* bLength */
  0x04,                                 /* bDescriptorType */
  0x01,                                 /* bInterfaceNumber */
  0x01,                                 /* bAlternateSetting */
  0x01,                                 /* bNumEndpoints */
  0x01,                                 /* bInterfaceClass */
  0x02,                                 /* bInterfaceSubClass */
  0x20,                                 /* bInterfaceProtocol */
  0x00,                                 /* iInterface */
  /* 09 byte*/

  /* USB HeadSet Audio Streaming Interface Descriptor */
  0x10,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptorSubtype */
  0x01,                                 /* 0x01: bTerminalLink */
  0x00,                                 /* bmControls */
  0x01,                                 /* bFormatType */
  0x01,                                 /* bmFormats PCM */
  0x00,
  0x00,
  0x00,
  0x02,                                 /* bNrChannels */
  0x03,                                 /* bmChannelConfig */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iChannelNames */
  /* 16 byte*/

  /* USB Speaker Audio Type I Format Interface Descriptor */
  0x06,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x01,                                 /* bFormatType */
  3,                                    /* bSubslotSize */
  24,                                   /* bBitResolution */
  /* 6 byte*/

  /* Endpoint 1 - Standard Descriptor */
  0x07,                                 /* bLength */
  0x05,                                 /* bDescriptorType */
  0x03,                                 /* bEndpointAddress 3 out endpoint for Audio */
  0x0d,                                 /* bmAttributes */
  AUDIO_PACKET_SZE(384000),    /* XXXX wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
  0x01,                                 /* bInterval */
  /* 07 byte*/

  /* Endpoint - Audio Streaming Descriptor*/
  0x08,                                 /* bLength */
  0x25,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptor */
  0x00,                                 /* bmAttributes */
  0x00,                                 /* bmControls */
  0x00,                                 /* bLockDelayUnits */
  0x00,                                 /* wLockDelay */
  0x00,
  /* 08 byte*/
       
        /* USB Microphone Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */
  /* Interface 2, Alternate Setting 0                                             */
        0x09,                                 /* bLength */
        0x04,                                 /* bDescriptorType */
        0x02,                                 /* bInterfaceNumber */
        0x00,                                 /* bAlternateSetting */
        0x00,                                 /* bNumEndpoints */
        0x01,                                 /* bInterfaceClass */
        0x02,                                 /* bInterfaceSubClass */
        0x20,                                 /* bInterfaceProtocol */
        0x00,                                 /* iInterface */
        /* 09 byte*/

  /* USB Microphone Standard AS Interface Descriptor - Audio Streaming Operational */
  /* Interface 2, Alternate Setting 1                                           */
        0x09,                                  /* bLength */
        0x04,                                  /* bDescriptorType */
        0x02,                                  /* bInterfaceNumber */
        0x01,                                  /* bAlternateSetting */
        0x01,                                  /* bNumEndpoints */
        0x01,                                  /* bInterfaceClass */
        0x02,                                  /* bInterfaceSubClass */
        0x20,                                  /* bInterfaceProtocol */
        0x00,                                  /* iInterface */
        /* 09 byte*/
       
        /* USB Microphone Audio Streaming Interface Descriptor */
  0x10,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptorSubtype */
  0x07,                                 /* 0x07: bTerminalLink */
  0x00,                                 /* bmControls */
  0x01,                                 /* bFormatType */
  0x01,                                 /* bmFormats PCM */
  0x00,
  0x00,
  0x00,
  0x02,                                 /* bNrChannels */
  0x03,                                 /* bmChannelConfig */
  0x00,
  0x00,
  0x00,
  0x00,                                 /* iChannelNames */
  /* 16 byte*/
       
        /* USB Microphone Audio Type I Format Interface Descriptor */
  0x06,                                 /* bLength */
  0x24,                                 /* bDescriptorType */
  0x02,                                 /* bDescriptorSubtype */
  0x01,                                 /* bFormatType */
  3,                                    /* bSubslotSize */
  24,                                   /* bBitResolution */
  /* 6 byte*/
       
        /* Endpoint 1 - Standard Descriptor */
  0x07,                                 /* bLength */
  0x05,                                 /* bDescriptorType */
  0x81,                                 /* bEndpointAddress 3 out endpoint for Audio */
  0x0d,                                 /* bmAttributes */
  AUDIO_PACKET_SZE(384000),             /* XXXX wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
  0x01,                                 /* bInterval */
  /* 07 byte*/

  /* Endpoint - Audio Streaming Descriptor*/
  0x08,                                 /* bLength */
  0x25,                                 /* bDescriptorType */
  0x01,                                 /* bDescriptor */
  0x00,                                 /* bmAttributes */
  0x00,                                 /* bmControls */
  0x00,                                 /* bLockDelayUnits */
  0x00,                                 /* wLockDelay */
  0x00,
  /* 08 byte*/
} ;

/**
  * @}
  */
不知道描述符对不对,刚接触USB AUDIO2.0,大佬们帮忙看下。

使用特权

评论回复

相关帖子

沙发
xuqingli123|  楼主 | 2019-4-18 09:28 | 只看该作者
自己顶一下

使用特权

评论回复
板凳
xuqingli123|  楼主 | 2019-4-18 09:30 | 只看该作者
描述符是枚举扬声器和麦克风的,但是不能正常枚举出来,专门枚举扬声器的是可以枚举出来的,不知道改过之后是不是哪地方写错了还是少些什么了?

使用特权

评论回复
地板
xuqingli123|  楼主 | 2019-4-18 09:53 | 只看该作者
@jinxuan97 大佬帮忙看下

使用特权

评论回复
5
xuqingli123|  楼主 | 2019-4-18 10:49 | 只看该作者
现在把描述符分开枚举,扬声器和麦克风都是可以出来的,但是想把他们综合起来,就不能正常枚举,有个疑惑,是不是时钟描述符要写两个,就是扬声器一个时钟描述符,麦克风一个时钟描述符?还是有其他的问题?

使用特权

评论回复
6
jinxuan97| | 2019-4-18 11:31 | 只看该作者

使用特权

评论回复
7
jinxuan97| | 2019-4-18 11:32 | 只看该作者
Table A-7: Audio Function Category Codes
HEADSET          0x04
AUDIO/VIDEO   0x0B

使用特权

评论回复
8
xuqingli123|  楼主 | 2019-4-18 12:59 | 只看该作者
本帖最后由 xuqingli123 于 2019-4-18 13:12 编辑
jinxuan97 发表于 2019-4-18 11:32
Table A-7: Audio Function Category Codes
HEADSET          0x04
AUDIO/VIDEO   0x0B

这个不是应该配置0X0B吗?audio,改成0X04还是不对, 耳机是0X04,我现在想要枚举出来扬声器和麦克风都有的,所以这个配置的是0X0B。

使用特权

评论回复
9
xuqingli123|  楼主 | 2019-4-18 13:06 | 只看该作者
不好意思,这个比较冷门,很少能找到这方面的资料,在论坛里面就看到过你比较熟悉这方面,所以每次都@你,不好意思,@jinxuan97

使用特权

评论回复
10
jinxuan97| | 2019-4-18 14:46 | 只看该作者
xuqingli123 发表于 2019-4-18 13:06
不好意思,这个比较冷门,很少能找到这方面的资料,在论坛里面就看到过你比较熟悉这方面,所以每次都@你, ...

没问题啊!

使用特权

评论回复
11
jinxuan97| | 2019-4-18 14:47 | 只看该作者
你的Device Descriptor是怎样的?

--------------------------------------------------------------------------------
Device Descriptor:
--------------------------------------------------------------------------------
BYTE  bLength             0x12
BYTE  bDescriptorType     0x01
WORD  bcdUSB              0x0200
BYTE  bDeviceClass        0xEF
BYTE  bDeviceSubClass     0x02
BYTE  bDeviceProtocol     0x01
BYTE  bMaxPacketSize0     0x40
WORD  idVendor            0x045E
WORD  idProduct           0xFFFF
WORD  bcdDevice           0x0100
BYTE  iManufacturer       0x01
WORD  iProduct            0x02
WORD  iSerialNumber       0x03
BYTE  bNumConfigurations  0x01

使用特权

评论回复
12
xuqingli123|  楼主 | 2019-4-18 15:14 | 只看该作者
jinxuan97 发表于 2019-4-18 14:47
你的Device Descriptor是怎样的?

-------------------------------------------------------------------- ...

__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
  {
    0x12,                       /*bLength */
    0x01,                       /*bDescriptorType*/
    0x00,                       /*bcdUSB */
    0x02,
    0x00,                       /*bDeviceClass*/
    0x00,                       /*bDeviceSubClass*/
    0x00,                       /*bDeviceProtocol*/
    64,                         /*bMaxPacketSize*/
    LOBYTE(USBD_VID),           /*idVendor*/
    HIBYTE(USBD_VID),           /*idVendor*/
    LOBYTE(USBD_PID),           /*idVendor*/
    HIBYTE(USBD_PID),           /*idVendor*/
    0x00,                       /*bcdDevice rel. 2.00*/
    0x02,
    0x01,                       /*Index of manufacturer  string*/
    0x02,                       /*Index of product string*/
    0x03,                       /*Index of serial number string*/
    1                           /*bNumConfigurations*/
  } ; /* USB_DeviceDescriptor */

使用特权

评论回复
13
xuqingli123|  楼主 | 2019-4-18 15:16 | 只看该作者
本帖最后由 xuqingli123 于 2019-4-18 15:20 编辑
jinxuan97 发表于 2019-4-18 14:47
你的Device Descriptor是怎样的?

-------------------------------------------------------------------- ...

改成你上面这样的了  还是不行,是不是从扬声器改成扬声器和麦克风都有的,代码里面请求也需要修改一下吗?

使用特权

评论回复
14
eydj2008| | 2019-4-19 08:02 | 只看该作者
直接用CUBEMX的例子就可以 注意堆的分配

使用特权

评论回复
15
xuqingli123|  楼主 | 2019-4-19 08:31 | 只看该作者
eydj2008 发表于 2019-4-19 08:02
直接用CUBEMX的例子就可以 注意堆的分配

CUBXMX有USB AUDIO2.0吗?我以前配过,官方带的都是USB AUDIO1.0的。

使用特权

评论回复
16
xuqingli123|  楼主 | 2019-4-19 08:32 | 只看该作者
eydj2008 发表于 2019-4-19 08:02
直接用CUBEMX的例子就可以 注意堆的分配

如果能直接用CUBEMX配置,那就很方便了,但是找不到USB AUDIO2.0的库,

使用特权

评论回复
17
xuqingli123|  楼主 | 2019-4-19 09:46 | 只看该作者
自己顶一下,希望做过的大佬们,帮助一下

使用特权

评论回复
18
eydj2008| | 2019-4-19 13:52 | 只看该作者
xuqingli123 发表于 2019-4-19 08:32
如果能直接用CUBEMX配置,那就很方便了,但是找不到USB AUDIO2.0的库,

你说的是USB 2.0 吧 ,High Speed - 480 Mb/s   
芯片支持这么快的速度才行.

使用特权

评论回复
19
xuqingli123|  楼主 | 2019-4-19 16:14 | 只看该作者
本帖最后由 xuqingli123 于 2019-4-19 16:40 编辑
eydj2008 发表于 2019-4-19 13:52
你说的是USB 2.0 吧 ,High Speed - 480 Mb/s   
芯片支持这么快的速度才行.

不是,是USB AUDIO2.0,是USB音频协议,和USB2.0是不一样的。

使用特权

评论回复
20
eydj2008| | 2019-4-19 17:28 | 只看该作者
xuqingli123 发表于 2019-4-19 16:14
不是,是USB AUDIO2.0,是USB音频协议,和USB2.0是不一样的。

USB Audio Class 2 standard (2009)
USB Audio Class 2 additionally supports 32 bit and all common sample rates > 96 kHz
Class 2 uses High Speed (480 MHz). This requires USB 2 or 3.
As the data rate of High Speed is 40 X Full speed, recording a 60 channel using 24 bits at 96 kHz (132 Mbit/s) is not a problem.
Using High Speed USB for playback there are no limits in resolution.
It is downwards compatible with class 1.

From mid-2010 on USB audio class 2 drivers are available in OSX 10.6.4 and Linux.
Both support sample rates up to 384 kHz.
Companies like Thesycon or Centrance have developed a USB Class 2 Audio driver for Windows.
This was necessary because Microsoft simply didn’t support UAC2.
In April 2017, an update of Win10 finally brought native mode drivers.
If you use older versions of Win, you still need a third party driver.

使用特权

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

本版积分规则

29

主题

174

帖子

2

粉丝