2025-02-28 9:14 AM - edited 2025-02-28 10:58 AM
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?
2025-02-28 11:20 AM
adding __disable_irq(); at the start makes it work. But IRQ are not supposed to wake the MCU from WFE!?
2025-02-28 11:37 AM
Is SEVONPEND=0?
2025-02-28 12:00 PM
Yes
2025-02-28 12:27 PM - edited 2025-02-28 1:29 PM
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.