Playing Chiptunes on an STM32L476G Discovery Board

Hours of music from a board with 128k RAM / 1MB Storage

smt32l476 chiptune player


For ECE271 the final lab of the semester was playing a 440Hz sine wave out the DAC port of the STM32L476G Discovery board. For extra credit they could play some music too (the textbook has most of the code for playing Twinkle Twinkle Little Star). Since I already had some existing sound code from previous projects, I kept escalating my demo code: first by playing some 3-channel sound files from a custom tracker, then by playing some ZX Spectrum PT3 chiptunes.

The Player

The code is written in C. It uses my pt3 player code (originally written for the pi-chiptune player and the Apple II PT3 player). The raw AY-3-8910 data is then fed into Alexander Sashnov's libayemu.

Initially the resulting 16-bit mono samples were fed at roughly 44kHz into the 12-bit DAC on the STM SoC. This comes out pin PA5 and a capacitor is used to drop it to line level.

The final version uses i2c/i2s to send 16-bit stereo samples the CS43L22 DAC which can output through the audio jack.

The Progression (In Reverse Chronological Order)