2025-01-12 03:10 PM
Hi,
MCU - STM32h743
I have a use case where I need to receive a large chunk of data on UART, and the RX data length is unknown. I have read ST articles about how to do this using the IDLE feature with circular DMA (HAL_UARTEx_ReceiveToIdle_DMA). However, I have a few doubts about this.
I read that you can enable interrupts for DMA TC, HT, and IDLE events to handle this. For example, if I have a DMA buffer of 3 KB and I receive 1 KB of data on UART, and if I understand correctly, this should trigger an IDLE interrupt when communication stops after receiving 1 KB. But will this interrupt also confirm that the data has already been copied to the DMA buffer? How can I be sure that the data has already been copied when I have the IDLE interrupt so that I can copy the data from the DMA buffer ?
2025-01-12 03:41 PM
Hi,
so you have a real fast cpu and receive RS232 (slow data rate) - but with unknown length.
So you dont need the dma here to avoid data loss (with slow cpu and high data speed the game is different),
rather the opposite : the dma might create big problems with unknown size of data blocks.
I would recommend only using receive with INT , because no problem with any length and time/pause between data.
Just dont forget both callbacks: receive and receive/error .
2025-01-12 04:51 PM
Within the IDLE IRQ completion routine you have several conditions to check. For your question, check the UART receive data flag to see if there is any data still pending in the UART. If not, the DMA controller has completed the last cycle with plenty of time to spare. This should not be an issue since, assuming you are framing packets by inter-message gap (for example, binary MODBUS), the IDLE timeout period will provide an ample period of time to complete the last DMA cycle.
The other issues are RX errors and DMA completion (typically a sign of data overrun). This assumes your DMA length is greater than one (preferably two if continuous receive) maximum data packet. DMA would normally be terminated in the IDLE completion routine or updating buffer pointers if there's no incoming flow control.
No idea how the ST libraries handle this, I don't use them.
Jack Peacock