cancel
Showing results for 
Search instead for 
Did you mean: 

DMA with SAI

DYann.1
Senior II

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.

DYann1_0-1699536737285.png

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.

30 REPLIES 30

@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) ?

DYann1_0-1699626432780.png

I already checked the clock signals yesterday and I have good signals.

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

AScha3_0-1699627896191.png

(without the "__weak " of course ! )

If you feel a post has answered your question, please click "Accept as Solution".
Imen.D
ST Employee

Hi @DYann.1 ,

If you are using STM32H7 with DMA, please check this article: DMA is not working on STM32H7 devices.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Very good ! But I don't have drivers/hal../src : H7...hal_sai.c as you say. I have STM32L5xx but 

DYann1_1-1699628467814.png

it still looks like. So I try to call this Function in my Main just to see if the RX is complete. 

 

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 ?

DYann.1
Senior II

Hi,

I'll come back for the signals :

FS_B

DYann1_0-1699869186263.png

SCK_B

DYann1_2-1699869249826.png

MCLK_B

DYann1_5-1699869317735.png

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.

LCE
Principal

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 ?

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. 

LCE
Principal

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.

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.