Working with dynamic buffers with DMA for USART communications

Hi there,

I am writing an embedded app using RTIC and stm32f3xx_hal that communicates using a USART (#3 in this case). The interface with the serial device is working fine as long as I know the length of the message that comes from the device, but the device I am interacting with does not have a fixed length message. It can vary.

I am using DMA to fill my buffer (a static mutable array of n elements). It works great, very efficient, but I am not sure how to get around the read_exact function of the stm32f3xx_hal::serial::Rx struct found in the hal crate. If the message length of a message from the device is less than the buffer, I never get the message (well, eventually when another message comes through and meets the array length). If it is longer than the buffer, it just seems to truncate it.

A read_line type function would do the trick if it was available. I possibly could read 1 character at a time into a 1 length array and then assemble them and decipher the message type and payload, but this would seem to counter the efficiencies of what DMA is bringing (at least based on my very limited experience).

Or, perhaps I need to look into something like bbqueue and just manage the queue with FIFO?

I’m still learning Rust, getting more comfortable, but as my question might reveal, I’m still a newbie.

Thank you in advance for any input you might have.

Matt