Skip to main content
ZXiao.1
Associate II
May 20, 2021
Question

It always work ok for RTC. But sometimes HAL_RTC_MspInit retrun me HAL_TIMEOUT, which case would cause this error? I did not change my hardware and firmware for RTC, I use the internal clock for rtc.

  • May 20, 2021
  • 3 replies
  • 1185 views

It will occur @here:

/** @addtogroup RTC_Private_Functions

 * @{

 */

/**

 * @brief Enter the RTC Initialization mode.

 * @note  The RTC Initialization mode is write protected, use the

 *     __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.

 * @param hrtc RTC handle

 * @retval HAL status

 */

HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)

{

 uint32_t tickstart;

 /* Check if the Initialization mode is set */

 if ((hrtc->Instance->ISR & RTC_ISR_INITF) == 0U)

 {

  /* Set the Initialization mode */

  hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;

  tickstart = HAL_GetTick();

  /* Wait till RTC is in INIT state and if Time out is reached exit */

  while ((hrtc->Instance->ISR & RTC_ISR_INITF) == 0U)

  {

   if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)

   {

    return HAL_TIMEOUT;

   }

  }

 }

 return HAL_OK;

}

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
May 20, 2021

> I use the internal clock for rtc.

Do you mean LSI?

When the timeout happens, read out the RCC registers and check if that clock is running, and check if it is selected as RTC clock in RCC_BDCR.

JW

ZXiao.1
ZXiao.1Author
Associate II
May 20, 2021

yes, i use LSI RC clock, when I debug again, it will not occur this error. i will focus on what you mean when it happen again. ​

waclawek.jan
Super User
May 20, 2021

After calling the function which returns the error, write a piece of program which checks for that error, and if the error happens, read out and store into an array in RAM the values of RCC registers. Then output these through your usual debugging method (look at it in debugger, send it to PC using UART, whatever you are normally using), and check the bits which are related to LSI and RTC.

You can do this also for the "working" state and then you can simply compare those two cases.

JW

ZXiao.1
ZXiao.1Author
Associate II
May 20, 2021

ok, thanks a lot. you mean read the RCC registers can know what happened now about the RTC clock?