2024-05-20 11:52 PM
Hello,
I am currently programming an STM32F469I in STM32CubeIDE (I am a beginner with STM) and I am facing some issues.
What I want: I want to read WAV file data from an SD card and send it to the AUX output so I can hear it on my headset/speaker. Currently, I am reading the data from a buffer, but I will change that afterwards once I know that everything works.
What is the issue?: The issue is that the sound plays way too fast and I don't know why. I am attaching my project so you can download it and look at it.
My main files are saved under /Core/Src
Thank you for your help!
Solved! Go to Solution.
2024-06-10 02:38 AM
Hey, after reviewing the code I'm using, I discovered that I'm modifying the SAI data size within the code.
So, that was the issue.
// From
haudio_out_sai.Init.DataSize = SAI_DATASIZE_16;
// To
haudio_out_sai.Init.DataSize = SAI_DATASIZE_32;
If you encounter any errors because it's too fast, simply change the data size to 32.
Thanks for the help ;)
2024-05-21 02:29 AM - edited 2024-05-21 02:34 AM
Hi,
so you got it working...right ?
But you use the BSP functions - i never did.
>The issue is that the sound plays way too fast
from source:
/**
* @brief Updates the audio frequency.
* AudioFreq: Audio frequency used to play the audio stream.
* @note This API should be called after the BSP_AUDIO_OUT_Init() to adjust the
* audio frequency.
*/
void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
and you use:
BSP_AUDIO_OUT_Init(2, 60, 44100);
AUDIO_Play_Start((uint32_t *)0x08080000, (uint32_t)0x143046);
HAL_Delay(500);
BSP_AUDIO_OUT_Pause();
BSP_AUDIO_OUT_SetFrequency(8000);
BSP_AUDIO_OUT_Resume();
So start with 44k1 , then switch to 8k ? why ?
Did you check, whats written to CSxxx codec ? And whats set in SAIx_Init(..) to the SAI ?
2024-05-21 02:35 AM - edited 2024-05-21 03:04 AM
so you got it working...right ?
Yeah, but just way to fast.
So start with 44k1 , then switch to 8k ? why ?
It was just to test if it would run slower with it, because in the BSP file, it was much slower with 8k. Unfortunately, it sounds nearly the same with 8k or 44k1.
Did you check, whats written to CSxxx codec ? And whats set in SAIx_Init(..) to the SAI ?
Yes but I don't understand where I could "slow" the code down
"I also tried to copy the SAI initialization from the BSP to my SAI initialization (in main.c line 675), but it resulted in the same issue."
2024-05-21 03:03 AM - edited 2024-05-21 03:07 AM
>Yes but I don't understand where I could "slow" the code down
The audio speed (= sample rate) is set by the SAI master and what you set it to.
in Cube:
then start it, from now its continuously running... (Check with scope the signal, word clk...to prove your setting.)
fresult = HAL_DMA_Init(&hdma_sai1_a);
fresult = HAL_SAI_Transmit_DMA(&hsai_BlockA1, (uint8_t *)playbuf , (sizeof(playbuf))/4);// SAI start
(playbuf is int32_t here, because i use 32b sample format, so you might adjust for int16 )
Then just feed it in half/full callbacks - thats it, to get it running. :)
2024-05-21 04:28 AM - edited 2024-05-21 05:04 AM
fresult = HAL_DMA_Init(&hdma_sai1_a);
fresult = HAL_SAI_Transmit_DMA(&hsai_BlockA1, (uint8_t *)playbuf , (sizeof(playbuf))/4);// SAI start
I tried a bit with the code but had no success; now i cant hear anything
I also inserted HAL_DMA_Init(&hdma_sai1_a) as you suggested.
I changed the following:
uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size)
{
uint8_t ret = AUDIO_OK;
/* Call the audio Codec Play function */
if(audio_drv->Play(AUDIO_I2C_ADDRESS, pBuffer, Size) != 0)
{
ret = AUDIO_ERROR;
}
/* Initiate a DMA transfer of PCM samples towards the serial audio interface */
if(ret == AUDIO_OK)
{
// Changed here
if ( HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t *)pBuffer , (sizeof(pBuffer))/4)!= HAL_OK)
{
ret = AUDIO_ERROR;
}
}
return ret;
}
And I think it would be an good idea, to upload my SAI config:
2024-05-21 07:32 AM - edited 2024-05-21 07:36 AM
>And I think it would be an good idea, to upload my SAI config
"Config" ...is wrong word for this , more "disfig". :)
1. SAI DMA data with : word + word ? (32b) -> half-word + half-word (16b)
2. SAI parameters : data size : 8 bit ??? -> 16 bit
+ protocol : free ?? -> I2S standard
+ frame : 8b ???? -> (stereo) -> 32 b (or 2 slot , whatever it shows you for I2S )
Then check with a scope : all signals ok, as should it be .
Your CSxxx dac is ..? + set to I2S , 16b stereo , right ?
2024-05-22 01:03 AM - edited 2024-05-22 01:05 AM
So, I changed everything you mentioned, but without any success; it's still the same issue.
I am not using I²S.
@AScha.3 wrote:Your CSxxx dac is ..? + set to I2S , 16b stereo , right ?
So, I changed everything you mentioned, but I have some issues with the protocol i only have Free and AC97 . I am not using I²S. What do you mean by "Your csxxx DAC"? If you mean the chip on the board, it's the CS43L22.
2024-05-22 02:33 AM
Yes , CS43L22 .
+
> I am not using I²S.
Why ? just set it to I2S , also SAI - and it should work.
2024-05-22 02:53 AM
I can't choose the I2S standard for the SAI protocol. Maybe there is something wrong with my I2S configuration?
I2S:
SAI:
2024-05-22 03:10 AM
Ok...i see, on F4xxx , seems no I2S preset :) (what a mess ... I only use H743 and H563 for this, they have it.)
so we try free :