Skip to main content
Lukasz Przenioslo
Associate III
September 29, 2015
Question

HAL UART transfer with DMA keeps busy

  • September 29, 2015
  • 4 replies
  • 4744 views
Posted on September 29, 2015 at 15:28

Hello there,

I am trying to write a logger application using uart4 and DMA on STM32F4 discovery. I am usinh HAL lib and I can send through uart using regular transfer funtion without problem:

HAL_UART_Transmit(&huart4, ''mama_'', 5, 1000);

But when I try to use the DMA version:

HAL_UART_Transmit_DMA(&huart4, ''mama_'', 5);

I can only send the message once, because after that this function returns status ''HAL_UART_STATE_BUSY''. I am trying to send this message every 1 second. Why is DMA bussy in this time? I have generated my config code using Cube software and when looking at the Hyperterminal examples its pretty similar. What am I doing wrong or what did i forget? I would apreciate all help.
    This topic has been closed for replies.

    4 replies

    Lukasz Przenioslo
    Associate III
    September 30, 2015
    Posted on September 30, 2015 at 08:38

    Anyone please?

    qwer.asdf
    Senior
    September 30, 2015
    Posted on September 30, 2015 at 09:50

    Are you handling the interrupts? Here is the code from the STM32F4 examples in STM32Cube_FW_F4_V1.8.0\Projects\STM32F4-Discovery\Examples\UART\UART_TwoBoards_ComDMA\Src\stm32f4xx_it.c:

    /**
    * @brief This function handles DMA RX interrupt request. 
    * @param None
    * @retval None 
    */
    void
    USARTx_DMA_RX_IRQHandler(
    void
    )
    {
    HAL_DMA_IRQHandler(UartHandle.hdmarx);
    }
    /**
    * @brief This function handles DMA TX interrupt request.
    * @param None
    * @retval None 
    */
    void
    USARTx_DMA_TX_IRQHandler(
    void
    )
    {
    HAL_DMA_IRQHandler(UartHandle.hdmatx);
    }
    /**
    * @brief This function handles USARTx interrupt request.
    * @param None
    * @retval None
    */
    void
    USARTx_IRQHandler(
    void
    )
    {
    HAL_UART_IRQHandler(&UartHandle);
    }

    Nickname5522_O
    Visitor II
    September 30, 2015
    Posted on September 30, 2015 at 11:06

    Hi Bremen,

    You should add the function that handles USART interrupts.

    /** 
    * @brief This function handles USARTx interrupt request. 
    * @param None 
    * @retval None 
    */ 
    void USARTx_IRQHandler(void) 
    { 
    HAL_UART_IRQHandler(&UartHandle); 
    }

    Indeed, the function ''HAL_UART_IRQHandler()'' calls ''UART_Transmit_IT()'' function that sets the USART state to ''HAL_UART_STATE_READY''. -Shahrzad-
    Lukasz Przenioslo
    Associate III
    September 30, 2015
    Posted on September 30, 2015 at 18:12

    Thats true, after handling interrupts the code started working. I didnt know it works like that. Thank you.