cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f uart init bug

Cheng zhihua
Associate
Posted on May 13, 2017 at 03:50

this   if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))  should be if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) < Timeout))  

static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)

{

  /* Wait until flag is set */

  while((__HAL_USART_GET_FLAG(husart, Flag) ? SET : RESET) == Status)

  {

    /* Check for the Timeout */

    if(Timeout != HAL_MAX_DELAY)

    {

      if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))

      {

        /* Disable the USART Transmit Complete Interrupt */

        CLEAR_BIT(husart->Instance->CR1, USART_CR1_TXEIE);

        /* Disable the USART RXNE Interrupt */

        CLEAR_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);

        /* Disable the USART Parity Error Interrupt */

        CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);

        /* Disable the USART Error Interrupt: (Frame error, noise error, overrun error) */

        CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);

        husart->State= HAL_USART_STATE_READY;

        /* Process Unlocked */

        __HAL_UNLOCK(husart);

        return HAL_TIMEOUT;

      }

    }

  }

  return HAL_OK;

}
2 REPLIES 2
Posted on May 13, 2017 at 18:40

>>this   if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))  should be if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) < Timeout))  

Wouldn't that cause it to return HAL_TIMEOUT in 100% of cases where the first read didn't have the desired status?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cheng zhihua
Associate
Posted on May 15, 2017 at 03:17

Thank you for your reply.

Sorry,My  English is not good.

My Problem is :    STM32F051C8      SOFTWARE  RESET THEN  STOP MX_USART1_UART_Init();  no restart

This USART_ISR_TEACK always   SET.

I before software reset(Iwdg reset),

while(HAL_UART_AbortTransmit(&huart1)!=HAL_OK);

     while(HAL_UART_AbortReceive(&huart1)!=HAL_OK);

     while(HAL_UART_Abort_IT(&huart1)!=HAL_OK);

     while(HAL_UART_AbortTransmit_IT(&huart1)!=HAL_OK);

     while(HAL_UART_AbortReceive_IT(&huart1)!=HAL_OK);

     while(HAL_UART_Abort(&huart1) !=HAL_OK);

     while(HAL_UART_DeInit(&huart1)!=HAL_OK);

Than Infinite loop  this  UART_WaitOnFlagUntilTimeout(huart, USART_ISR_TEACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) 

if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_TEACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) != HAL_OK)

      {

        /* Timeout occurred */

        return HAL_TIMEOUT;

      }