[sdiy] STM32G4 SAI problems

rburnett at richieburnett.co.uk rburnett at richieburnett.co.uk
Tue Aug 8 18:15:37 CEST 2023


I managed to get the SAI module on my STM32 Nucleo board working 
eventually.  Lessons learnt:

1. The graphical config tool for SAI appears to be a little bit broken.  
(Visually it looks like it isn't aware of where the SAI peripheral 
master clock is coming from in the RCC block, and it doesn't appear to 
calculate the sample-rate dividers and the rate error correctly in the 
tool.  However, despite it "looking" wrong, it generates meaningful and 
useful code for standard sample rates, 32k, 48k, 96k and automatically 
generated code can be edited for non-standard sample-rates.)
2. The graphical tool was generating the right code to configure the 
pins correctly for SAI peripheral alternative function.  This wasn't the 
reason why I was seeing no signs of life...
3. After being configured the SAI module doesn't generate any clock 
signals, until a transfer is "started" (be that polled, interrupt or 
DMA.)  Gerry, the polled example code you provided helped me to realise 
this!!! Thanks.
4. The way the various SAI dividers work for the MCLK, SCLK & FS is a 
bit strange on this chip and the documentation has a couple of typos and 
isn't particularly clear, (perhaps it also confused the people who wrote 
the graphical config tool for the peripheral!)
5. Reading the device manual, doing the calculations and setting the 
registers appropriately is now generating SAI outputs with the expected 
timings.

In general the hardware looks good and the HAL routines definitely help 
with SAI config.  I've managed to get 16-bit or 24-bit stereo audio 
going to an external I2S DAC or in both directions simultaneously with 
an AKM CODEC at 48kHz, 96kHz, etc. using an external 12.288MHz MCLK 
crystal oscillator module.  In fact the ping-pong DMA config on this 
chip actually turned out to be a breeze with STM32Cube compared to what 
I've become used to on other platforms.

Thanks again for your help everyone.  Particularly the online "Getting 
started with STM32" videos :-)

-Richie,


More information about the Synth-diy mailing list