Skip to main content
Graduate II
February 28, 2025
Question

STM32G0 Stop 1 with wake on event

  • February 28, 2025
  • 6 replies
  • 828 views

I'm trying to do something that seems simple if you go a search. I want the module to sleep. Then I will wake it with voltage on pin B6. I don't want an interrupt. Just an event. People mix event and interrupt so much and all the examples I see are based on interrupt so its nearly impossible to find any that actually are about events.

From what I can see it should be very simple. But my module does not sleep. It wakes immediately.

hack of my sleep code

 

{
GPIO_InitTypeDef GPIO_InitStruct = {0};
adcDeInit();
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; /* Configures: EXTI_EXTICRx, RTSR1, FTSR1, EMR1, IMR1*/
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);
}

 

From what I have read the module should be in STOP1 mode now. But what I see is it just enters and immediately exits. I don't see any flags set in RPR1 or FPR1. Should I?

Note: This module has UCPD and UART and other clocks that I have not turned off. EMR1 = 0x40; IMR1 = 0xFFFC0000; but interrupt should not wake the MCU only event right?

 

 

    This topic has been closed for replies.

    6 replies

    Carl_GAuthor
    Graduate II
    February 28, 2025

    adding __disable_irq(); at the start makes it work. But IRQ are not supposed to wake the MCU from WFE!?

    Super User
    February 28, 2025

    Is SEVONPEND=0?

    Carl_GAuthor
    Graduate II
    February 28, 2025

    Yes

    Carl_G_0-1740772840323.png

     

    Carl_GAuthor
    Graduate II
    February 28, 2025

    PWM output based on TIM2 is still active so I guess that means the MPU isn't really getting into STOP mode. Maybe the debug in stop mode feature is conspiring with TIM to keep the MPU somewhat awake. I thought TIM would stop on its own, but it seems not. Without the debugger the same behavior. TIM is still going.

    Further testing. TIM is running 4x slower. I think that means the PLL is off but HSI16 is still there. RM says some peripherals can enable HSI16 during stop mode. It seems that is what is happening. System clock is HSI16 as per RM.

    Carl_GAuthor
    Graduate II
    February 28, 2025

    And now its working. No discernable changes. Just works as expected. Not even disabling interrupts. Sleeps then wakes on GPIO... It keeps saying "debug in low power mode" even on just a program, but I think that is a bug because it does not behave as if that feature is still on since debugger will disconnect.

    Carl_GAuthor
    Graduate II
    March 2, 2025

    I've coded more now and have another point of confusion. It wakes even with no events. I have set EXTI_EMR1 = 0; and EXTI_EMR2=0. Then sleep with WFE. Yet it still wakes when my COMP triggers or my UCPD triggers. I don't get it.

    Carl_GAuthor
    Graduate II
    March 3, 2025

    WFE wakes on event or interrupt. WFI is interrupt only.