Skip to main content
Visitor II
June 26, 2026
Solved

STM32 UART receives data intermittently after enabling DMA

  • June 26, 2026
  • 1 reply
  • 87 views

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:

  1. Configure the DMA channel in Circular Mode if continuous reception is required.

  2. Restart DMA reception inside the HAL_UART_RxCpltCallback() when using Normal Mode.

  3. Check for UART error flags such as Overrun (ORE), Framing Error (FE), and Noise Error (NE), and clear them if necessary.

  4. Ensure the NVIC priorities for both UART and DMA interrupts are configured correctly, especially when using FreeRTOS.

  5. Avoid lengthy processing inside interrupt callbacks. Instead, copy the received data to a queue or buffer and process it in a separate task.

  6. 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.

Best answer by Ghofrane GSOURI

Hello ​@jonsmith67 

You can take inspiration from the STM32CubeMX / STM32CubeIDE example projects provided by ST for UART communication with DMA. In the “New Project from Example” window, simply search for the following example names: UART_TwoBoards_ComDMA, UART_Hyperterminal_DMA, and UART_ReceptionToIdle_CircularDMA. These examples illustrate the main recommended approaches for UART reception, including basic DMA transfers, continuous reception, and DMA circular mode with IDLE line detection, which is especially useful for robust reception of variable-length frames. Even if the example is available for a different STM32 board, it can still serve as a very good reference for the HAL configuration, interrupt handling, DMA setup, and callback usage to adapt into your STM32F407 project.

 

You can also refer to ST’s official wiki page “Getting started with UART”, which provides a useful introduction to UART communication on STM32 and complements the example projects well: Getting started with UART

1 reply

Ghofrane GSOURI
Ghofrane GSOURIBest answer
ST Technical Moderator
June 29, 2026

Hello ​@jonsmith67 

You can take inspiration from the STM32CubeMX / STM32CubeIDE example projects provided by ST for UART communication with DMA. In the “New Project from Example” window, simply search for the following example names: UART_TwoBoards_ComDMA, UART_Hyperterminal_DMA, and UART_ReceptionToIdle_CircularDMA. These examples illustrate the main recommended approaches for UART reception, including basic DMA transfers, continuous reception, and DMA circular mode with IDLE line detection, which is especially useful for robust reception of variable-length frames. Even if the example is available for a different STM32 board, it can still serve as a very good reference for the HAL configuration, interrupt handling, DMA setup, and callback usage to adapt into your STM32F407 project.

 

You can also refer to ST’s official wiki page “Getting started with UART”, which provides a useful introduction to UART communication on STM32 and complements the example projects well: Getting started with UART

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.