Skip to main content
JKaz.1
Associate III
September 14, 2026
Solved

Issues exiting Shutdown mode on STM32G0B1CEU using WKUP pin

  • September 14, 2026
  • 3 replies
  • 65 views

I am attempting to exist from a Shutdown mode using the WKUP6 pin (PB5) on an STM32G0B1CEU.

This is my shutdown code.

HAL_SuspendTick();
__HAL_RCC_PWR_CLK_ENABLE();


HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_5);
HAL_PWREx_EnablePullUpPullDownConfig(); // sets the APC bit in PWR_CR3
HAL_PWREx_EnablePORMonitorSampling();

HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN6_LOW);

// Do reads of registers to ensure they were written
(void)PWR->CR3;
(void)PWR->CR4;

/* Clear all related wakeup flags*/
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);

HAL_PWREx_EnterSHUTDOWNMode();

This seems to do almost exactly what I would expect it to do.
PB5 goes high.
Power consumption drops.

However, it never wakes up.  I have a wire connected to PB5, which I am measuring with a scope, and confirm that it is going high.  I am them shorting that wire to ground and confirm that it goes low.  The system doesn’t wake up. 

I know it’s not immediately going back to sleep because right now there is no automated way for it to enter sleep mode, I have to send it a serial command over USB.

 

I’ve searched the forums, messed around with swapping the polarity of the wakeup and using an external power supply to drive it to 3.3V, and double checked the errata...  I can’t get it to wake up from WKUP6.  What am I missing?

Best answer by JKaz.1

Thanks for putting this together… but this is pretty much just one of the examples from the G0 Software Framework, which I have already referenced.  As far a I can tell, I’m already doing everything in this example, so I don’t know why it’s not working.

 

However, it doesn’t matter.  I made my own shutdown mode!  I manually turn off every clock I could find, disable the HSI48 and LSI manually, divide my HSI by 128 and then enter low power sleep mode.  When I test that code against going into Shutdown mode, power consumption is approximately 1uA more, except I can wake up from standard EXTI interrupts and don’t have to rely purely on WKUP pins.

 

For anyone who stumbles across this and wants to get super low power, but wake up from EXTI interrupts (or events, I’m using events), here’s how to turn everything.  (Note, depending on your chip and what you have initialized, your mileage may vary).

 

instance()->m_pUsbUtils->stop();   // This de-inits the USB code

HAL_SuspendTick();

HAL_ADC_Stop_DMA(&hadc1);
HAL_ADC_Stop_IT(&hadc1);

HAL_ADC_DeInit(&hadc1);
HAL_I2C_DeInit(&hi2c1);
HAL_I2C_DeInit(&hi2c2);
HAL_TIM_Base_MspDeInit(&htim2);
HAL_CRC_MspDeInit(&hcrc);

HAL_PWR_DisableBkUpAccess();
HAL_RTC_MspDeInit(&hrtc);
HAL_PWR_DisableSEVOnPend();

LL_UCPD_SetccEnable(UCPD1, LL_UCPD_CCENABLE_NONE);
LL_UCPD_TypeCDetectionCC1Disable(UCPD1);
LL_UCPD_TypeCDetectionCC2Disable(UCPD1);
LL_UCPD_RxDisable(UCPD1);
LL_UCPD_RxDMADisable(UCPD1);

LL_UCPD_Disable(UCPD1);
LL_UCPD_ForceClockDisable(UCPD1);
HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE);

// Disable ALL PINS
utl::STM32::ConfigureAnalog(GPIOA, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOB, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOC, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOD, GPIO_PIN_All);

// Configure wakeup source
GPIO_InitTypeDef GPIO_InitStruct = {};
GPIO_InitStruct.Pin = nDisplay_Button_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_EVT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(nDisplay_Button_GPIO_Port, &GPIO_InitStruct);

// Disable lots of clocks
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_ALL);
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_ALL);

LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_CRC);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_DMA1);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_DMA2);

LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOC);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOD);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOF);

LL_AHB1_GRP1_DisableClockStopSleep(LL_AHB1_GRP1_PERIPH_ALL);

HAL_PWREx_EnablePORMonitorSampling();
HAL_PWREx_DisableInternalWakeUpLine();
HAL_PWREx_DisableSRAMRetention();
HAL_PWREx_DisablePVD();
HAL_PWREx_DisablePVMUSB();
HAL_PWREx_DisableVddUSB();
HAL_PWREx_DisableVddIO2();

__HAL_RCC_SYSCFG_CLK_DISABLE();
__HAL_RCC_PWR_CLK_DISABLE();
__HAL_RCC_RTCAPB_CLK_DISABLE();
__HAL_RCC_HSI48_DISABLE();
__HAL_RCC_LSI_DISABLE();

LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_SRAM);

// Drop system clock speed
__HAL_RCC_HSI_CONFIG(RCC_HSI_DIV128);
SystemCoreClock = (HSI_VALUE / (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV)) >> RCC_CR_HSIDIV_Pos)));

HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFE);

HAL_NVIC_SystemReset();

 

3 replies

JKaz.1
JKaz.1Author
Associate III
September 14, 2026

Update:  So I can’t even seem to wake up from Stop mode, the only mode I can wake up from is Sleep mode.  I can’t figure out why this isn’t working.  During normal run time PB5 is configured as an EXTI interrupt and that works, so I know the pin is like, at least kind of working.

 

Since I can’t seem to get the deeper sleeps to work, I have instead decided to see if I could manually kill as many things as possible to try and get Sleep mode’s power draw as low as possible.  I’ve gotten it with 500uA of Shutdown mode but I’m not sure what else I could be missing (besides BOR, still trying to figure out how to disable that).

USBD_Stop(m_pDevice);
USBD_DeInit(m_pDevice);

HAL_SuspendTick();

HAL_ADC_Stop_DMA(&hadc1);
HAL_ADC_Stop_IT(&hadc1);

HAL_ADC_DeInit(&hadc1);
HAL_I2C_DeInit(&hi2c1);
HAL_I2C_DeInit(&hi2c2);
HAL_TIM_Base_MspDeInit(&htim2);
HAL_CRC_MspDeInit(&hcrc);

HAL_PWR_DisableBkUpAccess();
HAL_RTC_MspDeInit(&hrtc);
HAL_PWR_DisableSEVOnPend();

LL_UCPD_TypeCDetectionCC1Disable(UCPD1);
LL_UCPD_TypeCDetectionCC2Disable(UCPD1);
LL_UCPD_RxDisable(UCPD1);
LL_UCPD_RxDMADisable(UCPD1);

LL_UCPD_Disable(UCPD1);
LL_UCPD_ForceClockDisable(UCPD1);
HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE);

// Disable ALL PINS
utl::STM32::ConfigureAnalog(GPIOA, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOB, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOC, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOD, GPIO_PIN_All);

// Disable lots of clocks
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_ALL);
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_ALL);

LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_CRC);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_DMA1);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_DMA2);

LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOC);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOD);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOF);

LL_AHB1_GRP1_DisableClockStopSleep(LL_AHB1_GRP1_PERIPH_ALL);

HAL_PWREx_EnablePORMonitorSampling();
HAL_PWREx_DisableInternalWakeUpLine();
HAL_PWREx_DisableSRAMRetention();
HAL_PWREx_DisablePVD();
HAL_PWREx_DisablePVMUSB();
HAL_PWREx_DisableVddUSB();
HAL_PWREx_DisableVddIO2();

__HAL_RCC_SYSCFG_CLK_DISABLE();
__HAL_RCC_PWR_CLK_DISABLE();


GPIO_InitTypeDef GPIO_InitStruct = { };
GPIO_InitStruct.Pin = nDisplay_Button_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_EVT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(nDisplay_Button_GPIO_Port, &GPIO_InitStruct);

LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_SRAM);

HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFE);

 

ST Technical Moderator
September 15, 2026

Hello ​@JKaz.1 

Here is an example that I have created that makes the (MCU)enter shutdown mode automatically after a few seconds and wake up by using wake-up pin 2.

The example achieves current consumption below 1 µA.

It can be used as a reference or modified as needed.
BR
Gyessine

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
JKaz.1
JKaz.1AuthorBest answer
Associate III
September 15, 2026

Thanks for putting this together… but this is pretty much just one of the examples from the G0 Software Framework, which I have already referenced.  As far a I can tell, I’m already doing everything in this example, so I don’t know why it’s not working.

 

However, it doesn’t matter.  I made my own shutdown mode!  I manually turn off every clock I could find, disable the HSI48 and LSI manually, divide my HSI by 128 and then enter low power sleep mode.  When I test that code against going into Shutdown mode, power consumption is approximately 1uA more, except I can wake up from standard EXTI interrupts and don’t have to rely purely on WKUP pins.

 

For anyone who stumbles across this and wants to get super low power, but wake up from EXTI interrupts (or events, I’m using events), here’s how to turn everything.  (Note, depending on your chip and what you have initialized, your mileage may vary).

 

instance()->m_pUsbUtils->stop();   // This de-inits the USB code

HAL_SuspendTick();

HAL_ADC_Stop_DMA(&hadc1);
HAL_ADC_Stop_IT(&hadc1);

HAL_ADC_DeInit(&hadc1);
HAL_I2C_DeInit(&hi2c1);
HAL_I2C_DeInit(&hi2c2);
HAL_TIM_Base_MspDeInit(&htim2);
HAL_CRC_MspDeInit(&hcrc);

HAL_PWR_DisableBkUpAccess();
HAL_RTC_MspDeInit(&hrtc);
HAL_PWR_DisableSEVOnPend();

LL_UCPD_SetccEnable(UCPD1, LL_UCPD_CCENABLE_NONE);
LL_UCPD_TypeCDetectionCC1Disable(UCPD1);
LL_UCPD_TypeCDetectionCC2Disable(UCPD1);
LL_UCPD_RxDisable(UCPD1);
LL_UCPD_RxDMADisable(UCPD1);

LL_UCPD_Disable(UCPD1);
LL_UCPD_ForceClockDisable(UCPD1);
HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE);

// Disable ALL PINS
utl::STM32::ConfigureAnalog(GPIOA, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOB, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOC, GPIO_PIN_All);
utl::STM32::ConfigureAnalog(GPIOD, GPIO_PIN_All);

// Configure wakeup source
GPIO_InitTypeDef GPIO_InitStruct = {};
GPIO_InitStruct.Pin = nDisplay_Button_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_EVT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(nDisplay_Button_GPIO_Port, &GPIO_InitStruct);

// Disable lots of clocks
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_ALL);
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_ALL);

LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_CRC);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_DMA1);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_DMA2);

LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOC);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOD);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOF);

LL_AHB1_GRP1_DisableClockStopSleep(LL_AHB1_GRP1_PERIPH_ALL);

HAL_PWREx_EnablePORMonitorSampling();
HAL_PWREx_DisableInternalWakeUpLine();
HAL_PWREx_DisableSRAMRetention();
HAL_PWREx_DisablePVD();
HAL_PWREx_DisablePVMUSB();
HAL_PWREx_DisableVddUSB();
HAL_PWREx_DisableVddIO2();

__HAL_RCC_SYSCFG_CLK_DISABLE();
__HAL_RCC_PWR_CLK_DISABLE();
__HAL_RCC_RTCAPB_CLK_DISABLE();
__HAL_RCC_HSI48_DISABLE();
__HAL_RCC_LSI_DISABLE();

LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_SRAM);

// Drop system clock speed
__HAL_RCC_HSI_CONFIG(RCC_HSI_DIV128);
SystemCoreClock = (HSI_VALUE / (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV)) >> RCC_CR_HSIDIV_Pos)));

HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFE);

HAL_NVIC_SystemReset();