cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB05TZ fails MX_RTC_Init()

DG_NC
Associate

I have a problem with the RTC initialization on the STM32WB05TZF6TR (BGA package).  When the board is powered on, the MX_RTC_Init() function calls HAL_RTC_Init(), which returns with HAL_ERROR status.

I traced the problem to the stm32wb0x_hal_rtc.c file, inside RTC_EnterInitMode().  It attempts to set the INIT bit, and then waits until the INITF bit changes state to confirm that Initialization Mode has been entered.

However, the INITF bit never changes state, so the while loop times out. 

On my custom board, I have confirmed that this error always occurs when power is applied to the board, but if I manually reset the MCU while power is already applied (by shorting RESET to GND momentarily), then the initialization will complete successfully.

To eliminate anything specific to my board, I generated a very simple test project (attached), which uses the default clock configuration with internal oscillators only, for both High Speed and Low Speed clocks.  The ONLY configuration in the attached project is enabling a single GPIO for debugging output and enabling the RTC peripheral.

Are other people seeing this same problem?

If you flash your board with the attached example project, PB5 will toggle if the RTC initializes successfully, and PB5 will just remain high forever if the RTC initialization times out.  On my board, PB5 is connected to an LED so I can see it blink or illuminate.

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

  /* Check that Initialization mode is not already set */
  if (READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U)
  {
    /* Set INIT bit to enter Initialization mode */
    SET_BIT(hrtc->Instance->ISR, RTC_ISR_INIT);

    /* Get tick */
    tickstart = HAL_GetTick();

    /* Wait till RTC is in INIT state and if timeout is reached exit */
    while ((READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U) && (status != HAL_ERROR))
    {
      if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
      {
        /*** Timeout occurs and this causes the function to exit with HAL_ERROR status ***/
        /* Set RTC state */
        hrtc->State = HAL_RTC_STATE_ERROR;
        status = HAL_ERROR;
      }
    }
  }

  return status;
}

 

0 REPLIES 0