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
Mohamed Aymen HZAMI
ST Employee

Hello,

the wake up from shutdown mode generate a system reset and all instructions after HAL_PWREx_EnterSHUTDOWNMode() function are not executed, to see the flag is set or not you need to read it before entering shutdown mode.

Try this sequence :

/* Going into shutdown */
__HAL_RCC_PWR_CLK_ENABLE();
 HAL_PWR_EnableBkUpAccess();
 /* Read Flag register */
PWR->SR1
  
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
 
HAL_PWREx_EnterSHUTDOWNMode();

Best Regards,

Mohamed Aymen.

Kyle B
Associate II

Thanks for your quick response!

The documentation indicates that ths PWR_SR1 register is not reset when exiting standby modes. I incorrectly assumed this included shutdown mode.

In the case of shutdown then, is there any method to determine the source of wakeup?

Thanks,

Kyle

Mohamed Aymen HZAMI
ST Employee

Hello,

What I mean is the wake-up from shutdown generate a system reset ( for more details you can refer to section 5.3.10 ), but the PWR_SR1 register is not reset.

Before clearing the Flag using this function __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2) try to read the PWR_SR1 register to determine the source of wake-up, after that you can clear all the flags for the next read.

Best Regards,

Mohamed Aymen.

Kyle B
Associate II

Ok great,

So I guess that brings me back to my original question. I am reading PWR_SR1 after wakeup from shutdown (system reset), but before clearing the flag, as you describe.

When I have a JLInk connected, the PWR_SR1 register contains the correct source of wakeup after shutdown. If not, it only ever reads 0.

Is there anything else that I need to configure either for reading the register on wakeup, or entering shutdown to allow the PWR_SR1 register to maintain its value?

Thanks,

Kyle

andrelongo85
Associate II

Hi There,

I have exactly the same issue. PWR_SR1 is set properly with the debug connect, but not when disconnected.

When I exit shutdown mode I always see the register at 0!

Did anyone solved this issue?

JSeyd
Associate

Hello,

I have the exact same issue with a STM32L431RCT6 and using a ST-LINK V2 debugger.

I saw that in their Cube examples, ST uses the RTC backup register BKP31R to store a value prior entering shutdown and read back this register after system reset. Maybe is this example linked to a misbehavior of the STM32L (PWR-SR1 not retained after power-on reset)?

ST team, can you please give us some feedback about this issue?

Thank you in advance.

Regards

SimonF
Senior

Hello,

As indicated in the reference manual RM035 (STM32L47xxx/STM32L48xxx/STM32L49xxx/STM32L4Axxx family), you should be able to read the power source with PWR_SR1 if you are either in Shutdown or in Standby mode : "This register is not reset when exiting Standby or Shutdown".

In the reference manual RM0394 (STM32L41xxx/42xxx/43xxx/44xxx/45xxx/46xxx family), you can read the power source after exiting Standby Mode but not from Shutdown Mode : "This register is not reset when exiting Standby modes". Thus it is reset in Shutdown.

To sum up, @Kyle B​ either there is a missing mention of Shutdown mode resetting the register in the RM035 or you are missing something.

And for @JSeyd​, MCUs like "stm32L43xxx" reset the register so you cannot use it. You need to find another solution or a workaround.

Check your MCU first and then the reference manual.

Simon

doerk
Associate

I discovered the same issue on a STM32L476RG.

In debugging state I am able to read the SR1 after getting out of shutdown mode. But I also discovered there won't be a BOR applied.

Without debug probe I see a BOR after waking up from shutdown mode. But the SR1 (and other registers too) is in reset state.

Could please someone from ST reproduce this issue or tell me what's going wrong?

Best regards

Dirk

JStri.1
Associate

@JSeyd​ I use the RTC registers successfully across a MCU shutdown/wakeup. But this is not a solution for what @Kyle B​ mentioned. For me the PWR->SR1 registers are always resetted after waking up from a configured wakeup source. RM0394 does tell us SR1 wouldn't be reset after a power up reset (that a shutdown does when waked up). So this seems to be a hardware errata at least on an STM32L4xx.