cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476 wakeup flag not set when exit from shutdown after JLink removed

Kyle B
Associate II

I have a project that makes use of the two external wakeup pins, and need to know which pin woke up the device. After flashing, with a JLink, the board can enter/exit shutdown, and will set the correct wakeup flag in the PWR_SR1 register.

If I power cycle the board, and allow it to run and enter shutdown again, it wakes up on the correct pins but the wakeup flags are not set. The SR1 register is cleared.

There must be something needed to do before entering shutdown, or on reset that I'm missing. Below is what is done before shutdown, and after wakeup (With just one wakeup pin for example):

 /* Going into shutdown */
__HAL_RCC_PWR_CLK_ENABLE();
 HAL_PWR_EnableBkUpAccess();
 
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
 
HAL_PWREx_EnterSHUTDOWNMode();
 
/* After reset, in main (After clock setup) */
PWR->SR1 // This is 0 when after wakeup from shutdown

13 REPLIES 13
MSatt.4
Associate III

Did anyone end up figuring this out?

Similar thing happening on a STM32WB55CG...

When the flag DBGMCU->CR.DBG_STANDBY is set, the WUFx flag is set upon wake up from shutdown mode correctly. Turning this DBG_STANDBY flag off, it no longer works and all the wakeup flags appear cleared.

Note the default debug configuration generated by STM32CubeIDE had set to allow debugging from sleep modes (Debug configuration properties -> Debugger tab -> "Debug in low power modes" = Enable), which is why the DBG_STANDBY was set - turning this option to "No configuration" and power cycling the device cleared this flag by default for me. I'd guess that's why the OP saw this behavior.

Using standby mode instead of shutdown mode also works... maybe shutdown mode just isn't supported :(

I guess the workaround is just to sample the pin upon wakeup - not perfect but good enough for us anyway.

I came across the same problem as @MSatt.4​  and I also needed to set the DBG_STANDBY bit on a STM32G484QE. This took be by surprise, as I've implemented standby on other processor families (F4xx and L4xx) without issue. I got a working example on an eval kit, then spent a day doing some 'divide and conquer debugging' on my real hardware. I found that my issue had to do with the fact that my board derived the PLL from the HSE in bypass mode. When I called HAL_RCC_DeInit before going to shutdown, I found that I could wake from shutdown without using the DBG_STANDBY bit (definitely preferable so we can turn off HCLK/FCLK).

All I can do is theorycraft at this point. I know that the core uses FCLK to sample interrupts for the WFI instruction. When in shutdown, it should use the wakeup interrupt controller (WIC), which should not require a clock to wake. However, perhaps upon seeing the wake event, it tries to start the clock but fails because of the HSE in bypass (HSE with crystal seems to work) in some arrangement that is unique to the the Gxx series (and possibly the WB series based on your description; I've never used that family).

You are saying that you have the same problem, but then are describing a different problem. This topic talks about WUFx flags not being set at wake-up, not about the MCU not waking up.

Take a note that setting DBG_STANDBY bit has a significant consequences, about which you can read in the section 3 of the following topic:

https://community.st.com/s/question/0D53W00001bnh8dSAA/how-to-enter-standby-or-shutdown-mode-on-stm32

Also the idea about clocks is almost certainly not true, because after reset your MCU sets the HSI16 oscillator without PLL as a system clock. To me it sounds like the HAL/Cube broken bloatware startup code is failing in your case.