A FreeRTOS based project were a spectrum analyser is displayed on a LED matrix board run from a STM32 device
A MAX7219 based 8x8 led matrix displays the fast fourier transform (FFT) of an incoming audio signal picked up by a microphone. The incoming audio is a double buffered DMA signal. The led matrix is driven via the STM32’s SPI interface. All while internal hardware timers and FreeRTOS are responsible for accurate timing e.g. refresh rate of led matrix and data acquisition.
The following tools are needed to build this project
- make
- arm-none-eabi-gcc
- gcc (for unit tests)
- st-flash in order to interact with the STM32
- [X] Create LED matrix driver for MAX7219 devices
- [X] Drive LED matrix from STM32 using FreeRTOS
- [X] Run FFT off target
- [X] Verify FFT on target (using off target results as a guide)
- [X] Verify that LED matrix can be driven alongside FFT code (manually verified, no delays etc.)
- [X] Capture data from mic
- [X] Verify output of mic from raw logic analyser data (using SigPlotI2S)
- [X] Capture data from mic via DMA
- [X] Perform FFT on this raw logic analyser data with a sine wave test tone (off-target)
- [X] Animate FFT graphs to get a rough estimate of how the LED matrix will display it (off-target)
- [X] Perform FFT on mic data sampled by STM32 with a sine wave test tone (off-target)
- [X] Verify that LED matrix can be driven along with data capture and processing
- [X] Perform FFT on captured mic data to drive LED matrix
FFT size = 64, start offset = 0, next offset = 32, FPS = 4
FFT size = 64, bin resolution = (1/60E-6)/64 –> ~260Hz
Note: I measured one Ws period as 60us on PulseView hence the 1/60E-6 above
Peak expected at the 7th/8th bin (2000 / 260 = ~7.69)
Peak expected at the 15th/16th bin (4000 / 260 = ~15.36)
Since the I2S Ws period is 60us, this gives us a sampling frequency of 16.66 kHz. Giving us a visual representation of 0-8.88 kHz with Spekky Matrix
Sine sweep source (youtube link)
Note: Gif is played at 2.5x speed, see mp4 for realtime playback and audio of sweep test
Rough timing of how long each task/sub-task takes to complete
Actual times are a mean of the traces from the timing branch
- FreeRTOS
- CMSIS V6
- ARM CMSIS DSP
- STM32G4xx Nucleo BSP
- STM32G4 HAL
- CMSIS G4 CMSIS device library
- Greatest C test framework
- fff C test doubles
- SigPlotI2S Plot I2S PulseView/Sigrok output data
CMSIS will also produce linker warnings due to newlib e.g. “_write is not implemented and will always fail”. There is quite a bit of a size overhead when pulling in all the CMSIS modules. An average project would be around ~100Mb. This increases with FreeRTOS too.