2024-02-05 09:08 PM - last edited on 2024-09-24 05:17 AM by Amel NASRI
Hi,
I have a board with an STM32U575 at the core.
I'm attempting to set up SAI receiver in I2S mode, with 32-bit 48kHz sampling. See my configuration of SAI A below:
I also want to receive the data continuously in circular mode via DMA (or GPDMA in the case of this MCU).
Reading other sources, I've concluded that the following setup should be established:
The audio DMA functions can be seen below. The Audio_Init() function is called once in the main function, and the CpltCallback functions are called by DMA interrupts.
static uint16_t audio_rx[AUDIO_BUFFER_SIZE];
static uint16_t audio_tx[AUDIO_BUFFER_SIZE];
void Audio_Init(){
audio_ready_flag = AUDIO_DATA_FREE;
if(HAL_SAI_Receive_DMA(&AUDIO_RX_PORT, (uint8_t *)audio_rx, AUDIO_BUFFER_SIZE) != HAL_OK){
Error_Handler();
}
if(HAL_SAI_Transmit_DMA(&AUDIO_TX_PORT, (uint8_t *)audio_tx, AUDIO_BUFFER_SIZE) != HAL_OK){
Error_Handler();
}
}
void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hi2s){
audio_ready_flag = AUDIO_DATA_READY_HALF;
}
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hi2s){
audio_ready_flag = AUDIO_DATA_READY_FULL;
}
(I'm omitting all the HAL stuff, since I've already showed the setup in the above images. I want to note that all of the HAL code seems to be configured correctly --> no errors or warnings)
When my hardware has no audio source connected to it, I would assume that the audio data stored via DMA in the audio_rx buffer should be equal to 0 (and maybe some weak noise).
However, my buffer is filled with what appears to be 16-bit garbage values:
Why is this? I've successfully implemented this code on my old build, which used a STM32G4.
I'm very thankful for any help I can receive on this issue!
Best regards,
Max Borglowe
Solved! Go to Solution.
2024-02-29 10:32 AM
I'm setting this as the solution, because the way I interpreted the data was the issue all along!
By outputting the RX buffer audio_rx to the HAL_SAI_Transmit_DMA function, I can now confirm that the audio data is both received and transmitted correctly.
Here's my takeaway from this discussion, which I'll leave as a reference for anyone who is experiencing similar issues:
1. The "garbage" data I was receiving at the beginning of this thread was actually just very low noise swinging around zero. What I was totally unaware of was that the ADC and DAC data is transceived in 2's complement, i.e. signed integers of the size defined in the CubeMX (32-bit ints in my case).
So, check the MX setup I posted later in the thread if you want to configure reception of 32-bit data (both GPDMA and SAI).
2. The strange looking waveforms that I posted late in the thread was probably just a result of the SWV not being perfect, or maybe some HP-filtering on the ADC inputs.
And finally, hats off to @LCE who helped me in this struggle. Not all heroes wear capes ;)
2024-02-29 10:53 PM - edited 2024-02-29 10:56 PM
Great you got it running now! Thanks for the summary.
> Not all heroes wear capes
If you knew... ;)
PS: It might have helped if you had connected RX / TX data IOs, with a simple sawtooth on TX, there would have been no 2's complement trouble.