UART variable sized string receive with DMA and a timer

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

UART variable sized string receive with DMA and a timer

Post by rolanddixon »

I am new to ChibiOS but have been developing on STM32 and LPC43xx MCUs in a super loop fashion for a while now. A functionality that I found useful was the ability to reset a general purpose timer counter (STM32) or the SCT (LPC43xx) from an external source without an interrupt (timer slave reset mode configuration on STM32). This allowed me to connect the UART receive source to the UART_RX pin and another pin that resets a timer count on any polarity transition. The DMA can then handle any UART receive by putting it onto a buffer and then if the timer counter ever reaches the value in the timer's Auto Reload Register (STM32) an interrupt is generated and we know that nothing is being sent anymore (transmission is finished) so we can then collect the data on the DMA buffer for processing. This allows variable sized string receives without any processor interaction at all as we can query the DMA counter in the interrupt routine once the receive is finished.

Is there any such functionality in the ChibiOS hal? I am currently using the Serial driver to receive each byte separately as it becomes available which is quite a resource intensive method (similar to https://github.com/grantmd/ChibiCopter/ ... ster/GPS.c).

This is useful for things like a GPS unit that sends NMEA strings of variable size.

Thank you for any help in advance.

Roland
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: UART variable sized string receive with DMA and a timer

Post by Giovanni »

Hi,

There is the UART driver which is unbuffered, fixed-size oriented and uses the DMA internally.

Giovanni
rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Re: UART variable sized string receive with DMA and a timer

Post by rolanddixon »

Thank you for the quick reply.

So is there no way of reseting the a GPT based on an external signal transition without using an interrupt?

I have not looked into the hal underlying code much but could I program a timer (say TIM3 on the STM32F4xx) at register level to do slave resets without upsetting other Chibios peripheral drivers other than GTP?

I must say, I am impressed by chibiOS, how easy you have made it to get going, its functionalityand portability, so thank you.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: UART variable sized string receive with DMA and a timer

Post by Giovanni »

Hi,

This may require some custom programming of timers, it is possible you could use the ICU driver for that (the overflow callback specifically).

Giovanni
rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Re: UART variable sized string receive with DMA and a timer

Post by rolanddixon »

I did it by adapting the GPT drivers to reset on an external signal. Working like a charm. Thank you.
chibby314
Posts: 3
Joined: Tue Feb 24, 2015 12:00 am

Re: UART variable sized string receive with DMA and a timer

Post by chibby314 »

Have a look at the UART IDLE interrupt!
I use this Interrupt as an indication that the bus is idle .. (never guessed that - huh?)
In the ISR i check for transmitted / received byte count and signal tasks accordingly.

Best,
chibby
Post Reply