STM32L476 wakeup flag not set when exit from shutdown after JLink removed
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