cancel
Showing results for 
Search instead for 
Did you mean: 

STM32C01x RTC initialization Timeout error

KenLee
Associate III

I am working on firmware with stm32c011f4u6 mcu. When the program is operated, a timeout error occurs after falling into the infinite loop of the function below.

 

HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)
{
  uint32_t tickstart;
  HAL_StatusTypeDef status = HAL_OK;

  /* Check if the Initialization mode is set */
  if ((hrtc->Instance->ICSR & RTC_ICSR_INITF) == 0U)
  {
    /* Set the Initialization mode */
    SET_BIT(hrtc->Instance->ICSR, RTC_ICSR_INIT);

    tickstart = HAL_GetTick();
    /* Wait till RTC is in INIT state and if Time out is reached exit */
    while (((hrtc->Instance->ICSR & RTC_ICSR_INITF) == 0U) && (status != HAL_TIMEOUT))
    {
      if ((HAL_GetTick()  - tickstart) > RTC_TIMEOUT_VALUE)
      {
        /* New check to avoid false timeout detection in case of preemption */
        if ((hrtc->Instance->ICSR & RTC_ICSR_INITF) == 0U)
        {
          status = HAL_TIMEOUT;

          /* Change RTC state */
          hrtc->State = HAL_RTC_STATE_TIMEOUT;
					
        }
        else
        {
          break;
        }
      }
    }
  }

  return status;
}

 

How do I not fall into the infinite loop above? I'm using the built-in RTC initialization function.

(RTC_EnterinitMode function is contained within the HAL_RTC_Init.)

 
1 ACCEPTED SOLUTION

Accepted Solutions
KenLee
Associate III

I found the cause of the error. HAL_RTC_MspInit was not included in the stm32c0xx_hal_msp.c.

I added a function inside the file and it works well now!

 

View solution in original post

1 REPLY 1
KenLee
Associate III

I found the cause of the error. HAL_RTC_MspInit was not included in the stm32c0xx_hal_msp.c.

I added a function inside the file and it works well now!