Skip to main content
Visitor II
November 29, 2019
Question

Implement UART Transmit in DMA mode correct way

  • November 29, 2019
  • 4 replies
  • 4252 views

I am using stm32f779I eval kit. I am using example UART_HyperTerminal_DMA by en.stm32cubef7.

I am trying to implement UART in DMA mode to transmit a simple string.

So I have used CubeMX to generate the code and I have configured UART1 TX DMA in normal mode.

Whenever I run the code in debugging mode, I see the first time I attemp to send the string, it works ok and sends the string.

But I couldn't send a second transmission.

Can any one please suggest the correct way to use Uart Tx in DMA mode? How can I send successive strings one after another?

E.g. :

i used

 if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxStartMessage, TXSTARTMESSAGESIZE-10)!= HAL_OK)

 {

  /* Transfer error in transmission process */

  Error_Handler();

 }

 if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxStartMessage, TXSTARTMESSAGESIZE-10)!= HAL_OK)

 {

  /* Transfer error in transmission process */

  Error_Handler();

 }

2 times HAL_UART_Transmit_DMA() API. 2nd time API has huart->gState == HAL_UART_STATE_BUSY_TX

    This topic has been closed for replies.

    4 replies

    Visitor II
    November 29, 2019

    Check this one.

    https://community.st.com/s/question/0D50X0000BcPXk2SQG/32f746-usart-dma-with-stemwin-not-working

    and maybe you forget to wait for uart DMA working. If uart DMA is not finished the first message. the huart is in busy state so the second message will not work. try add this code before next transmit.

     while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

     {

     }

    phenomAuthor
    Visitor II
    November 29, 2019

    Hi,

    I have added code as suggested by you:

    Print()

    {

    HAL_UART_Transmit_DMA(&UartHandle, (uint8_t *)ch, len);

      while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

      {

      }

    }

     But after HAL_UART_Transmit_DMA() execution pointer goes to

     void DMA2_Stream7_IRQHandler(void)

    {

      HAL_DMA_IRQHandler(UartHandle.hdmatx);

    };

    in stm32f7xx_it.c and then comes back to 

      while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

      {

      }

    Here while loop never ends.

    Visitor II
    November 29, 2019

    Did you check the first signal transmission . Do it have data output? if it's not.

    Please check MX_DMA_Init() function. you have to call this function before MX_USARTx_UART_Init().

    phenomAuthor
    Visitor II
    November 29, 2019

    My issue is same as

    https://community.st.com/s/question/0D50X00009XkgtY/dma-uart-with-hal-remain-busy-bug

    but solution provided in this link is not working for me.

    Already  HAL_UART_IRQHandler()  enabled.

    Super User
    November 30, 2019

    Do you observe the Tx pin using an oscilloscope/LA? Is there any activity related to the second "batch" of data?

    Read out and check the USART and relevant DMA registers content.

    JW

    phenomAuthor
    Visitor II
    December 2, 2019

    Hi,

    I have added code as suggested by you:

    Print()

    {

    HAL_UART_Transmit_DMA(&UartHandle, (uint8_t *)ch, len);

      while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

      {

      }

    }

     But after HAL_UART_Transmit_DMA() execution pointer goes to

     void DMA2_Stream7_IRQHandler(void)

    {

      HAL_DMA_IRQHandler(UartHandle.hdmatx);

    };

    in stm32f7xx_it.c and then comes back to 

      while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

      {

      }

    Here while loop never ends.

    Visitor II
    February 9, 2022

    Hey,

    I am facing the same issue. How did you solve it? Thank you for your Answer.

    I am using a STM32G4

    Visitor II
    August 12, 2024

    Facing exactly same issue, have you ever find the solution and root cause? DISCOVERY 1 stm32f407 board...

    Graduate II
    August 12, 2024

    You haven't posted any code so no telling what could be wrong.

    See if this helps https://github.com/karlyamashita/Nucleo-G431RB_Three_UART/wiki