How to recover continuous data with DMA ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 5:56 AM
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
Solved! Go to Solution.
- Labels:
-
DMA
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 1:23 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 6:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 6:13 AM - edited ‎2023-11-30 6:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 11:15 AM
>>.. 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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 11:22 AM
> 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 11:24 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 11:34 AM - edited ‎2023-11-30 11:35 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 11:42 AM
Sorry,
Now I understand where to look. But this example still doesn't match what I'm looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 11:50 AM
Bummer. Hope you can find what you're looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-30 12:13 PM
@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.
