This project is a fully functional, multithreaded "Personal MP3 Player" developed for BCA182 Laboratory Activity 2. It is built on the RT-Thread RT-Spark development board, featuring an STM32F407ZGT6 ARM Cortex-M4 microcontroller.
Rather than decoding compressed audio files from an SD card, the system mathematically synthesizes audio notes in real-time. The PCM (Pulse Code Modulation) data is generated on the fly and streamed directly to the onboard ES8388 audio codec via I2S and DMA. The application leverages FreeRTOS to manage concurrent tasks cooperatively, ensuring a responsive user interface (LCD and RGB matrix) and uninterrupted audio playback through the 3.5mm headphone jack.
How It WorksThe player uses three separate FreeRTOS threads to handle different tasks without blocking each other:
update_lcd_leds_thread: Manages the UI. It uses a mutex to safely access the FSMC-driven LCD, preventing race conditions. It updates the song name, selection menu, and RGB matrix effects.
update_lcd_leds_thread: Manages the UI. It uses a mutex to safely access the FSMC-driven LCD, preventing race conditions. It updates the song name, selection menu, and RGB matrix effects.
polling_buttons: Reads and debounces the onboard navigation buttons. It implements the 3-bit binary selection logic for the 8 songs and the Play/Pause state machine.
polling_buttons: Reads and debounces the onboard navigation buttons. It implements the 3-bit binary selection logic for the 8 songs and the Play/Pause state machine.
Audio Controller: This task handles the song_player and audio_synth engines. It utilizes a phase accumulator to generate sine waves at a 44.1 kHz sampling rate. The PCM data is then fed into a circular DMA buffer to stream to the I2S3 peripheral, minimizing CPU overhead.
- Audio Controller: This task handles the
song_playerandaudio_synthengines. It utilizes a phase accumulator to generate sine waves at a 44.1 kHz sampling rate. The PCM data is then fed into a circular DMA buffer to stream to the I2S3 peripheral, minimizing CPU overhead.
The system uses a 3-bit selection method for the 8 programmed melodies:
000- Für Elise001- Canon in D010- Minuet in G Major011- Turkish March100- Nocturne in E-flat101- Waltz No. 2110- Nocturne in C-sharp111- Symphony No. 40







Comments