UART & DMA overrun error
Hi all.
I'm working on a project where my MCU (STM32H755) communicate with a device via UART at 921600 Bauds.
Here some details about the environment:
The device sends constantly, each second, a log at 921600 Bauds.
The MCU sends at same speed some commands to the device, the device will answer after that the command is executed and continue to sends out log. There isn't any synchronization mechanism for communication (no clock signal or CTS/RTS is used), plus, there isn't any difference or special character that will allow me to differentiate between command answer and log, so I must take everything I receive in a window of time and parse it at upper level (not relevant for this question), and, finally, to manage the communication I tried with FIFO enabled and disabled (but result seems to not change)
What I do to manage the communication is the following:
1a: Flush Read data register (but is this sufficient in case of FIFO enabled?)
2a: Enable DMA via HAL_UART_RECEIVE_DMA API
3a: Enable UART peripheral setting the UE bit into CR1 register.
4a: transmit data in polling mode.
For reception, I set the Number of bytes to receive to 20KB but I will never receive this amount of data, I need this because the device constantly sends me log and when it will answer, the command answer will be sent between 2 logs.
After a certain time (timer interrupt), I do the following to manage the communication end.
1b: disable UART via UE bit.
2b: Abort DMA reception via UART_ABORT_DMA API.
3b: flush Read Data register.
What happens is that sometimes, after the step 2a (with FIFO enabled) or randomly during reception process (if FIFO disabled) an overrun error (ORE bit) fires and the DMA will abort. As result I will find only 1 character into my Rx buffer instead a log+command answer, or some garbage characters or no characters.
I tried to manage the error calling interrupt API, clearing error flag and resuming DMA but this seems to not work.
The DMA is serving requests coming from ADC1 and 2 too, but the priority of the UART request is set to Very high, meanwhile for the ADCs the priority is set to normal.
How can I properly manage this communication on a clean way?
