cancel
Showing results for 
Search instead for 
Did you mean: 

DMA and USART

jennyschneider2
Associate II
Posted on February 10, 2010 at 20:57

DMA and USART

4 REPLIES 4
Posted on May 17, 2011 at 13:39

Create code to manage your buffer(s)

Build a scatter-gather type list of fragments you want to send, or buffer them to be sent. Each fragment would minimally contain an Address and Size, and perhaps linking or context information.

Dispatch the next fragment to the DMA controller, as it asserts TC (Terminal Count) for the prior fragment. You'd want to to this in the TC IRQ handler.

-Clive

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jennyschneider2
Associate II
Posted on May 17, 2011 at 13:39

Hi Clive,

thank you very much for your help.

This sounds a little bit complex. Lets see if i got this right.

The easiest way woult be to put all data that has to be sent in a single buffer with fixed size. As soon as this buffer is full, i restart the DMA with count of the buffer size. As soon as the Transfer Complete interrupt occurs, i can rewrite the buffer.

Is this correct? Has anyone done this and might provide me an example?

Posted on May 17, 2011 at 13:40

Yes, pretty much. You can't touch/refill the DMA buffer until you get a TC.

The problem with fixed size buffers is that you will introduce a lot of latency if you have to wait to fill them. You might want to be able to send partial buffers. At a minimum you really want to have at least two fixed buffers which you can alternate in a ping-and-pong fashion. It is always better to have prepared a secondary buffer which can be lit off immediately once you get the terminal count for the primary. Once the DMA is busy you can go about preparing the next buffer so it is ready. You will also need to consider the startup conditions where your data stalls, or the transmission is otherwise idle.

Fixed size ping-pong buffers work well for audio data, where the rate of consumption is known/constant.

The benefit of using scatter-gather type technics is that you can leave data already in static buffers where it is, and eliminate unnecessary copying of buffers.

The USART DMA_Interrupt example code represents a reasonable starting point, you'll just have to hack it around to get a more general solution.

You are probably best served  by just starting with DMA for transmit. Receiving unknown amounts of data coming in randomly via DMA is probably more fun than you want.

-Clive

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jennyschneider2
Associate II
Posted on May 17, 2011 at 13:40

Hi Clive,

thanks again. Sending fixed buffers works now. Furtunatly this is the most import

ant part.

I have found an application Note (AN3109) from ST, which deals exactly with this topic (DMA and USART, FIFO, ...).

Here is the link:

http://www.st.com/stonline/products/literature/an/16795.pdf

Thank you very much!

Yours

Jenny