[sdiy] STM32G4 SAI problems

rburnett at richieburnett.co.uk rburnett at richieburnett.co.uk
Sun Jul 16 16:39:38 CEST 2023

On 2023-07-16 13:53, Chris McDowell via Synth-diy wrote:
> Somewhere in the tool you have to tell it to actually generate code,
> though that setting should be on by default. I have found I also have
> to click on whatever tab I'm on in the tool, then save, then it will
> prompt to generate code. If you're not getting any new code generated,
> that's certainly the first hurdle. a quick check is to name a pin in
> the graphical pin setup tab, then check "main.h" for that pin name
> define.

It is certainly generating *some* code, as I can look through what it 
puts into "main.c" in between the comment lines.  And I know not to put 
my own code in the wrong places where it will get deleted ;-)  I 
probably need to slow down and walk before I try and run.  More "blinky 
LED" and "Hello World" examples for me I think before trying to get a 
CODEC interface working, and carefully look what code the config tool is 
generating each time a pin or clock is configured to do something new.

> The other cubeide gotcha is that most things set up with the config
> tool need to be enabled manually. I don't know if I2S / SAI works that
> way, but I'd bet it does. I often have to do a little digging in the
> hal library to find the associated "start" function living somewhere
> near the config and setup functions that cube calls in the generated
> code.

Yes, I did think of this.  I haven't got an Interrupt or DMA set up yet 
to feed my I2S peripheral with data, but had at least expected to be 
able to get it configured to the point where it would generate MCLK, SCK 
and Word Clock on the appropriate output pins.  Once I could see those 
signs of life I'd then proceed to feed data to the peripheral via an ISR 
or DMA.  Seeing that the appropriate pins are still tri-stated 
(floating) doesn't give me confidence to proceed further, and makes me 
think that either the SAI module isn't configured or that the pins 
aren't configured for use with that peripheral.

I'll do some single stepping through the code in debug mode and see what 
registers are actually getting written to.  As stated previous if there 
isn't an active clock to the SAI peripheral then all of the writes to 
the peripherals config registers will fall on deaf ears.  (The NXP 
Kinetis chip I used previously would throw a bus error exception if you 
tried to write to a peripheral without an active clock, which was 
helpful, but looks like STM32 just silently fails without performing the 

> And also, people certainly do like to complain about cube and hal
> online, but I rely on it heavily for work and it is not generally
> broken. I've had stumblings or misunderstandings but I don't think
> I've ever run into an issue that was ultimately a CubeIDE bug.

Ok, that's useful information and the sort of comment I was hoping for.  
This learning process is very much for my benefit and for a hobby 
project at the moment, but the NXP Kinetis chips we used to use at work 
have been unavailable now for 4 years, so if I end up liking STM32 it 
could well become my platform of choice for work stuff too.  So far I've 
got mixed impressions, but you've convinced me to give the tools the 
benefit of the doubt for a bit longer ;-)


More information about the Synth-diy mailing list