2023-11-09 05:32 AM
Hello,
I would like to use DMA with SAI but I am having difficulty writing the code. Can you check if my code is correct and why I cannot retrieve the RX values ?
/* USER CODE BEGIN 2 */
HAL_SAI_RegisterCallback(&hsai_BlockA1, HAL_SAI_RX_HALFCOMPLETE_CB_ID, HAL_SAI_RxHalfCpltCallback);
HAL_SAI_RegisterCallback(&hsai_BlockA1, HAL_SAI_RX_COMPLETE_CB_ID, HAL_SAI_RxCpltCallback);
fresult= HAL_SAI_Init(&hsai_BlockA1);
if (fresult != HAL_OK)
{
return HAL_ERROR;
}
fresult = HAL_SAI_Receive_DMA(&hsai_BlockA1, (uint8_t *)playbuf_RX, (sizeof(playbuf_RX))/4);
HAL_SAI_RegisterCallback(&hsai_BlockB1, HAL_SAI_TX_HALFCOMPLETE_CB_ID, HAL_SAI_TxHalfCpltCallback);
HAL_SAI_RegisterCallback(&hsai_BlockB1, HAL_SAI_TX_COMPLETE_CB_ID, HAL_SAI_TxCpltCallback);
fresult= HAL_SAI_Init(&hsai_BlockB1);
if (fresult != HAL_OK)
{
return HAL_ERROR;
}
fresult = HAL_SAI_Transmit_DMA(&hsai_BlockB1, (uint8_t *)playbuf , (sizeof(playbuf))/4);
With CubeMX I have configured 2 DMAs.
One to send the data and the other to read the data again.
I think I'm missing something for the callback but I don't know how to use it to retrieve the values.
Thank you for your helps.
Regards.
Solved! Go to Solution.
2023-11-10 06:31 AM
@AScha.3 wrote:2. set a breakpoint at receive callback
How to do that ? Where I can find the information for this function ? I would like to call this function in the Main to know when reception is complete (RX) ?
I already checked the clock signals yesterday and I have good signals.
2023-11-10 06:52 AM - edited 2023-11-10 06:54 AM
> Where I can find the information for this function ?
the secrets of HAL ....
look in the drivers/hal../src : H7...hal_sai.c -> what you have to write as function name <- this will be called
(without the "__weak " of course ! )
2023-11-10 07:02 AM
Hi @DYann.1 ,
If you are using STM32H7 with DMA, please check this article: DMA is not working on STM32H7 devices.
Regards
Imen
2023-11-10 07:02 AM - edited 2023-11-10 07:02 AM
Very good ! But I don't have drivers/hal../src : H7...hal_sai.c as you say. I have STM32L5xx but
it still looks like. So I try to call this Function in my Main just to see if the RX is complete.
2023-11-10 07:06 AM
Hi Imen,
No I have a evaluation board STM32L552E-EV but I use with another CODEC only. Can you tell me if the DMA will not work on the SAI too ?
2023-11-13 02:01 AM
Hi,
I'll come back for the signals :
FS_B
SCK_B
MCLK_B
I also detected if the buffer_RX is correctly filled by flashing the LED with the code below :
while (1)
{
/* USER CODE END WHILE */
HAL_SAI_TxHalfCpltCallback (&hsai_BlockA1);
{HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3);
HAL_Delay(200);}
/* USER CODE BEGIN 3 */
}
But I can't find the expected values. You really have no idea where this could come from ? Thank you for your helps.
2023-11-13 07:06 AM
You don't understand the callback's purpose:
It's not something you call to check, it should be called automatically when the DMA triggers the half- / complete interrupts. Check the HAL files.
Just because the examples do not exactly fit your purpose, you should look at theses and understand what's going on. Are there no SAI playback / record examples for L5 ?
2023-11-13 07:17 AM
Hi,
There is an example with the evaluation card but there is no '.ioc' file and it is not easy to understand the configuration of the SAI and the peripherals.
It seems to me that it was you who told me to do this test, by sending an initialized table and making a connection between the TX and the RX. I have a TX array initialized but the values are not found in the RX array. Most likely the test configuration is not correct or I have incorrectly initialized my arrays.
2023-11-13 07:39 AM
Why that effin' ioc file?
You need to understand the underlying code!
Nobody said it's going to be easy. ;)
Yes, I said it's a good way for testing the SAI, because it keeps any external ICs out of the code.
But sure you can try something else.
2023-11-13 07:43 AM
I've already looked at the example provided with the evaluation card but I don't understand it very well. I thought that connecting TX with RX is simpler for me but ultimately nothing is simple.