cancel
Showing results for 
Search instead for 
Did you mean: 

Init RTC failed - timeout error - stm32wb10cc

aviel
Associate II

hi,

I configure my micro to work on internal clock by cubemx - this is the clock configure:

//#############################################################################################################
//                 Init Device:  System Clock Configuration
//#############################################################################################################
static  void IDM_Config_System_Clock(void)
{
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

    /** Initializes the RCC Oscillators according to the specified parameters
    * in the RCC_OscInitTypeDef structure.
    */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI1;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.LSIState = RCC_LSI_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    {
      Error_Handler();
    }

    /** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
    */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK4|RCC_CLOCKTYPE_HCLK2
                                |RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.AHBCLK2Divider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
    {
      Error_Handler();
    }
}

and this is the RTC init function:

static void IDM_RTC_Init(void)
{
  RTC_Object.Instance = RTC;
  RTC_Object.Init.HourFormat = RTC_HOURFORMAT_24;
  RTC_Object.Init.AsynchPrediv = 127;
  RTC_Object.Init.SynchPrediv = 255;
  RTC_Object.Init.OutPut = RTC_OUTPUT_DISABLE;
  RTC_Object.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RTC_Object.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
   if (HAL_RTC_Init(&RTC_Object) != HAL_OK)
   {
     Error_Handler();
   }
}
but rtc  init is failed, its occured on 

RTC_EnterInitMode() function

 

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)

{

I RECEIVED THE TIMEOUT ERROR HERE:

return HAL_TIMEOUT;

}

}

}

 

return HAL_OK;

}

 

I tried everything without success :(

Can anyone help me to understand where the problem is?

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

Hello @aviel

Try adding HAL_PWR_EnableBkUpAccess() after SystemClock_Config()

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Sarra.S
ST Employee

Hello @aviel

Try adding HAL_PWR_EnableBkUpAccess() after SystemClock_Config()

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Sarra,

thank you!
at now its work for me!

for better understanding why need to add this function?