Issues waking up from Stop2 mode using interrupt on STM32WB55
Hello!
I'm trying to put my project into Stop2 mode (so it can only be woken up by 1 of 5 wakeup pins) on an STM32WB55 Nucleo board. I have an external signal that starts low and goes high to generate an interrupt. I've tried various approaches to code and I can't seem to get my code to wake it up after entering sleep mode (which I assume is happening based solely on LED outputs).
Based on all the variations I've tried, I assume it's because I'm not setting up the interrupt pin correctly.
Here's my *.ioc file showing that I have wakeup pin 2 (PC13) setup for my interrupt:
Below is the code I'm running in main:
Enter_Sleep_Mode();
Exit_Sleep_Mode();Below is the code for the above functions (with various attempts commented out to show some of the things I've tried):
void Enter_Sleep_Mode(void)
{
BSP_LED_On(LED_RED);
//HAL_EnableDBGStopMode();
/* Disable WKUP pin */
HAL_PWR_DisableWakeUpPin( PWR_WAKEUP_PIN1 );
HAL_PWR_DisableWakeUpPin( PWR_WAKEUP_PIN2 );
HAL_PWR_DisableWakeUpPin( PWR_WAKEUP_PIN3 );
HAL_PWR_DisableWakeUpPin( PWR_WAKEUP_PIN4 );
HAL_PWR_DisableWakeUpPin( PWR_WAKEUP_PIN5 );
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* Enable WKUP pin */
//HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2);
//HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN3);
//HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4);
//HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN5);
/* Clearing the bit as per the reference manual to enter into STOP2 mode*/
//CLEAR_BIT(PWR->CR1, PWR_CR1_LPR);
//__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);
//osDelay(1000); /* Put delay before going to shut down */
//HAL_Delay(1000); /* Put delay before going to shut down */
//HAL_SuspendTick();
//HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON,PWR_STOPENTRY_WFI);
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
//SystemClock_Config();
//HAL_ResumeTick();
}
void Exit_Sleep_Mode( void )
{
BSP_LED_Init(LED_BLUE);
BSP_LED_On(LED_BLUE);
SYSCLK_Resume_After_STOP();
BSP_LED_Init(LED_GREEN);
BSP_LED_On(LED_GREEN);
}
/**
* @brief Configures system clock after wake-up from STOP: enable MSI, PLL
* and select MSI as system clock source.
* @param None
* @retval None
*/
void SYSCLK_Resume_After_STOP(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
uint32_t pFLatency = 0;
/* Get the Oscillators configuration according to the internal RCC registers */
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
/* After wake-up from STOP reconfigure the system clock: Enable MSI and PLL */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Get the Clocks configuration according to the internal RCC registers */
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
/* Select MSI as system clock source */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK)
{
Error_Handler();
}
}I think I'm pretty close but I'm clearly missing something important (like maybe I'm calling a function with the wrong argument, I'm not setting up my interrupt correctly, need to set the polarity of my interrupt, etc).
Any ideas what I might be missing? Thanks!
