cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f2xx_hal_uart.c | UART_WaitOnFlagUntilTimeout() 's Status parameter usage

teik-hong
Associate
Posted on June 11, 2015 at 11:33

Hi folks,

I was looking at the generated code from STM Cube @ STMCubeGeneratedCode\Drivers\STM32F2xx_HAL_Driver\Src\stm32fxx_hal_uart.c, UART_WaitOnFlagUntilTimeout() below. According to the comment of the code, the Status is meant for the new Status of the flag, however if  you look at the code below, the algorithm seems to be doing the opposite(due to the while loop expression).

/**

  * @brief  This function handles UART Communication Timeout.

  * @param  huart: UART handle

  * @param  Flag: specifies the UART flag to check.

  * @param 

Status

:

The new Flag status (SET or RESET).

  * @param  Timeout: Timeout duration

  * @retval HAL status

  */

static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus

Status

, uint32_t Timeout)

{

  uint32_t timeout = 0;

 

  timeout = HAL_GetTick() + Timeout;

 

  /* Wait until flag is set */

  if(

Status == RESET

)

  {

    while(__HAL_UART_GET_FLAG(huart, Flag) ==

RESET

)

    {

      /* Check for the Timeout */

      if(Timeout != HAL_MAX_DELAY)

      {

        if(HAL_GetTick() >= timeout)

        {

          /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */

          __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);

          __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);

          __HAL_UART_DISABLE_IT(huart, UART_IT_PE);

          __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);

          huart->State= HAL_UART_STATE_READY;

          /* Process Unlocked */

          __HAL_UNLOCK(huart);

          return HAL_TIMEOUT;

        }

      }

    }

  }

  else

  {

    while(__HAL_UART_GET_FLAG(huart, Flag) != RESET)

    {

      /* Check for the Timeout */

      if(Timeout != HAL_MAX_DELAY)

      {

        if(HAL_GetTick() >= timeout)

        {

          /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */

          __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);

          __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);

          __HAL_UART_DISABLE_IT(huart, UART_IT_PE);

          __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);

          huart->State= HAL_UART_STATE_READY;

          /* Process Unlocked */

          __HAL_UNLOCK(huart);

       

          return HAL_TIMEOUT;

        }

      }

    }

  }

  return HAL_OK;     

}
0 REPLIES 0