I'm learning about USB classes using STM32F429ZI(on Discovery board). I already tried to implement Communications device class (CDC) and it worked well, now I tried to do some simple test with Audio Device Class.
I am using CubeMX to generate project, chose Audio Device Class there, it created default library files. uVision complied without errors or warnings. I flashed my MCU and in device manager it looks like this: enter image description here

After my learning about CDC USB, I knew that I need to increase Stack_Size and Heap_Size in startup file. I tried it - nothing changes. I also found some advice to decrease HS_MAX_PACKET_SIZE - still no effect.

Well, the questions are:

  1. Why is it under COM port? Even if some configurations are not correct, shouldn't it be under sound devices?
  2. What is wrong? How to make it work? It would be good just to make it recognized as audio device at least, nothing special.

The error under the device is just generic "This device cannot start" error.

enter image description here

Actually, I don't know what kind of code to attach, since everything is generated with CubeMX. I can give any snippets on request, if needed.
USB Device description generated by CubeMX.

#define USBD_VID     1155
#define USBD_LANGID_STRING     1033
#define USBD_MANUFACTURER_STRING     "STMicroelectronics"
#define USBD_PID_HS     22336
#define USBD_PRODUCT_STRING_HS     "STM32 Audio Class"
#define USBD_SERIALNUMBER_STRING_HS     "00000000001A"
#define USBD_INTERFACE_STRING_HS     "AUDIO Interface"

#define USB_SIZ_BOS_DESC            0x0C

I found that USBD_AUDIO_Init() is not called anywhere by default and this can be the problem. But I have troubles understanding how can I call it when it is "Static uint8_t", so basically not callable from main. Here is the description:


  * @brief  USBD_AUDIO_Init
  *         Initialize the AUDIO interface
  * @param  pdev: device instance
  * @param  cfgidx: Configuration index
  * @retval status
static uint8_t  USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, 
                               uint8_t cfgidx)
  bunch of code

Have you tried this function?

USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id)

The documentation for this library is located here, but it's not great. In general, the HAL gives you some functions and if you use them correctly, a lot of other things happen behind the scenes. Your USBD_AUDIO_Init may be one of those things.

  • \$\begingroup\$ USBD_Init() is called by default inside MX_USB_DEVICE_Init() in code generated by CubeMX. And I checked - it uses correct values in DescriptorsTypeDef, so the basic initialization seems fine. I have read the pdf you are referring, unfortunately they only mention this USBD_AUDIO_Init, which I have no idea how to call, since it is static uint8_t. \$\endgroup\$ – ScienceSamovar Nov 28 '15 at 7:38
  • \$\begingroup\$ If you dig further, you will probably find that it is called internally by one of the other init funcitons. \$\endgroup\$ – Daniel Nov 28 '15 at 23:28

Check USBD_malloc() in the USBD_AUDIO_Init() allocates requested memory. USBD_AUDIO_HandleTypeDef contains:

AUDIO_OUT_PACKET = (22100 * 2 * 2)/1000

So total memory allocation size is about 7100 bytes. I set heap size in CubeMx project 10KB (2800h). After that windows (I use win10) recognizes stm32f4 as audio device.


In device manager, right click on virtual COM port device and uninstall device. Check delete the driver software for this device. Reset the device. Now Windows should install driver for usb audio device class.


You shall change the PID of the new device. Or your audio device will have the same PID as the previous CDC device. The system will recognize those two devices as the same then.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.