Skip to main content
Explorer
November 30, 2023
Solved

How to recover continuous data with DMA ?

  • November 30, 2023
  • 2 replies
  • 3919 views

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

    This topic has been closed for replies.
    Best answer by DYann.1

    @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.

    2 replies

    Super User
    November 30, 2023

    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.

    DYann.1Author
    Explorer
    November 30, 2023

    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

     

    Graduate II
    November 30, 2023

    >>.. 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.

    Super User
    November 30, 2023

    > 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.

    DYann.1Author
    Explorer
    November 30, 2023

    @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