on 2022-06-22 6:37 AM
It is also worth mentioning before diving that not all STM32 have a DAC, so make sure you properly adjust the code to your own STM32 peripheral availability
The code implemented was based on the AN4453 with the STSW-STM32022 package and update to use the HAL and LL driver, so this firmware can be easily tailored to any other STM32. 
The focus of this article is to guide you over the firmware implementation for the low-level portion of an audio player, including how to configure the peripherals to play audio files and how to convert these files to be read by the STM32 without relying on other middleware’s, such as USB (mass storage) and Filesystem to store several audio files in external memories. This means that the audio file will be placed in the embedded FLASH of the MCU, with considerable limits the size of it.
These are the requirements for this article’s implementation:
STM32CubeIDE (version 1.7.0 or higher)
STM3G0 HAL firmware pack – you can install this from within STM32CubeIDE
STSW-STM32022 software pack
SOX – WAV to IMA converter, can be downloaded here
HxD – IMA to C vector, ca be downloaded here
NUCLEO-G071RB – our STM32 board
STEVAL-CCA037VI – our audio amplifier board
A small way to prototype the low pass filter 
Your WAV file
Note: Have your WAV file ready – please be aware that this implementation will use the MCU’s embedded FLASH to store your audio file, so it is recommended to have an audio that has only a few seconds, otherwise it might not fit in the embedded FLASH. An improvement of this implementation would be to add an external memory to allow larger audio files to be played.
Before diving into the firmware, a few notes about the hardware construction. We’ll aim to have a 16bit resolution in total when using the PWM, this will be done by separated it in 8bit for the MSB (TIM3 channel 1) and 8bit for the LSB (TIM3 channel 2) – to achieve this, the PWM output pins must pass thru a combined low pass filters as shown in the image below – note that there is a relationship between the resistor values, where R2 is obtained by dividing R1 by 256:
Alternatively, for a simple experiment, you can use just the MSB portion (TIM3 channel 1) and have a simpler low pass filter, like this:
 
Hi, I was wondering when Part 2 be published?, this is good article and would like to use it for toy sound
How does the choice of STM32 model affect the implementation of audio playback, considering the availability of DAC?
STM32F407G-DISC1 but this written code didn't work then can you help about this? dac1
I did ima convert online. c file --> Hxd
Hello @B.Montanari
I am following this tutorial to better understand how the timer is configured. I noticed that you explained the calculations of PWM frequency, where f_PWM = 125 kHz, but I did not see this being implemented in the STM32CubeIDE nor in CubeMX in this tutorial.
Also, how do we know that Timer 3 (TIM3) runs off of APB timer?