cancel
Showing results for 
Search instead for 
Did you mean: 

Hlo everyone, I am new to work on stm32g071rb mcu and i am working on a project in which i want to play the mp3 files from the SD card attached to the hardware. to fetch that mp3 filesI am also using the FATFS library but how to play those mp3 files.

SGoel.2
Associate III

Can anyone suggest me some easy tips/libraries to play or decode those mp3 files to the speaker.

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

Hello @SGoel.2​,

just to clarify the steps for you, so you can have some insights on how to dot it

To play MP3 files from an SD card attached to an STM32G071RB MCU :

  1. first configure the SPI and GPIO pins in STM32CubeIDE.
  2. wire your SD card adapter to the appropriate pins.
  3. use the FatFS library to access the MP3 files stored on the card.
  4. use a library to decode the MP3 files and output the audio (libmad for example)
  5. configure the DMA to transfer the audio data from the MCU to the speaker.

Hope that helps!

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.

View solution in original post

6 REPLIES 6
AScha.3
Chief III

this is not easy...i have a player running, but on H743 cpu; also on F411 , but RAM was almost used up here. MP3 decoder use about 10% cpu time on H743 at 200MHz, so expect about 60% cpu on this small 64MHz cpu, + time for reading from SDcard (without SDIO controller - i never tried);

so this cpu is on limits for MP3 music player. i would recommend other cpu, if you want ready to run examples, look for Arduino and faster cpu, maybe something like ESP32 .

but if you want try on this cpu, here some info:

i use mp3 decoder from here: https://github.com/lieff/minimp3

but on small cpu without float unit, better use : https://keyj.emphy.de/minimp3/

or look here : https://www.underbit.com/products/mad

or try using the lib from STM example: STM32 Audio MP3 Decoder Library - no, i see: This package includes MP3 Decoder libraries, depending on the STM32 device core: it supports STM32 devices with CortexM3, CortexM4 and CortexM7 cores. -- need bigger cpu .

so try minimp3 or take bigger and faster cpu, stm32F411 has SDIO and float, much better preconditions for mp3-decoder project.

If you feel a post has answered your question, please click "Accept as Solution".
Sarra.S
ST Employee

Hello @SGoel.2​,

just to clarify the steps for you, so you can have some insights on how to dot it

To play MP3 files from an SD card attached to an STM32G071RB MCU :

  1. first configure the SPI and GPIO pins in STM32CubeIDE.
  2. wire your SD card adapter to the appropriate pins.
  3. use the FatFS library to access the MP3 files stored on the card.
  4. use a library to decode the MP3 files and output the audio (libmad for example)
  5. configure the DMA to transfer the audio data from the MCU to the speaker.

Hope that helps!

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.

On step5, depends of what he is using to output the audio.

If its a hardware audio codec then DMA+I2C

If its just an amplifier then DMA+DAC

we dont need to firmware by ourselves, lets talk

Sure! you're right

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.

Hello @Saara.S & @Javier, Thank you for your information, I have understood your reply, as you said:

  1. I have configured the SPI & GPIO pins in STM32CubeIDE.
  2. Also I've connected the SD card adapter to that pins & also using FATFS library to fetch that audio files stored in SD card
  3. Now I am adding the libmad library in my code and confirm you when it will done.
  4. I am using external speaker as a output device connected to the board.

According to your message i have initialized the DMA & DAC for output the PCM samples and also added the libmad library for decoding the mp3 audio in my code but can u suggest me some sample program based on Libmad library to do the decoding and store it on buffer for sending to output device.

@Community member​ also can u please help me regarding this.