STM32WB55 Shutdown mode
Ciao,
I am trying to put my STM32wb55 in shutdown mode and wake it up using 2 external pins.
Wake-up sources are on PA0 (active high) and PC12 (active low). Those should be PIN1 and PIN3 wake-up sources.
This is the code I use to put the device in shutdown mode:
void EnterLowPower()
{
__disable_irq();
__disable_fault_irq();
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
HAL_PWREx_DisableBLEActivityIT();
HAL_PWREx_Disable802ActivityIT();
HAL_RTCEx_DeactivateWakeUpTimer(&RTC_Handle);
HAL_PWREx_EnablePullUpPullDownConfig();
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, GPIO_PIN_1);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, GPIO_PIN_7);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, GPIO_PIN_15);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_B, GPIO_PIN_4);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_B, GPIO_PIN_7);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_B, GPIO_PIN_13);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_B, GPIO_PIN_15);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_D, GPIO_PIN_0);
HAL_PWREx_ClearWakeupFlag(PWR_FLAG_WU);
HAL_PWREx_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH,PWR_CORE_CPU1);
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
HAL_PWREx_EnableWakeUpPin(PWR_WAKEUP_PIN3_LOW,PWR_CORE_CPU1);
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN3);
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4);
HAL_PWREx_DisableInternalWakeUpLine();
HAL_PWREx_ClearWakeupFlag(PWR_FLAG_WU);
HAL_PWREx_EnterSHUTDOWNMode();
}
I have some simple code that just enters shutdown mode a few seconds after boot (just toggling some LEDs to give me a hint of the current state).
What I see is that the device seems to enter shutdown mode (I see the outputs I set as pull-down changing their state) but almost immediately (50ms) resuming. It may also be just a reset instead of a shutdown, but I checked nRST_SHDW in FLASH_OPTR and it's set to 1 and so this should not happen).
I check the state of PWR->SR1, PWR->SR2 and RCC->CSR after this "resume" and values are 0x0000 0x0101 and 0x0C000000 like for a normal boot-up.
This is how clocks are initialized:
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS |
RCC_PERIPHCLK_RFWAKEUP |
RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_CLK48SEL |
RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_I2C3;
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_HSI48;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
PeriphClkInitStruct.RFWakeUpClockSelection = RCC_RFWKPCLKSOURCE_LSE;
PeriphClkInitStruct.SmpsClockSelection = RCC_SMPSCLKSOURCE_HSE;
PeriphClkInitStruct.SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1;
PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_SYSCLK;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) ;I mention this because if I remove RCC_PERIPHCLK_RFWAKEUP and set RFWakeUpClockSelection to RCC_RFWKPCLKSOURCE_NONE the device seems to enter shutdown mode but then does not seem to be able to recover (one of the two inputs is a button, so pushing-releasing it would generate multiple rising and falling edges, excluding a configuration problem for the wake-up source polarity, I think. I anyway tried to change those with no success.
It's there something I am missing in my EnterLowPower function?
I checked STMicroelectronics/STM32CubeWB on github but can't find any sample using HAL_PWREx_EnterSHUTDOWNMode. I found some for the L4 and I think I do the same things they do in their code, but ATM it does not seem to work.
