UART DMA receive in circular mode

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

UART DMA receive in circular mode

Postby franek.bmw » Wed Feb 12, 2020 8:57 am

Hello!

I have to receive data from uart very fast. It is possible to use uart with dma in circular mode using standard Chibios functions?
I think about DMA circular buffer with size about 1024bytes and callback or irq when each 256 bytes are received. It is possible to configure uart for this functionality using standard Chibios functions?

Thank you in advance for any help and advice,
best regards,
Franek

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: UART DMA receive in circular mode

Postby Giovanni » Wed Feb 12, 2020 2:47 pm

Hi,

This scenario is not supported.

It would be difficult to implement because it would be hard to synchronize the DMA memory pointer with your software read/write pointer, the DMA pointer would move continuously and unpredictably (from a SW point of view).

You would have to suspend DMA operations, do your read/write then resume DMA operations, I am not even sure it is possible to suspend/resume DMA channels.

You could try to implement a half callback event callback like ADC, DAC, I2S, SPI drivers but probably that would not work for an UART.

Giovanni

electronic_eel
Posts: 77
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 17 times

Re: UART DMA receive in circular mode

Postby electronic_eel » Wed Feb 12, 2020 8:36 pm

I concur that the circular buffer implementation won't be easy to implement in a correct way.

Giovanni wrote:You would have to suspend DMA operations, do your read/write then resume DMA operations, I am not even sure it is possible to suspend/resume DMA channels.

How about using two buffers instead of the circular buffer?

Use the ISR for half transfer complete to disable the current dma transaction and set up a new one to the second buffer. Replacing on half transfer (and not on fully complete) is to allow for some interrupt latency. You have to calculate if that is necessary or if the fully complete ISR would be enough.

While the dma is going to the second buffer, you can read out the first buffer safely in your regular thread.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: UART DMA receive in circular mode

Postby Giovanni » Thu Feb 13, 2020 6:02 am

electronic_eel wrote:I concur that the circular buffer implementation won't be easy to implement in a correct way.

Giovanni wrote:You would have to suspend DMA operations, do your read/write then resume DMA operations, I am not even sure it is possible to suspend/resume DMA channels.

How about using two buffers instead of the circular buffer?

Use the ISR for half transfer complete to disable the current dma transaction and set up a new one to the second buffer. Replacing on half transfer (and not on fully complete) is to allow for some interrupt latency. You have to calculate if that is necessary or if the fully complete ISR would be enough.

While the dma is going to the second buffer, you can read out the first buffer safely in your regular thread.


With dual buffers you are getting an "RX event" only after half buffer has been filled not for each received byte. On TX side it could work with some tricks.

It would not fit in the current UART driver model anyway, it is designed for fixed size data exchange not continuous streams.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 8 guests