Skip to main content
Visitor II
July 7, 2025
Question

Standby and Shutdown mode in stm32u585 using RTC

  • July 7, 2025
  • 5 replies
  • 739 views

Hi,

  I am on stm32u585 IOT dev board for low power modes am using RTC wakeup the sleep and stop 1,2 and 3 are working fine but standby and shutdown is not working ? my code 

 
void sleep(int mode, int seconds ) {

if (seconds <= 0) return;

 HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);

uint32_t wakeup_counter (uint32_t)(seconds 2048);

 HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, wakeup_counter, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0);




switch (mode) {

case 0: // Sleep

 HAL_SuspendTick();

HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

 HAL_ResumeTick();

break;

case 1: // Stop0

 HAL_SuspendTick();

 HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);

break;

case 2: // Stop1

 HAL_SuspendTick();

 HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

break;

case 3: // Stop2

 HAL_SuspendTick();

 HAL_PWREx_EnterSTOP3Mode(PWR_STOPENTRY_WFI);

break;

case 4: // Standby

 __HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_ALL_FLAG | PWR_FLAG_SBF);

 HAL_PWR_EnterSTANDBYMode();

break;

case 5; // Shutdown/DeepSleep

 __HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_ALL_FLAG | PWR_FLAG_SBF);

 HAL_PWREx_EnterSHUTDOWNMode();

break;

default:

break;

 }

}

void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) {

 HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

 SystemClock_Config();

 HAL_ResumeTick();
}

 

    This topic has been closed for replies.

    5 replies

    Technical Moderator
    July 8, 2025

    Hello @shivss 

    The device cannot enter on standby and shutdown mode or cannot exit? 

    Please refer to the example below: 

    STM32CubeU5/Projects/NUCLEO-U545RE-Q/Examples/PWR/PWR_STANDBY at main · STMicroelectronics/STM32CubeU5 · GitHub

    Note that The RTC remains active when the RTC clock source is LSE or LSI.

    Saket_Om_0-1751971126551.png

     

    shivssAuthor
    Visitor II
    July 8, 2025

    Hi,

    It is not exit from standby and shutdown modes. The example code is using Wakeup pin but want I need is wakeup with RTC .In RTC INIT checking for wakeup same as in example . This code is working for sleep,stop1,2 and 3 the RTC is working fine  with these modes but not for standby or shutdown even UART messages are also not printing after standby or shutdown

    static void MX_RTC_Init(void)
    {
    
     /* USER CODE BEGIN RTC_Init 0 */
    	uart_send("RTC start\r\n");
    	// Check if waking from Standby — if yes, skip full init
    	 if (__HAL_PWR_GET_FLAG(PWR_FLAG_SBF) != RESET)
    	 {
    		 uart_send(">> Woke from STANDBY\r\n");
    	 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SBF); // Clear standby flag
    
    	 HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
    	 }
    
     /* USER CODE END RTC_Init 0 */
    
    void sleep(int mode, int seconds ) {
    
    if (seconds <= 0) return;
    
     HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
    
     __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
    
    uint32_t wakeup_counter (uint32_t)(seconds 2048);
    
     HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, wakeup_counter, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0);
    
    
    
    
    switch (mode) {
    
    case 0: // Sleep
    
     HAL_SuspendTick();
    
    HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
    
     HAL_ResumeTick();
    
    break;
    
    case 1: // Stop0
    
     HAL_SuspendTick();
    
     HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
    
    break;
    
    case 2: // Stop1
    
     HAL_SuspendTick();
    
     HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
    
    break;
    
    case 3: // Stop2
    
     HAL_SuspendTick();
    
     HAL_PWREx_EnterSTOP3Mode(PWR_STOPENTRY_WFI);
    
    break;
    
    case 4: // Standby
    
     __HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_ALL_FLAG | PWR_FLAG_SBF);
    
     HAL_PWR_EnterSTANDBYMode();
    
    break;
    
    case 5; // Shutdown/DeepSleep
    
     __HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_ALL_FLAG | PWR_FLAG_SBF);
    
     HAL_PWREx_EnterSHUTDOWNMode();
    
    break;
    
    default:
    
    break;
    
     }
    
    }
    
    void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) {
    
     HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
    
     SystemClock_Config();
    
     HAL_ResumeTick();
    }

     Screenshot 2025-07-08 182837.png

    ST Employee
    July 8, 2025

    Hello @shivss 

    Could you please ensure that the RTC wake-up timer interrupt is properly configured by adding the following functions ? Once done, kindly let us know if the issue persists:

     /* Enable WakeUp line functionality for the RTC ALARMA */
     HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN7_HIGH_3);
    
     /* Enable the Autonomous Mode for the RTC */
     __HAL_RCC_RTCAPB_CLKAM_ENABLE();

    Best regards,

    Haifa.

    shivssAuthor
    Visitor II
    July 9, 2025

    Hi @Hai 

     
    HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
    
    /*functionality for the RTC ALARMA */
     HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN7_HIGH_3);
    
     /* Enable the Autonomous Mode for the RTC */
     __HAL_RCC_RTCAPB_CLKAM_ENABLE();
    
     __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);/* Enable WakeUp line 

    I have added after the deactivate wakeup timer  then it wakeup one time after then when am trying to send it again back to standby/shutdown then its not even entering into standby/shutdown its getting hang   

    shivssAuthor
    Visitor II
    July 13, 2025

    Hi @Hai 

     Waiting the reply with solution . Thanks

    shivssAuthor
    Visitor II
    July 29, 2025

    HI ,

    any reply ? can you guys give me example code for all sleep ,stop and shutdown and standby ? or any working code

    Technical Moderator
    July 30, 2025
    shivssAuthor
    Visitor II
    July 30, 2025

    HI @Saket_Om 

     

    That is for different board and more over that is not standby or shutdown mode?

    Visitor II
    November 27, 2025

    Hello @shivss 
    Were you able to solve the problem?