Skip to main content
Visitor II
January 23, 2023
Solved

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

  • January 23, 2023
  • 2 replies
  • 2321 views

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

    This topic has been closed for replies.
    Best answer by Sarra.S

    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!

    2 replies

    Super User
    January 23, 2023

    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.

    Sarra.SAnswer
    ST Employee
    January 23, 2023

    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!

    Graduate II
    January 23, 2023

    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

    ST Employee
    January 23, 2023

    Sure! you're right