2024-05-02 07:01 PM
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.)
Solved! Go to Solution.
2024-05-03 02:27 AM
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!
2024-05-03 02:27 AM
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!