Skip to main content
Visitor II
May 3, 2024
Solved

STM32C01x RTC initialization Timeout error

  • May 3, 2024
  • 1 reply
  • 1228 views

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.)

 
    This topic has been closed for replies.
    Best answer by KenLee

    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!

     

    1 reply

    KenLeeAuthorAnswer
    Visitor II
    May 3, 2024

    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!