Showing results for 
Search instead for 
Did you mean: 

Resetting DMA memory pointer for USART TX



I'm using USART with DMA to transmit a fixed sized packet message from master to slave, and have the slave send back a fixed size response.   I have a freeRTOS enabled.  I have DMA setup in circular mode, and set the buffer size to twice the size of the largest packet size I expect to receive, in case of an overflow which is unlikely to happen.  This all works well but would like to improve my solution to avoid having a freeRTOS task on the slave block for a short time when it sends a response.

How do I reset the USART DMA's rx buffer memory pointer to DMA_CMAR's initial programmed value?

I currently send a response and reset the USART/DMA on the slave after it receives a request from the master like this:

HAL_UART_Transmit(&huart2, (uint8_t*)txData, 4, HAL_MAX_DELAY);


HAL_UART_Receive_DMA(&huart2, clock_USART_DMA_RX_Buffer, CLOCK_PACKET_MAX_LENGTH * 2);


I would like to do something like the following instead, but when I transmit from the

slave using DMA, I need to block the freeRTOS task to wait until the slave UART is

done transmitting back to the master. If I don't wait, the transmission gets cut off early

when DMA is stopped:

HAL_UART_Transmit_DMA(&huart2, (uint8_t*)txData, 4);

// need to poll DMA Transfer Complete here.... which blocks freeRTOS task


HAL_UART_Receive_DMA(&huart2, clock_USART_DMA_RX_Buffer, CLOCK_PACKET_MAX_LENGTH * 2);


Thank you


Why are you calling HAL_UART_DMAStop at all? The transmission will stop when it's complete, no need to wait around until it does. You could also call it prior to HAL_UART_Transmit_DMA and start the RX and TX at the same time, if you really wanted.

In terms of receiving, setting up a circular buffer and processing data as it comes in is the most robust solution, rather than stopping/starting RX all the time. You can use the idle/HT/TC interrupts to process data appropriately.

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

So now you have to learn asynchronous and multi-thread software design and development. In other words, you "just" have to learn the actual software engineering, because your current level of understanding is on a level of Arduino and HAL/Cube team.

As for the reception:

@Guenael Cadier will gladly tell you how "easy" all of it is with the "competently designed and useful" HAL library!