2025-07-16 12:29 AM
My simple program to test wake from standby with PC13/Wakeup_pin4 is working. I use the pushbutton on this pin as an EXTI and had to add the GPIO_DeInit before setting the pin as an input without EXTI.
The same code does not work in my larger program and I can't work out why??
printf("0 - sleep until button pressed\r\n");
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_13);
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4);
PWR->WKUPCR = 0x3F; // Clear all wakeup flags (write 1 to clear)
PWREx_WakeupPinTypeDef sPinParams = {
.WakeUpPin = PWR_WAKEUP_PIN4,
.PinPolarity = PWR_PIN_POLARITY_HIGH,
.PinPull = PWR_PIN_NO_PULL
};
HAL_PWREx_EnableWakeUpPin(&sPinParams);
HAL_Delay(10);
HAL_TIM_Base_Stop_IT(&htim6);
HAL_SuspendTick();
BlinkOff();
HAL_PWR_EnterSTANDBYMode();
2025-07-16 2:43 AM
Hello @Ian_CP,
The most likely reason is wakeup pin configuration conflict, the pin PC13 is being used as an EXTI, enabled in another part of the program, it is interfering with the wakeup functionality.
This is the recommended sequence to follow
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.
2025-07-18 7:38 PM
You can configure PC13 either as a regular GPIO_input or GPIO_EXTI13. That way you can still read the pin state and/or get an EXTI interrupt.
So if you want, you can use the button to put the STM32 in Standby mode and wake it up without modifying the GPIO pin during the different stages.
If you configure PC13 as PWR_WKUP4, then you can't read the pin state.
This is all you really need.
void EnterStandbyMode(void)
{
__HAL_PWR_CLEAR_WAKEUPFLAG(PWR_FLAG_WKUP4); // PWR_FLAG_WKUP4
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4_HIGH); // PWR_WAKEUP_PIN4_HIGH
HAL_PWR_EnterSTANDBYMode();
// only for STM32 that Wake up in HSI mode, but you need HSE mode.
//RunClockConfig(); // calls SystemClock_Config(),
}
The datasheet says only these triggers can wake up from Standby. So there is no need to disable a basic Timer or SysTick.
2025-07-18 9:17 PM
Sarra
I think that is exactly what my code above is doing, isn't it???
My code above is working but it does not work when I add it to my bigger program.
How do I make it work in my bigger program?
2025-07-18 9:22 PM
Karl
I tried your code and it doesn't work. Did you test it?
My code works as a small test program but does not work in my larger program and I don't know why.
The section of the datasheet that you have highlighted does not mention wake on pin change from Standby is possible except for pins enabled for WKUP??
2025-07-18 10:16 PM
Yes, I've tested on a Nucleo-H723ZG. I've set PC13 as a regular input or EXTI and they both wake up from Standby. I can also read the pin at anytime during run time.
If i configure for SYS_WKUP, it still wakes up, but you can't read the pin correctly. It just reads as being low even though pressing the button pulls it high.
I've been doing it like this for a STM32G071RB though this one has Sleep and Shutdown modes along with Sleep and Standby. But all 4 modes still wake up with an falling edge on PC13.
So somewhere else in your code, you must be changing your PC13 pin configuration?