2024-05-10 07:56 AM - edited 2024-05-10 08:00 AM
Our Project uses the STM32WB55 with FreeRTOS, using the Systick to context switch. We use both IWDG and WWDG.
To power down the unit we set a flag in non-volatile RAM and then force a WWDG reset. At reset, the NV RAM is checked and if it indicates a power-down request we use the following code to put the unit to sleep:
// And Stop
UTIL_LPM_SetStopMode(1U << CFG_LPM_APP_BLE, UTIL_LPM_ENABLE);
UTIL_LPM_SetOffMode(1U << CFG_LPM_APP_BLE, UTIL_LPM_DISABLE);
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(LL_RCC_STOP_WAKEUPCLOCK_HSI);
STO();
UTIL_LPM_EnterLowPower(); // Sleep Here
NVIC_SystemReset();
So at wake-up the unit always restarts with a software reset.
We use the ST Class B Safety Libraries, so each reset tests both Watchdogs.
Sometimes (maybe one time in ten) when we come to run FreeRTOS there is no Systick Interrupt.
Other interrupts continue to run, TICKINT and ENABLE are set in the Systick Configuration and the
Systick counter is visibly counting down. COUNTFLAG is set showing that the Systick
should have generated at least one interrupt.
I'm not totally clear about how the NVIC works but Bit 15 (systick) is cleared in ISER0, ICER0 and ISPR0.
Not sure which register contains the priority but I'm setting it to 15.
A very important detail is that resetting does not fix this problem - it requires a chip power down.
2024-05-10 09:32 AM
Hello @TWood.4
You need to suspend the systick interrupt before entering in stop or sleep mode. And resume it after wakeup.
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
HAL_ResumeTick();