After adding some code to my project, I found the the I2S audio no longer worked.
But, the code that was added was to a completely different part of the application.
On further investigation, I found that for some reason if I call the SAI initialisation at start of my main(), which is fw_main_task() since I'm using RTOS, the audio gets corrupted.
I also found that the transfer using
SAI_TransferSendEDMA(I2S0, &g_SAI_TX_Handle, &xfer);
Was not receiving the ISR callback to indicate that the transfer was complete.
Debugging into SAI_TransferSendEDMA, as far as I can tell, the parameters which are passed in &xfer seem to have a valid length, which I presume is the only thing that matters
A workaround to get the ISR to be called, seems to be to set the optimization to anything except -Os (optimize for size).
-O2 (which is almost the same as -Os) works OK, and even -O3 works.
So I'm kinda stumped about why...
1. I can't setup the SAI interface at the very beginning of main()
2. Why optimusation -O2 and -O3 work, and I get a callback (ISR), but -Os fails to do so.
Note, the optimization level is only in the function calling SAI_TransferSendEDMA. I initially tried turning down the optimization on fsl_si_edma.c but it didn't make any difference.
I also note that by default the SDK example projects are set to no optimization, which I find a bit odd, as normally I use -Os because -O0 results in very large binary sizes and code that runs unnecessarily slowly/