Skip to main content
Explorer
April 2, 2025
Solved

DMA won’t function after firmware is updated with a data stream

  • April 2, 2025
  • 2 replies
  • 1214 views

The problem only happens when a constant stream of data is being send to the UART. When I update my firmware sometimes DMA won't work. It is hard to debug when it only happens when updating and not every time. 

This post is exactly the same issue as mine: DMA issue post 

In the first image below are the registers when DMA won't work. The second image are the registers when DMA is working correctly.

I looked at every register and tried manually resetting and staring the DMA, but still sometimes after an update DMA won't work. I can;t find the source of why this happens and why it won't work even when I hardware reset the controller.

 

I looked at the HAL datasheet and validated the steps needed for DMA. I'm really out of option. If someone has an idea on what to check or knows a solution (maybe don't use DMA but interrupt?).

problemproblem

 

no problemno problem

 

UART/DMA init

 hdma_uart5_rx.Instance = DMA1_Stream0;
 hdma_uart5_rx.Init.Channel = DMA_CHANNEL_4;
 hdma_uart5_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
 hdma_uart5_rx.Init.PeriphInc = DMA_PINC_DISABLE;
 hdma_uart5_rx.Init.MemInc = DMA_MINC_ENABLE;
 hdma_uart5_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
 hdma_uart5_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
 hdma_uart5_rx.Init.Mode = DMA_CIRCULAR;
 hdma_uart5_rx.Init.Priority = DMA_PRIORITY_HIGH;
 hdma_uart5_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

 

    This topic has been closed for replies.
    Best answer by dvp

    The issue was that the DMA interrupt wasn't enabled, so the system never entered the HAL_UART_ErrorCallback() when things went wrong. That also explains why the problem was intermittent — it only happened when data started arriving before everything was properly set up.

    At startup, the UART overrun flag was being set due to incoming data, but since the interrupt wasn't enabled, no error handler was triggered, and the system couldn't recover.

    Enabling the interrupt with:

     HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
     HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);

    fixed the problem.

    2 replies

    Technical Moderator
    April 2, 2025

    Hello @dvp and welcome to the ST community,


    @dvp wrote:

    This post is exactly the same issue as mine: https://community.st.com/t5/forums 


    If possible to update the link above as it's an invalid link.

    Super User
    April 2, 2025

    I see a StackOverflow link, but StackOverflow seems to be down at the moment (HTTP 503: Service Temporarily Unavailable)

    dvpAuthorAnswer
    Explorer
    April 4, 2025

    The issue was that the DMA interrupt wasn't enabled, so the system never entered the HAL_UART_ErrorCallback() when things went wrong. That also explains why the problem was intermittent — it only happened when data started arriving before everything was properly set up.

    At startup, the UART overrun flag was being set due to incoming data, but since the interrupt wasn't enabled, no error handler was triggered, and the system couldn't recover.

    Enabling the interrupt with:

     HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
     HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);

    fixed the problem.