Skip to main content
Visitor II
January 22, 2024
Question

STM32L55 USB microphone 4 channels using external I2S

  • January 22, 2024
  • 1 reply
  • 1574 views

Hi,

I have an external ADC connected to my STM32L55 using the I2S interface. The ADC is sampling 4-channel 16-bit data at 48000Hz sampling rate. However, I have encountered issues while streaming a large amount of data using USB CDC. Therefore, I am considering using the Audio device class to solve this problem. By doing so, I hope to make the PC recognize the 4 channels as 4 microphones and receive all the data without losing a single sample. I've configured my ADC as a master to ensure that there is always data for the STM32 to receive. 

 

To begin with, I plan to modify the USB descriptor so that the PC can recognize the STM32 as a microphone. My question is whether I need to make more changes than just altering the descriptor. Do I need to properly fill in these functions?

USBD_AUDIO_ItfTypeDef USBD_AUDIO_fops_FS =

{

AUDIO_Init_FS,

AUDIO_DeInit_FS,

AUDIO_AudioCmd_FS,

AUDIO_VolumeCtl_FS,

AUDIO_MuteCtl_FS,

AUDIO_PeriodicTC_FS,

AUDIO_GetState_FS,

};

 

    This topic has been closed for replies.

    1 reply

    Graduate II
    January 22, 2024

    I have never used USB audio class, but I would check a) where and when these might be called , and b) what the return values of these functions are, or what's done with pointers given to these functions.

    Are there any example / __weak functions or prototypes?

    DhanarajAuthor
    Visitor II
    January 26, 2024

    After modifying the USB descriptor, my STM was neither detected as a speaker nor a Mic. I captured the USB description on the Windows side; the data is below. I am referring to this page for my changes (https://hackaday.io/project/181868-stm32f4-usb-microphone/details).

    I think the windows error is due to an unsuccessful query by the OS. But not sure what OS wants that I need to implement in STM. I never got the data IN request from the OS. Can anyone point me what I am missing here.

    USBD_AUDIO_DataIn

    Information for device USB\Vendor_0483_Product_5740:

    ------------------------------
    Connection Information:
    ------------------------------
    Device current bus speed: FullSpeed
    Device supports USB 1.1 specification
    Device supports USB 2.0 specification
    Device address: 0x0003
    Current configuration value: 0x01
    Number of open pipes: 0


    ------------------------------
    Device Descriptor:
    ------------------------------
    0x12 bLength
    0x01 bDescriptorType
    0x0201 bcdUSB
    0x00 bDeviceClass
    0x00 bDeviceSubClass
    0x00 bDeviceProtocol
    0x40 bMaxPacketSize0 (64 bytes)
    0x0483 idVendor
    0x5740 idProduct
    0x0200 bcdDevice
    0x01 iManufacturer
    0x02 iProduct
    0x03 iSerialNumber
    0x01 bNumConfigurations


    -------------------------
    Configuration Descriptor:
    -------------------------
    0x09 bLength
    0x02 bDescriptorType
    0x0064 wTotalLength (100 bytes)
    0x02 bNumInterfaces
    0x01 bConfigurationValue
    0x00 iConfiguration
    0x80 bmAttributes (Bus-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:
    ------------------------------
    0x09 bLength
    0x24 bDescriptorType
    0x01 bDescriptorSubtype
    0x0100 bcdADC
    0x001E wTotalLength (30 bytes)
    0x01 bInCollection
    0x01 baInterfaceNr(1)

    AC Input Terminal Descriptor:
    ------------------------------
    0x0C bLength
    0x24 bDescriptorType
    0x02 bDescriptorSubtype
    0x01 bTerminalID
    0x0201 wTerminalType (Microphone)
    0x00 bAssocTerminal
    0x01 bNrChannels (1 channels)
    0x0000 wChannelConfig
    0x00 iChannelNames
    0x00 iTerminal

    AC Output Terminal Descriptor:
    ------------------------------
    0x09 bLength
    0x24 bDescriptorType
    0x03 bDescriptorSubtype
    0x03 bTerminalID
    0x0101 wTerminalType (USB Streaming)
    0x00 bAssocTerminal
    0x02 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
    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
    0x03 bTerminalLink
    0x01 bDelay
    0x0001 wFormatTag (PCM)

    AS Format Type 1 Descriptor:
    ------------------------------
    0x0B bLength
    0x24 bDescriptorType
    0x02 bDescriptorSubtype
    0x01 bFormatType (FORMAT_TYPE_1)
    0x01 bNrChannels (1 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
    0x81 bEndpointAddress (IN endpoint 1)
    0x05 bmAttributes (Transfer: Isochronous / Synch: Asynchronous / Usage: Data)
    0x0060 wMaxPacketSize (1 x 96 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

    ------------------------------

    Connection path for device:
    USB xHCI Compliant Host Controller
    Root Hub
    Generic USB Hub
    USB\Vendor_0483_Product_5740 Port: 4

    Running on: Windows 10 or greater (Build Version 22621)

    Brought to you by TDD v2.17.0, Feb 23 2021, 14:04:02