2026-01-05 5:34 AM
Hi,
I want to design a voice announcement system using the STM32F103C8T6.
My requirement is to Load WAV audio files from an SD card and play them using the STM32, without using any external DAC.
I would like guidance on how to start the project using STM32CubeMX / STM32CubeIDE, including:
Peripheral configuration in CubeMX
Audio playback method without a DAC (for example, PWM-based audio)
Basic coding structure to read WAV files from an SD card and play them
Any help or reference projects would be greatly appreciated.
I have design hardware also here attachment is there please go through it ...Thank you
Solved! Go to Solution.
2026-01-06 12:05 AM
@itrajusankar The examples given by @MOBEJ refer to an external audio DAC, which would also be possible with an STM32F103. However, apart from the schematics, you have not provided many details so far, neither that it is an genuine STM32F103 and not one of the many counterfeits, nor the expected maximum audio frequency, nor an explanation of what you mean by ‘not as good as expected’ in the result.
We can only speculate at this point and assume that you are using TIM4 as a PWM output on PB6 and PB8, correct?
I must also assume that you are generating an internal frequency of 72MHz from the HSE=8MHz. Your low-pass filter of 1k+100nF, which you have on each of the two PWM outputs, has a cut-off frequency of 1591Hz, which could be suitable for subwoofers at best. For reasonably good audio quality (which also needs to be defined first), I assume a minimum PWM resolution of 14 bits. With these parameters, we can already estimate the result: 72MHz/16384 ~ 4394Hz, which is extremely attenuated by the low-pass filter – this cannot produce a meaningful result.
Regards
/Peter
2026-01-05 5:45 AM
Welcome @itrajusankar, to the community!
If your STM32F103C8T6 is on a so called Blue Pill, it is most likely not a device from STMicroelectronics but an illegal counterfeit, so you would need to contact its manufacturer.
Regards
/Peter
2026-01-05 6:40 AM
Welcome to the forum.
Please see How to write your question to maximize your chances to find a solution for best results.
@itrajusankar wrote:using the STM32F103C8T6.
As @Peter BENSCH said, if that's on a Blue Pill, then prepare for a bumpy ride... !
For a better experience, I would strongly suggest that you get a Nulceo-F103 instead.
Do you already have experience with STM32? and/or any other microcontroller(s)?
If not, then it would be better to start with some basics first.
As always, the secret is to break down your project into manageable parts; eg,
ST provide examples for the first two - especially if you use an ST board.
@itrajusankar wrote:I have design hardware also here attachment is there please go through it .
You forgot the attachment?
Did you study the Application note AN2586, "Getting started with STM32F10xxx hardware development" ?
And other documentation:
https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#documentation
Again, I would strongly suggest that you start on a known-good board (eg, Nucleo) before adding the uncertainties of unverified hardware!
2026-01-05 6:57 AM
> ... without using any external DAC.
That's fine - but you still need to tell us how you want to output those WAV files, and in a way they remain comprehensible.
A lot depends on that.
> - Basic coding structure to read WAV files from an SD card and play them
Just use a file system like FatFS.
With that, more generic WAV file examples will do.
Select an appropriate library for decoding WAV files that can be ported to a CM3, or for which already ports exist.
Decoding RIFF files "by hand" (with you own code) is less than trivial, and would consume a lot of time and effort.
2026-01-05 7:04 AM
As @Ozone suggests, decoding a WAV file may be non-trivial.
The format is well-documented and widely-used; eg, https://en.wikipedia.org/wiki/WAV
You might be able to simplify your implementation by restricting yourself to just a certain specific type of WAV file.
Or maybe just use a simple binary format instead?
2026-01-05 7:16 AM
Hello @itrajusankar ,
You can find an audio example using I2S with DMA in the I2S_Audio example on GitHub. This example demonstrates how to play an audio file with an external codec on the STM32F1xx board via the I2S peripheral using DMA transfers.
Additionally, you can refer to the BSP example in the sub-demo named "AUDIO PLAY". This example shows how to play, pause, resume, and adjust the volume (from 50% to 100%) of audio playback using the Key or Joystick buttons.
You can adapt and deploy these examples to your own STM32 device by modifying the peripheral settings and pin configurations accordingly.
Br
2026-01-05 7:17 AM
> Or maybe just use a simple binary format instead?
Which is what I would probably do.
Convert them to simple binary files of fixed format (probably signed 8-bit) and sampling frequency, and store them either in SD card files of fixed names, or in Flash.
PC-based libraries make reading and decoding WAV a relatively trivial task, so even writing such a converter tool would not consume much time.
2026-01-05 10:01 PM
2026-01-05 10:08 PM
Hi Andrew,
Thank you for your quick reply.
We have already designed our custom board, and it is working fine. We also have some experience with the STM32F103C8T6. However, this is our first project involving audio-related applications.
We are able to get voice output, but the audio clarity is not as good as we expected. Kindly guide us with some example code or reference implementation to help improve the audio quality.
Thank you for your support.
2026-01-05 10:10 PM
Hi
Thank you for your quick reply.
We have already designed our custom board, and it is working fine. We also have some experience with the STM32F103C8T6. However, this is our first project involving audio-related applications.
We are able to get voice output, but the audio clarity is not as good as we expected. Kindly guide us with some example code or reference implementation to help improve the audio quality.
Thank you for your support.