cancel
Showing results for 
Search instead for 
Did you mean: 

Wakeup from standby with RTC on STM32C5

Hello,

 

I am using the RTC wakeup from the power standby example provided in the STM32C5 repository. The example starts the RTC wake-up timer and places the device in standby mode. The device does go to standby, and it does wake up due to the RTC wakeup interrupt; however, the RTC initialization fails after wakeup. It is worth mentioning that the only way I can get rid of this error is to power cycle the board.

The failure happens in HAL_RTC_WAKEUP_SetConfig due to RTC_WaitSyncrhroWUTW() returning an error due to  RTC_CR_WUTE being set.

static hal_status_t RTC_WaitSynchro_WUTW(void)
{
  uint32_t tickstart;

  if (LL_RTC_IsActiveFlag_INIT() == 0U)
  {
    if (LL_RTC_WAKEUP_IsEnabled() == 1U)
    {
      return HAL_ERROR; // Code returns this error
    }
    tickstart = HAL_GetTick();

    while (LL_RTC_IsActiveFlag_WUTW() == 0U)
    {
      if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
      {
        if (LL_RTC_IsActiveFlag_WUTW() == 0U)
        {
          return HAL_ERROR;
        }
      }
    }
  }

  return HAL_OK;
}

To make the example work, I had to add a call to HAL_RTC_WAKEUP_Stop() before HAL_RTC_WAKEUP_SetConfig in mx_rtc.c.

  HAL_RTC_WAKEUP_Stop(); // Added line of code
  /* Configure wake-up timer */
  hal_rtc_wakeup_config_t wakeup_config;
  wakeup_config.clock = HAL_RTC_WAKEUP_TIMER_CLOCK_RTCCLK_DIV16;
  if (HAL_RTC_WAKEUP_SetConfig(&wakeup_config) != HAL_OK)
  {
    return SYSTEM_PERIPHERAL_ERROR;
  }

 

This does not seem to be the proper solution. Do you have any suggestions of how to address this issue?

I attached the .io2 file. The project runs on Nucleo-C562RE.

 

Thank you,

-Gil

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

 

For those who experience the problem above, I recommend that you look at the STM32CubeC5/examples/hal/rtc/wakeup_timer_from_standby from the same repository as the other example that I referenced earlier: STM32Cube5/examples/hal/pwr/standby_rtc. The two examples have the same goal of waking up the MCU from standby using the RTC wakeup, but the code is slightly different. The one that works for me without an error upon wakeup is the second example (wakeup_timer_from_standby).

 

Regards,

-Gil

 

 

 

View solution in original post

1 REPLY 1

Hi,

 

For those who experience the problem above, I recommend that you look at the STM32CubeC5/examples/hal/rtc/wakeup_timer_from_standby from the same repository as the other example that I referenced earlier: STM32Cube5/examples/hal/pwr/standby_rtc. The two examples have the same goal of waking up the MCU from standby using the RTC wakeup, but the code is slightly different. The one that works for me without an error upon wakeup is the second example (wakeup_timer_from_standby).

 

Regards,

-Gil