cancel
Showing results for 
Search instead for 
Did you mean: 

Port X-CUBE-USB-AUDIO whithout nodes and recording sessions to create a USB audio microphone

Gabriel Melo
Associate III

Hi ST Geniuses

So, for quite a while I have been trying to create an USB audio mic. Problem is: it is quite hard and not always a complete solution.

And the X-CUBE-USB-AUDIO offers the complete solution, for audio and playback, even with feedback.

The problem is: it is so complicated to detach the USB solution from the nodes, and sessions thing (see here if you don't know what I am talking about USB device audio streaming Expansion Package for STM32Cube - User manual). And the middleware isn't the same generated by CubeMX, which makes it harder to port it to another microcontroller (in my case the STM32L4R9)

So, did anyone manage to do this? Or to approach this problem in another manner?

I also tried TinyUSB, which does not offer native support for the STM32L4 family nor it is fully tested for audio (isochronous).

Thanks for the help,

Gabriel.

8 REPLIES 8
Gabriel Melo
Associate III

It has been 2 years since this question : STM32F4 Cube-based USB Device Microphone in Audio Class streaming to Host PC was asked. I want to believe that someone has figured it out

it actually started 4 years ago!

I guess the conclusion must be that it's not a priority for ST.

Presumably, commercial products doing this sort of thing are using dedicated chips rather than general-purpose microcontrollers?

Definitely not a priority. There are IC's that do I2S <-> USB, just not available from ST. Weird from them...

And I'm stuck in a limbo where I have half my code working, a custom board that I made, and I don't wanna start over...

Piranha
Chief II

That topic actually it started not 2 or 4, but 6 years ago... Honestly ST doesn't care about STM32 software. USB, Ethernet, lwIP, FatFS - nothing works. Even USART and till not long ago pin toggling!

As for TinyUSB, L4(+) is supported:

https://github.com/hathach/tinyusb/blob/14083ad2df1252436d9f563fb5cf357052a7ec3c/src/portable/st/synopsys/dcd_synopsys.c#L41

Audio class seems to be a work in progress. But, comparing ST and TinyUSB software progress... Probably this year TinyUSB will have usable audio class, while ST's stack will always be buggy, bloated, using malloc() and doing everything in ISR. You can even help them develop that audio class. :)

Damn, 6 years...

I got it semi working with the package I asked about... but really it shouldn't take that much work

TinyUSB is really a work in progress... isochronous transfers aren't that well tested apparently; and as for L4+ I asked hathach personally by mail and I got an answer not too long after. And looking at the branches he is the only one working on audio. Hope it does not take too long but I needed something for now

For others who can pay, there is also HCC stack (official ST partner); maybe that is why they don't give that much attention to the official package

"Honestly ST doesn't care about STM32 software"

That's a bit of a leap!

Clearly, ST (or any other chip manufacturer) can't provide full, ready-made solutions for every single possible application - that's your job as a developer.

Actually that is what I mean - they should provide a few decent libraries and examples, not a junk in million minor variations. But unfortunately they are doing exactly the opposite. The main driver library (HAL) is a terribly buggy bloatware with a so limited API that it is completely useless. At the same time they are providing a trivial and broken examples in literally almost 100 (for UART) minor modifications across all series. It's a complete waste of resources. In reality a few decent examples for one or few functionally different MCUs would be actually educational and useful. They even have an employee, who already privately have shown how it should be done:

https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx

One actually useful example, proper explanation and a few MCUs! The result - it obliterates those 100 useless official examples of how not to develop software. And it doesn't use HAL exactly because it is broken and useless...

Gabriel Melo
Associate III

I'm also helping someone else with the same problem, posting here if anyone needs : Having problem setting up USB Audio(Microphone) for STM32H743

Okay, so, once you change the USB descriptors make sure you uninstall your device on windows, and then plug it in again... Windows does not recognize a USB device with the same VID and PID if it has changed the descriptors (the same is not true on Linux, for example).

I had more luck using the X-CUBE-USB-AUDIO package, altough it is not cube-compatible. My mic works much better (it is not 100% tough). What you need to do is:

  • Generate code with stm32cubeide for usb audio device
  • Replace files with those on the expansion package but keep those on the Core (Middlewares/ST/STM32_Device_Library/Core) and Target (USB_MIC/Target) folders. The usbd_conf files are device-specific (more on that here: STM32 USB training - 08 STM32 USB Device library - YouTube at around the 4 min mark)
  • Make sure you use the STM32F769I_DISCO_UAC10-DUM example, for a dummy microphone (easier to decouple from the software used for the MEMS mic)

And then, you configure as your application should run :

  • Have your audio samples transferred by DMA
  • Once you get the HalfTransferComplete and TransferComplete callbacks, call the AUDIO_Fill_Buffer function (you can take a hint by looking at the implementation on STM32F769I_DISCO_UAC10-REC (Application/User/audio_mic_node.c). Try to implement the important functions on audio_mic_node.c to your audio_dummymic_node.c that is in your project. I think you only have to modify this file and the usbd_user_cfg.h file

Tell me if you have any questions, and good luck ! If you can make it work 100% (or at least 90) please post your updates.

Regards