cancel
Showing results for 
Search instead for 
Did you mean: 

USART with DMA receive Timeout

laurie
Associate II
Posted on February 06, 2012 at 03:34

Hi, I'm using an STM32F103 board running at 24Mhz. I have USART1 set at 115200 to send and receive transfers using DMA. This is working fine except when an incomplete packet is received. What I need to do is add a timeout capability similar to that suggested in Method 1 of AN3109.

Unlike method 1,

I was thinking it would function by setting a timer that would generate an update event interrupt (my timeout indication) at say a 3 character time interval (The time to receive 3 characters). If the update event interrupt is generated then a timeout has occurred. The timer is preferably started when the first character is received. Every time a character is received, the timer is reset. The timer is stopped when the whole packet has been received. Packets are at least 20 characters in length.

How do I connect an Input Capture to the RX line (PA10)? The manual really didn�t help me understand this (or I didn�t find the section that explains it).

I�m guessing I must have to use TIM1_CH3 as it is also listed as being on PA10.

Is that true or could I use a different timer and channel?

I�d really like to see sample code that sets up this configuration as I can�t find any.

Seems like something that would be useful to lots of users too.

Cheers                                  ...Laurie:{)

P.S. Having looked for this for days and then posting, within 30 minutes I find this:

http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/SW_DRIVER/an3109.zip

Just going through it now to see if it holds the asnwers.

...Laurie:{)

Answering my own questions:

You have to make a physical connection from the RX pin to a TIMx_CHn pin (where x and n are the timer and channel that will then monitor the comms).

I don't have a spare pin on the production board so I've decided that on the receipt of the first character I'll calculate the timer length to be 3 characters longer than the expected characters to be received (I know how many characters to expect). Start the timer.

If all the characters are received then stop the timer.

If not all characters are received, the timer will update and generate a timeout event.

Thanks         ...Laurie:{)

#dma-timeout
10 REPLIES 10
jpeacock
Associate III
Posted on August 05, 2015 at 19:58

The idle detect is an event that marks the gap between the end of a message and the start of the next message.  It's an edge event, there has to be two messages arriving to detect the idle gap as the ending frame for the first, starting frame for the second.  So your requirement is a gap of more than one character time plus a guarantee a second message will arrive, or something like a sync character used as a filler between messages.

Using idle isn't a very good way to end RX DMA unless there is a constant stream of incoming messages so you are guaranteed a new message to complete the frame of the old message.  That's why ST recommends connecting the RX data input to a timer reset instead.  With a timer reset there's no dependency on the next message arriving in order to terminate the current message.

One of the best examples of this issue is the Modbus RTU (binary) protocol, where there has to be a minimum time between messages in order to detect an end of message framing mark.  Using idle won't guarantee the minimum time, and it stalls the completed message until a new one arrives (assuming it does, although the line may be turned around while the host is waiting for a reply, so no second message ever arrives).

   Jack Peacock