Unable to wake from Stop2 power mode with user button
I put my L4R5ZI chip into Stop2 mode but it doesn't seem to want to wake up from the user button, unfortunately. According to the datasheet, the wakeup sources include:
Reset pin, all I/Os
BOR, PVD, PVM
RTC, IWDG
COMPx (x=1..2)
I2C3(7)
LPUART1(6)
LPTIM1
I have setup the user button (PC13) as an external interrupt on the rising edge and have it entering low power mode using this same button. My code is shown below:
static void MX_GPIO_Init(void)
{
/* Other GPIO setup here */
/*Configure GPIO pin : B1_Pin */
GPIO_InitStruct.Pin = B1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
/* Other GPIO setup here */
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == B1_Pin)
{
while(HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin) == GPIO_PIN_SET)
{
}
if(lowpowermode == true)
{
lowpowermode = false;
//ExitLowPowerMode();
}
else
{
lowpowermode = true;
//EnterLowPowerMode();
Run_Stop_Mode();
//Enter_LowPower_Mode();
}
//HAL_GPIO_TogglePin(GPIOB, LD3_Pin);
}
}
void EnterLowPowerMode()
{
HAL_TIM_Base_Stop_IT(&htim2);
HAL_ADC_Stop_DMA(&hadc1);
HAL_SPI_DeInit(&hspi1);
__HAL_RCC_SPI1_CLK_DISABLE();
//__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOG_CLK_DISABLE();
}
void ExitLowPowerMode()
{
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_SPI1_CLK_ENABLE();
HAL_SPI_Init(&hspi1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_Value, 1);
HAL_TIM_Base_Start_IT(&htim2);
}
void Run_Stop_Mode()
{
EnterLowPowerMode();
// Suspend the Ticks before entering the STOP mode or else this can wake the device up
HAL_SuspendTick();
// Enter Stop Mode
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
SystemClock_Config();
HAL_ResumeTick();
ExitLowPowerMode();
}Am I missing anything obvious? Do I need to setup that pin specifically to enable to interrupt? I've looked at a few other examples but haven't seen anything specifically setting that up. Maybe I'm looking in the wrong place?
I assume I'm probably pretty close but I clearly missed something. Any help you can give me would be appreciated. Thanks!
