cancel
Showing results for 
Search instead for 
Did you mean: 

STM32wl series: Wakeup call with rtc

Mahe11
Associate II

Hi.

I'm implementing a wakeup call using the STM32WLxx series and an RTC. However, when I use this, the device enters standby mode but upon wakeup, the code completely resets and runs from the beginning. It seems like the main function is running without any issues. Please let me know if there are any mistakes in my code.

 

 

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_RTC_Init();
  
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 61475, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0);
 
while (1) {
 
HAL_SuspendTick();
HAL_PWR_EnterSTANDBYMode();
 
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
HAL_ResumeTick();
}
  
}
7 REPLIES 7
KDJEM.1
ST Employee

Hello @Mahe11 and welcome to STCommunity 🙂,

It is mentioned in RM0461 and RM0453 that "All registers are reset after wake-up from Standby except for PWR extended status and status clear register (PWR_EXTSCR)"

An PWR_STANDBY_RTC example is available in STM32CubeWL, I advise you to check your code based on this example.

I hope this answer your request and thank you for your contribution.

Kaouthar

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.

I tried your example code, but after waking up, the controller gets reset, which means it starts executing from the beginning. What I want is for the controller to execute only the main loop (while) after waking up. Is that possible? If so, please share any examples.

 

KDJEM.1
ST Employee

Hello @Mahe11,

I think you want to enter standby mode and then the RTC wakes up the STM32 , after that execution goes to the RTC to clear some RTC flags and then goes back to main to continue code execution.

To do that, I recommend you, How to configure the RTC to wake up the STM32 periodically from Low Power modes FAQ

Does this answer your request?

Thank you.

Kaouthar

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.

Thanks, but I've tried this example code first, and I couldn't achieve what I need. As I mentioned, my MCU is getting reset (executing from the header file) after waking up. I don't know what I'm missing. Can you tell me which flag I can modify or use?

KDJEM.1
ST Employee

Hi @Mahe11 ,

I made some tests using Nucleo-WL55JC1 and STM32CubeIDE1.13.2 and I didn't find any issue (executing code from the main) 

After generating code, I just added these lines of code to the main.c as mentioned in the FAQ

 

while (1)
  {
    /* USER CODE END WHILE */
      HAL_SuspendTick();
      HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 61475, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0);
      /* Enter standby mode */
      HAL_PWR_EnterSTANDBYMode();
      HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
      SystemClock_Config();
      HAL_ResumeTick();
 /* USER CODE BEGIN 3 */
  }

 

If the issue still persisting, could you please share your project?

Thank you.

Kaouthar 

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.

Sure sir. I have attached the project as link below. I just add the variable a ,b to check the value incrementing in the wakeup call but it always printing 1 only it doesn't increment after wakeup for every 10 seconds. Its like reset (executing from the header file). i just want to execute only while loop after wakeup call. Please check and let me know is there any mistake in my project. Thanks     

 

https://drive.google.com/drive/folders/1VJvdHQkz01ASXwWPrPzsSp1sGW9Dxq8M?usp=sharing

"After waking up from Standby or Shutdown mode, the program execution restarts in the same way as after a reset (boot pin sampling, option bytes loading, reset vector is fetched)."

 

I didn't find any issue (executing code from the main) 

So did the MCU entered the Standby mode and proved that your "continue after wake-up" code is nonsense? Or it didn't actually enter the Standby mode, because the code is broken? Which one was it?

This is how you enter the Standby mode: https://community.st.com/t5/stm32-mcus-embedded-software/how-to-enter-standby-or-shutdown-mode-on-stm32/m-p/145849

This is how you set up the RTC wake-up: https://community.st.com/t5/stm32-mcus-embedded-software/clearing-the-rtc-wutf-saving-your-sanity-by-sharing-my-hard/m-p/200677

These are correct examples.