cancel
Showing results for 
Search instead for 
Did you mean: 

How to recover continuous data with DMA ?

DYann.1
Senior

Hello,

I have a program that works in DMA but I would like to put a function to know when the transfer in the DMA is finished so that I can recover the data continuously. Do you have any information on this ? Here is part of my code

 

  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;
  	}

  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_Receive_DMA(&hsai_BlockA1, (uint8_t *)playbuf_RX, (sizeof(playbuf_RX))/4);
  if (fresult != HAL_OK)
  	{
  	return HAL_ERROR;
  	}
  fresult = HAL_SAI_Transmit_DMA(&hsai_BlockB1, (uint8_t *)playbuf , (sizeof(playbuf))/4);
  if (fresult != HAL_OK)
  	{
  	return HAL_ERROR;
  	}

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

@David Littell wrote:

Another entitled brat.  Thanks, Generation Arduino!


We talk about everything except the subject. You deserve to be the KING my friend ! Not the Senior III.

View solution in original post

11 REPLIES 11
TDK
Guru

The HAL_SAI_TxHalfCpltCallback/HAL_SAI_TxCpltCallback functions should be used to process data. When half-transfer completes, the first half of the buffer is ready for processing. When full transfer completes, the second half of the buffer is ready.

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

Hi, 

Thank you for this information but can you tell me how to implement it with an example code please ? In my case I just need about the HAL_SAI_RxHalfCpltCallback and HAL_SAI_RxCpltCallback, in fact my previous code works by simulation I looped the TX with the RX and I created 2 tables, one TX and one RX. But in reality the data comes from a CODEC and my STM32 only receives the data sent by the CODEC

 

int32_t playbuf[4096*2] __attribute__ ((aligned (32)));
int32_t playbuf_RX [4096*2] __attribute__ ((aligned (32)));  
  for (i=0;i<8192;i++)
  {playbuf_RX[i]=0;}
  for (i=0;i<8192;i++)
  {playbuf[i]=i;}

Here is the summary of my diagram

DYann1_0-1701353856828.png

 

>>.. can you tell me how to implement it with an example code please ?

I guess that's where the computer science or software engineering degree kicks in.

You need to disengage the linear thinking, and think about how you juggle data in real-time from basically a ping-pong buffer. The callbacks facilitate you managing the inactive half of the live buffer, and you've got to get it done prior to the next half coming around.

How and what you're doing with the data is at the crux of your use case, not sure there's a one size fits all example that satisfies this without a recursive what do I do next type question.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

> Thank you for this information but can you tell me how to implement it with an example code please? 

Writing basic code for people is not very enjoyable to me. If you share what you have, I will look at it.

There are plenty of DMA examples in CubeMX that illustrate this premise that you can go after given sufficient drive and motivation.

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

@Tesla DeLorean wrote:

How and what you're doing with the data is at the crux of your use case, not sure there's a one size fits all example that satisfies this without a recursive what do I do next type question.


A lot of phrasing without saying much. On youtube or a few clicks I find more information of what you say. If you can enlighten me, do so, but otherwise, please don't come to talk about literature.

Thank you


@TDK wrote:

There are plenty of DMA examples in CubeMX that illustrate this premise that you can go after given sufficient drive and motivation.


Plenty I trust you but when I go to CubeMX and type the keywords I only have 6 examples. And that's not what I'm looking for but thanks anyway.

DYann1_0-1701372912491.png

Sorry,

Now I understand where to look. But this example still doesn't match what I'm looking for.

DYann1_0-1701373328693.png

Bummer. Hope you can find what you're looking for.

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

@TDK wrote:

Bummer. Hope you can find what you're looking for.


This forum is great, whether it exists or not it doesn't change anything! When you don't have an answer, well.... You'll never have answers.