STM32WB Sleep mode issues
Hey, we are developing a product using a STM32WB5MMGHx on a custom PCB and using ThreadX instead of the scheduler + TinyLPM.
I'm having issues getting the MCU into a suitably low power sleep mode, and I'm seeing odd behaviour where lower current draw is measured in STOP_2 vs SHUTDOWN mode.
my code for entering SHUTDOWN mode
DBGMCU->CR = 0;
hci_reset();
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
HAL_SuspendTick();
HAL_PWREx_DisableBLEActivityIT();
HAL_PWREx_Disable802ActivityIT();
HAL_PWREx_EnablePullUpPullDownConfig();
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, GPIO_PIN_1);
HAL_PWREx_ClearWakeupFlag(PWR_FLAG_WU);
HAL_PWREx_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH,PWR_CORE_CPU1);
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_PWREx_DisableInternalWakeUpLine();
HAL_PWREx_ClearWakeupFlag(PWR_FLAG_WU);
LL_PWR_ClearFlag_WU();
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
LL_LPM_EnableDeepSleep();
__WFI();
We have a button on pin A1 that we intend to wake from sleep mode, we intend to treat waking from sleep as a system reset so SHUTDOWN seemed like the best option.
Our board draws 0.024A with the MCU active and 0.011A after attempting to enter shutdown mode.
I also tried STOP_2 mode with the following code
while(1)
{
DBGMCU->CR = 0;
HAL_SuspendTick();
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
__WFI();
if(platform_gpio_read_pin(PLATFORM_GPIO_PWR_BUTTON) == 0)
{
NVIC_SystemReset();
}
}
In STOP2 power mode we measure an input current of 0.007A.
In shutdown mode, all interrupts are ignored and the device wakes up only when our power button PA1 is pressed.
In STOP2 we get woken by any interrupt source, but go back to sleep unless it is the power button.
The 2nd core does appear to go to sleep in both modes, we get disconnected from BLE on sleep and if sleep is entered during advertising then advertising stops.
Can anyone give advice on entering SHUTDOWN mode correctly, or if we are doing so already, why we would be seeing lower currents in STOP2 vs SHUTDOWN?
