cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 DMA in UART RX

hariprasad
Associate III
Posted on December 03, 2015 at 14:38

I will be receiving 10 bytes on UART RX periodically and I want to configure UART RX DMA for it.

Configuring DMA is like loading the NDTR register with the number of bytes to transfer from/to peripheral to/from memory.

So if I want to configure DMA for UART do I have to initialize DMA controller in each DMA periodic transacation of 10 bytes ?

#stm32 #dma
5 REPLIES 5
Posted on December 03, 2015 at 16:42

Well you're going to have to configure enough of it to restart the transfer.

Rx is always an issue because you have to deal with data loss or resync issues. Consider a circular buffer of 20 and interrupt on the HT/TC, and fish out what you need, for the more simplistic approach.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Amel NASRI
ST Employee
Posted on December 03, 2015 at 17:20

Hi arbitrer,

Using the DMA circular mode, you should be able to automatically initialize NDTR content without reconfiguring the DMA.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

hariprasad
Associate III
Posted on December 04, 2015 at 08:34

Hi

I reffered circular mode code from [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/UART%20with%20DMA%20mode&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=16364]this post

and I changed the Buffer size to 10 from 32, but when I'm transferring 10bytes to STM32 I'm not getting Transfer Complete consistently every time.

Is it because of the DMA_SxNDTR = Multiple of ((Mburst beat) × (Msize)/(Psize))

inconsistency

When I checked MBURST, MSIZE, and PSIZE all are configured for byte, so it should give me DMA_TC on reception of every 10 byte .

What am I missing?

AvaTar
Lead
Posted on December 04, 2015 at 09:28

>What am I missing?

 

Most probably one or more characters.

That's why DMA is inappropriate for occasional, non-permanent transmissions.

If you miss one character in a packet, the first character of the nect packet will trigger the transfer. That gets you out of sync, and introduces a substantial delay.

Use the RXNE interrupt of the UART, this is much more appropriate for your case.

And always assume that characters might get lost, or corrupted.

hariprasad
Associate III
Posted on December 04, 2015 at 11:52

But If I'm following Clive's code blindly, ie; 32byte buffer, on every transaction I'm getting the TC flag, So if it was byte missing/corruption it should reflect here also and I don't expect that