cancel
Showing results for 
Search instead for 
Did you mean: 

DMA to receive unknown length frames with UART

po221
Senior

Hi

I need to listen to Rx UART to receive unknown length frames (I will search for a frame start byte, then read the frame size and then test a CRC for frame validating)

I would like to use DMA for performance but I only see half or full reception interrupt of a fixed number of bytes.

Is it possible to do that with DMA or must I using simple interrupts, with 1interrupt for each byte received ?

thanks in advance

PS : I'm using STM32L431 with STM32cubeIDE

6 REPLIES 6

Cube-based, although principle may be usable generally:

https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx

Author is ST FAE.

JW

po221
Senior
RMcCa
Senior II

Dunno about L4s, but F7s have a UART character match interrupt that i have used in conjunction with DMA. If you can terminate the messages with a unique framing character, this method works great. Just stop the DMA in the UART isr and read the NDTR​ and subtract from the initial value to find the number of bytes in the message.

po221
Senior

L4 reference manual indicates CMIE Character match control bit.

I look for this solution too

Thanks

Depends if the pattern appears elsewhere in the data stream.

Personally found it easier to use a circular DMA buffer I can sweep on the 1 KHz ticker, or main loop

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thus the reason for the word 'unique' in my response. I use ascii hex to send user commands to my system partially for this reason. 0x0a can only happen at the end of a message. Using ascii hex effectively halves the actual transmission rate in exchange for robustness that is simple and efficient to implement.​