USB音频设备到主机的音量控制



我目前正在使用stm32微控制器开发USB耳机。我使用X-CUBE-USB-AUDIO包中的示例代码将音频流式传输到PC。一切似乎都很好。现在我想修改代码,允许USB设备通知主机音量/静音的变化。根据USB音频规范1.0 p.30,可选的状态中断端点可用于此目的。所以我修改了设备描述符,以包含那个可选的端点。这是原始描述符:

Information for device STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730):
Connection Information:
------------------------------
Device current bus speed: FullSpeed
Device supports USB 1.1 specification
Device supports USB 2.0 specification
Device address: 0x004B
Current configuration value: 0x01
Number of open pipes: 0
Device Descriptor:
------------------------------
0x12    bLength
0x01    bDescriptorType
0x0200  bcdUSB
0x00    bDeviceClass      
0x00    bDeviceSubClass   
0x00    bDeviceProtocol   
0x40    bMaxPacketSize0   (64 bytes)
0x0483  idVendor
0x5730  idProduct
0x0200  bcdDevice
0x01    iManufacturer   "STMicroelectronics"
0x02    iProduct        "STM32 AUDIO Streaming in FS Mode"
0x03    iSerialNumber   "368932633438"
0x01    bNumConfigurations
Configuration Descriptor:
------------------------------
0x09    bLength
0x02    bDescriptorType
0x00CB  wTotalLength   (203 bytes)
0x03    bNumInterfaces
0x01    bConfigurationValue
0x00    iConfiguration
0xC0    bmAttributes   (Self-powered Device)
0x32    bMaxPower      (100 mA)
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x00    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x01    bInterfaceSubClass   (Audio Control Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
AC Interface Header Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x0100  bcdADC
0x0048  wTotalLength   (72 bytes)
0x02    bInCollection
0x01    baInterfaceNr(1)
0x02    baInterfaceNr(2)
AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x12    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x06    bDescriptorSubtype
0x16    bUnitID
0x12    bSourceID
0x01    bControlSize
bmaControls: 
0x03   Channel(0) - Mute / Volume
0x00   Channel(1)
0x00   Channel(2)
0x00    iFeature

AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x14    bTerminalID
0x0301  wTerminalType   (Speaker)
0x00    bAssocTerminal
0x16    bSourceID
0x00    iTerminal
AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x11    bTerminalID
0x0201  wTerminalType   (Microphone)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x06    bDescriptorSubtype
0x15    bUnitID
0x11    bSourceID
0x01    bControlSize
bmaControls: 
0x03   Channel(0) - Mute / Volume
0x00   Channel(1)
0x00   Channel(2)
0x00    iFeature

AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x13    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x15    bSourceID
0x00    iTerminal
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x01    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x01    bInterfaceNumber
0x01    bAlternateSetting
0x02    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x12    bTerminalLink
0x01    bDelay
0x0001  wFormatTag   (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x02    bNrChannels   (2 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00BB80    tSamFreq(1)   (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x01    bEndpointAddress  (OUT endpoint 1)
0x05    bmAttributes      (Transfer: Isochronous / Synch: Asynchronous / Usage: Data)
0x00C4  wMaxPacketSize    (1 x 196 bytes)
0x01    bInterval         (1 frames)
0x00    bRefresh
0x81    bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x81    bEndpointAddress  (IN endpoint 1)
0x01    bmAttributes      (Transfer: Isochronous / Synch: None / Usage: Data)
0x0003  wMaxPacketSize    (1 x 3 bytes)
0x01    bInterval         (1 frames)
0x07    bRefresh
0x00    bSynchAddress
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x01    bAlternateSetting
0x01    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x13    bTerminalLink
0x01    bDelay
0x0001  wFormatTag   (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x02    bNrChannels   (2 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00BB80    tSamFreq(1)   (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x82    bEndpointAddress  (IN endpoint 2)
0x01    bmAttributes      (Transfer: Isochronous / Synch: None / Usage: Data)
0x00C0  wMaxPacketSize    (1 x 192 bytes)
0x01    bInterval         (1 frames)
0x00    bRefresh
0x00    bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay
Microsoft OS Descriptor is not available. Error code: 0x0000001F
String Descriptor Table
--------------------------------
Index  LANGID  String
0x00   0x0000  0x0409 
0x01   0x0409  "STMicroelectronics"
0x02   0x0409  "STM32 AUDIO Streaming in FS Mode"
0x03   0x0409  "368932633438"
------------------------------
Connection path for device: 
USB xHCI Compliant Host Controller
Root Hub
STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730) Port: 5
Running on: Windows 10 or greater (Build Version 19043)
Brought to you by TDD v2.15.0, Jun  8 2020, 17:18:07

这是修改后的描述符:

Information for device STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730):
Connection Information:
------------------------------
Device current bus speed: FullSpeed
Device supports USB 1.1 specification
Device supports USB 2.0 specification
Device address: 0x001B
Current configuration value: 0x01
Number of open pipes: 1
Device Descriptor:
------------------------------
0x12    bLength
0x01    bDescriptorType
0x0200  bcdUSB
0x00    bDeviceClass      
0x00    bDeviceSubClass   
0x00    bDeviceProtocol   
0x40    bMaxPacketSize0   (64 bytes)
0x0483  idVendor
0x5730  idProduct
0x0200  bcdDevice
0x01    iManufacturer   "STMicroelectronics"
0x02    iProduct        "STM32 AUDIO Streaming in FS Mode"
0x03    iSerialNumber   "368932633438"
0x01    bNumConfigurations
Configuration Descriptor:
------------------------------
0x09    bLength
0x02    bDescriptorType
0x00D4  wTotalLength   (212 bytes)
0x03    bNumInterfaces
0x01    bConfigurationValue
0x00    iConfiguration
0xC0    bmAttributes   (Self-powered Device)
0x32    bMaxPower      (100 mA)
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x00    bInterfaceNumber
0x00    bAlternateSetting
0x01    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x01    bInterfaceSubClass   (Audio Control Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
AC Interface Header Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x0100  bcdADC
0x0048  wTotalLength   (72 bytes)
0x02    bInCollection
0x01    baInterfaceNr(1)
0x02    baInterfaceNr(2)
AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x12    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x06    bDescriptorSubtype
0x16    bUnitID
0x12    bSourceID
0x01    bControlSize
bmaControls: 
0x03   Channel(0) - Mute / Volume
0x00   Channel(1)
0x00   Channel(2)
0x00    iFeature

AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x14    bTerminalID
0x0301  wTerminalType   (Speaker)
0x00    bAssocTerminal
0x16    bSourceID
0x00    iTerminal
AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x11    bTerminalID
0x0201  wTerminalType   (Microphone)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal
AC Feature Unit Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x06    bDescriptorSubtype
0x15    bUnitID
0x11    bSourceID
0x01    bControlSize
bmaControls: 
0x03   Channel(0) - Mute / Volume
0x00   Channel(1)
0x00   Channel(2)
0x00    iFeature

AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x13    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x15    bSourceID
0x00    iTerminal
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x83    bEndpointAddress  (IN endpoint 3)
0x03    bmAttributes      (Transfer: Interrupt / Synch: None / Usage: Data)
0x0002  wMaxPacketSize    (1 x 2 bytes)
0x0A    bInterval         (10 frames)
0x00    bRefresh
0x00    bSynchAddress
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x01    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x01    bInterfaceNumber
0x01    bAlternateSetting
0x02    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x12    bTerminalLink
0x01    bDelay
0x0001  wFormatTag   (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x02    bNrChannels   (2 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00BB80    tSamFreq(1)   (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x01    bEndpointAddress  (OUT endpoint 1)
0x05    bmAttributes      (Transfer: Isochronous / Synch: Asynchronous / Usage: Data)
0x00C4  wMaxPacketSize    (1 x 196 bytes)
0x01    bInterval         (1 frames)
0x00    bRefresh
0x81    bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x81    bEndpointAddress  (IN endpoint 1)
0x01    bmAttributes      (Transfer: Isochronous / Synch: None / Usage: Data)
0x0003  wMaxPacketSize    (1 x 3 bytes)
0x01    bInterval         (1 frames)
0x07    bRefresh
0x00    bSynchAddress
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x01    bAlternateSetting
0x01    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface
AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x13    bTerminalLink
0x01    bDelay
0x0001  wFormatTag   (PCM)
AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x02    bNrChannels   (2 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00BB80    tSamFreq(1)   (48000 Hz)
Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x82    bEndpointAddress  (IN endpoint 2)
0x01    bmAttributes      (Transfer: Isochronous / Synch: None / Usage: Data)
0x00C0  wMaxPacketSize    (1 x 192 bytes)
0x01    bInterval         (1 frames)
0x00    bRefresh
0x00    bSynchAddress
AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay
Microsoft OS Descriptor is not available. Error code: 0x0000001F
String Descriptor Table
--------------------------------
Index  LANGID  String
0x00   0x0000  0x0409 
0x01   0x0409  "STMicroelectronics"
0x02   0x0409  "STM32 AUDIO Streaming in FS Mode"
0x03   0x0409  "368932633438"
------------------------------
Connection path for device: 
USB xHCI Compliant Host Controller
Root Hub
STM32 AUDIO Streaming in FS Mode (VID=0x0483 PID=0x5730) Port: 5
Running on: Windows 10 or greater (Build Version 19043)
Brought to you by TDD v2.15.0, Jun  8 2020, 17:18:07

我所做的改变是:

  1. 添加AC中断端点描述符
  2. 更改配置描述符中的wTotalLength
  3. 将AC接口描述符中的bNumEndPoints从0更改为1

USB设备似乎枚举良好,并且有音频,但当查看Beagle USB逻辑分析器的输出时,我没有看到主机从中断端点请求任何数据。所以我的问题是,我修改描述符的方式有问题吗?还是其他原因?是否有人设法使USB音频设备的状态中断端点正常工作?

运行于:Windows 10或更高版本(内部版本19043(

根据我的经验,Windows无法处理此中断。在Linux或MacOS上尝试一下。

最新更新