cancel
Showing results for 
Search instead for 
Did you mean: 

The STM32F103 HAL usb audio library is still broken? The CubeMX generated code is not working with the F103 or 303, but working with F411.

JVoro.2
Associate II
10 REPLIES 10
JVoro.2
Associate II

Some details: I tried to write a simple usb audio speaker with the STM32F103 Bluepill using STM32CubeMX (again). No success. Then I switched to an F411 Blackpill, its working in a minute.

I Googled a lot, there is not a single succesful effort on the net using the HAL library for USB audio speaker (however SPL audio middleware is working). No ST usb audio sample code for this family.

So either the CubeMX generated code is broken, or no one was able to figure out how to use it.

Please, ST, take a look into it...

Well, you have asked essentially the same question before.

STM32F103 Bluepill?

I wouldn't be surprised if this is also due to the STM32F103 counterfeits that have been used on the Bluepills for a long time, i.e. they are usually not original parts from STMicroelectronics.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
JVoro.2
Associate II

Sure, I hoped that the new HAL version is better.

It's definitely an original ST uC from the good old times. I tried it with a Nucleo as well. I am pretty sure it's broken code.

The HAL for the STM32F1 has not changed for a year, the STM32_USB_Device_Library has been unchanged for much longer and is essentially identical to that of the STM32F4.

What do you mean by "new HAL version"?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
JVoro.2
Associate II

The version number of the STM32CubeMX increased. I hoped, that ST corrected the broken code.

The HAL for the STM32F1 has not changed for a year

Considering it's not working, and it's a known "feature", it's not good news.

essentially identical to that of the STM32F4

Essentially... 🙂

The F411 code is working, but the f103 and f303 is not working. It's not just me, there is not a single working project on the net. The SPL library is working.

The version number of STM32CubeMX has nothing to do directly with the version number of the libraries. If it is about special functions of the HAL or LL, you should therefore look there first.

If something does not work as you expect, it would also be helpful to know what exactly you tried, so that it can be understood and tested.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
JVoro.2
Associate II

If something does not work as you expect, it would also be helpful to know what exactly you tried, so that it can be understood and tested.

Sure, thank you for help.

I tried to make a simple isochronous usb sound transfer from the PC to the STM32F103C8T6 (original ST uC, not a clone).

What I did:

Using STM32CubeMX (latest) set the clock system (8MHz crystal HS osc, 72MHz clock, 48MHz for the USB).

Enable serial wire debug.

Connectivity/ enable the USB, default parameter settings (full speed, Rx0 interrupt enabled).

Middleware/ enable USB_Device, select Audio Device Class, set USB_Audio_Freq to 48000.

Project manager/ minimum heap size to 0x2400, stack to 0x1000 (because the generated code uses malloc)

Generate code for Keil 5. Compile, no errors. Upload to device.

Test it:

Connect the to PC, Win11.

It enumerates, win11 recognises it as audio device.

First test, as simple as possible:

I select first my PC's built-in soundcard, and start a video in order to start audio stream. I hear the music.

Then I select the STM32 audio device on the PC. My expectation is silence, as the uC receives the stream, but there is no any processing of the stream.

But no, a short (shorter the 1 sec) pause in the sound, and the PC's sound card plays the music again.

It means, that my uC device failed to receive the audio stream, Win11 dropped it and switched back to the built-in soundcard.

I did this test using exactly the same settings etc. with an STM32F411 board, it is working as expected. Select the board: silence. Select the built-in soundcard, music. Repeat, allways working.

Then I wrote a simple test code for the F411 to handle the stream using the callback, and a PWM channel, it is working, I can hear the music from the uC, so it is definitely working well. (It's just a test, my project is not a usb speaker, but a HAM radio project that needs audio processing in the uC.)

Another test using the STM32F103 code and a debugger:

  • connect the usb to PC, enumerates as audio device, ok, select it on the PC
  • the mute callback is working if I mute in win11
  • then I start to play audio on the PC
  • no more callbacks, mute not working any more, the audio stream switches back to the PC soundcard

Hope, it's detailed enough for reproducing the problem.

While I have no deep knowlidge in the HAL library (I just like to use it, not debugging it), I am not absolute beginner. I was able to use it with the F411, and wrote a working usb audio code for the F103 too using the SPL. Tried tinyusb library as well with success.

regards,

Jozsef

With rare exceptions, almost everything in HAL/Cube code is broken and bloated. You cannot expect a reliable device, which is built on broken bloatware. And you cannot expect a decent code from incompetent developers...

Stick to TinyUSB - it is decent, rapidly evolving and designed by competent developers.

Tinyusb has no isochronous transfer support for the stm32F1xx and stm32F3xx family. I learned it the hard way, first tried it, and made an unsuccesful test. Then debugged it, and found the reason. Then Googled the forums and got the claim it's not supported...

So far the only working example is the UM0424 "STM32 USB audio speaker demo".

For the stm32F411 either the CubeMX generated code or Tinyusb is working too.