STM32 UART receives data intermittently after enabling DMA
Hi everyone,
I'm working on an STM32 project where UART communication uses DMA for receiving data. The application works correctly after startup, but after running for a few minutes, the UART stops receiving data intermittently.
Project details:
-
MCU: STM32F407VG
-
STM32CubeIDE 1.16
-
HAL drivers
-
UART2 configured with DMA in Normal Mode
-
FreeRTOS enabled
I've already tried:
-
Increasing the DMA buffer size.
-
Lowering the baud rate from 115200 to 57600.
-
Verifying the UART wiring.
-
Checking for overrun errors.
The DMA interrupt still occurs, but the receive callback is not always executed.
Has anyone experienced a similar issue? Is there a recommended way to keep UART DMA reception running continuously?
Solution
The issue was related to how DMA reception was configured.
The following changes resolved the problem:
-
Configure the DMA channel in Circular Mode if continuous reception is required.
-
Restart DMA reception inside the
HAL_UART_RxCpltCallback()when using Normal Mode. -
Check for UART error flags such as Overrun (ORE), Framing Error (FE), and Noise Error (NE), and clear them if necessary.
-
Ensure the NVIC priorities for both UART and DMA interrupts are configured correctly, especially when using FreeRTOS.
-
Avoid lengthy processing inside interrupt callbacks. Instead, copy the received data to a queue or buffer and process it in a separate task.
-
Verify that the DMA buffer is not being overwritten before the application finishes reading the data.
After switching to Circular Mode and moving packet processing out of the interrupt callback, UART reception became stable and no further data loss occurred.
If anyone has additional recommendations or best practices for continuous UART DMA communication on STM32 devices, I'd be interested in hearing them.
If you want any information click here.
