cancel
Showing results for 
Search instead for 
Did you mean: 

Restarting UART DMA using HAL

kylepennington
Associate III
Posted on October 09, 2016 at 23:26

What is the best way to restart a DMA servicing a UART using the HAL drivers?

On the first iteration the DMA works correctly; transfers new data and fires interrupt.

On second iteration, the DMA transfers only one new data reading but doesn't fire an interrupt.

On the third iteration and beyond, the DMA doen't interrupt or transfer data. It is in

HAL_DMA_STATE_BUSY

.

I've tried using 

HAL_DMA_Abort, 

HAL_UART_DMAStop

, and recalling the DMA initialisation routine but it still doesn't restart correctly.

I can't find any documentation on how to restart the DMA with HAL drivers.

Any help would be greatly appreciated. Thanks.

5 REPLIES 5
slimen
Senior
Posted on October 10, 2016 at 11:35

Hello,

You can review the STM32 reference manual to see how the DMA works

There is a set of DMA examples useful for your case in STM32cube packages

STM32CubeXX 

that use HAL library. So, try to pick the one suitable for the device and board you are using and start from it. 

The example will give you an overview of how to design and code each part for your application.

Regards

Walid FTITI_O
Senior II
Posted on October 10, 2016 at 13:49

Hi kpnz, 

It seems you don't need to restart DMA but you need to check how DMA is configured in your code and haw you call UART transmit function in your main function. Try to run the ''UART_HyperTerminal_DMA'' example in on of STM32CubeFx library package relevant to the STM32 device you are using.

-Hannibal-

kylepennington
Associate III
Posted on October 11, 2016 at 00:00

Thank you for your replies.

I was using the example code from the STM32Cube project, but that code only uses the DMA once then enters an infinite loop.

The problem was that the receiving UART stream continued after the DMA had completed, causing the UART to over-run, which seems to prevent the second DMA transfer from working.

 I added

__HAL_USART_CLEAR_OREFLAG(&huart1); 

before calling HAL_UART_Receive_DMA to ensure the over-run flag was clear and it's all working now.

Will any of the other UART flags cause this same problem?

Walid FTITI_O
Senior II
Posted on October 17, 2016 at 12:55

Hi kpnz, 

Which device you are using and which STM32Cube package version.

Thanks 

-Hannibal-

Thank u so much, i been fighting with the same issue for over a week, for me:
__HAL_UART_CLEAR_OREFLAG(&huart1); 
did the trick!