STM32L4 Wakeup source never detectable after power cycle
Hello everybody,
i am having trouble determining the wakeup source after power cycling and i can not figure out why this is.
Simple test case:
I am using the NUCLEO-L496ZG->Examples->PWR->PWR_SHUTDOWN example as a base.
The example was slightly modified to produce serial output of the pwr status register and "out of shutdown" information.
int main(void)
{
HAL_Init();
/* Configure the system clock to 80 MHz */
SystemClock_Config();
/* Enable Power Clock */
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
/* Read PWR status register to determine wakeup source */
printf("PWR->SR1: 0x%08X\n", PWR->SR1);
printf("PWR->SR2: 0x%08X\n", PWR->SR2);
/* Check if the system was resumed from shutdown mode,
resort to RTC back-up register RTC_BKP31R to verify
whether or not shutdown entry flag was set by software
before entering shutdown mode. */
if (READ_REG(RTC->BKP31R) == 1)
{
WRITE_REG( RTC->BKP31R, 0x0 ); /* reset back-up register */
printf("OUT OF SHUTDOWN\n");
}
/* Insert 5 seconds delay */
HAL_Delay(5000);
/* Disable all used wakeup sources: WKUP pin */
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN3);
/* Clear wake up Flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF3);
/* Enable wakeup pin WKUP2 */
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN3_HIGH);
/* Set RTC back-up register RTC_BKP31R to indicate
later on that system has entered shutdown mode */
WRITE_REG( RTC->BKP31R, 0x1 );
/* Read PWR status register to see if wakeup source was reset */
printf("PWR->SR1: 0x%08X\n", PWR->SR1);
printf("PWR->SR2: 0x%08X\n", PWR->SR2);
/* Enter shutdown mode */
HAL_PWREx_EnterSHUTDOWNMode();
while (1)
{
}
}The behavior i experience:
Flash the device -> Run:
Produces:
PWR->SR1: 0x00000000
PWR->SR2: 0x00000100
PWR->SR1: 0x00000000
PWR->SR2: 0x00000100Which has to be expected since the wakeup pin was just configured before shutting down.
Trigger wakeup pin 3 -> RUN:
Produces:
PWR->SR1: 0x00000104
PWR->SR2: 0x00000100
OUT OF SHUTDOWN
PWR->SR1: 0x00000100
PWR->SR2: 0x00000100Which also gives the expected result. PWR->SR1 WUF3 is set and gets reset after pin configuration. Out of shutdown is detected also correctly.
Now assume the device looses power (i simply disconnect it from its power source for a few seconds).
Power device -> RUN:
Produces:
PWR->SR1: 0x00000000
PWR->SR2: 0x00000100
OUT OF SHUTDOWN
PWR->SR1: 0x00000000
PWR->SR2: 0x00000100Still as i would expect. No external wakeup and PWR->SR1 SBF cleared by the power reset.
Again Trigger wakeup pin 3 -> RUN:
Produces:
PWR->SR1: 0x00000000
PWR->SR2: 0x00000100
OUT OF SHUTDOWN
PWR->SR1: 0x00000000
PWR->SR2: 0x00000100The same output as directly after the power reset but from shutdown. Here i would expect the output generated earlier with PWR->SR1 SBF and WUF3 flags set.
I wonder if i must clear or reset any registers after power reset? It is not clear to me if i manually need to reset PWR->SCR CSBF since it seems related to the behavior?
Any guidance to the appropriate resource or explanation of this behavor would be highly appreciated.
Best Regards
