STM32WLE5: LPTIM2 ARROK flag never sets after Sleep wake-up unless LSESYSEN is written again
Device
STM32WLE5
Clock configuration
SYSCLK : MSI 16 MHz (MSIPLL mode Enabled)
LSE : 32.768 kHz crystal
LPTIM2 kernel clock : LSE
Low power mode : Sleep
Observed behavior
When configuring LPTIM2 with LSE clock, the following code sometimes blocks because the ARROK flag never sets.
__HAL_LPTIM_AUTORELOAD_SET(&hlptim2, Period); while (!__HAL_LPTIM_GET_FLAG(&hlptim2, LPTIM_FLAG_ARROK));
This occurs after waking up from Sleep mode.
Workaround
Executing the following code before or after wake-up resolves the issue.
RCC->BDCR |= RCC_BDCR_LSESYSEN;
After writing LSESYSEN, the ARROK flag sets normally.
Initialization code
SystemClock_Config() already enables LSESYSEN. It is CubeMX provided.
LL_PWR_EnableBkUpAccess();
LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_MEDIUMLOW);
LL_RCC_LSE_EnablePropagation();
LL_RCC_LSE_Enable();
while (LL_RCC_LSE_IsReady() != 1)
{
}
LL_RCC_LSE_EnablePropagation() is defined as:
__STATIC_INLINE void LL_RCC_LSE_EnablePropagation(void)
{
SET_BIT(RCC->BDCR, RCC_BDCR_LSESYSEN);
}
Therefore LSESYSEN is set during system initialization.
RM0461 description
RM0461 states:
“To be able to use the clock by other peripherals (LPTIMx, TIMx, USARTx, LPUARTx...), the LSE system clock must be enabled with the LSESYSEN bit.”
Also:
“This bit is set and cleared by software.”
And:
“RCC_BDCR is reset only by backup domain reset.”
From this description:
-
LSESYSEN should remain set unless cleared by software
-
Sleep mode should not reset RCC_BDCR
Questions
-
Why does LPTIM2 stop receiving the LSE system clock after waking from Sleep mode, even though LSESYSEN was already set during initialization?
-
Does LSESYSEN require re-writing after low-power mode exit for LPTIM to receive the LSE clock?
-
Are there documented limitations or errata regarding:
-
LSE system clock distribution
-
LSESYSEN behavior after low-power mode
-
LPTIM using LSE on STM32WL devices
-
In my case, LSEON & LSERDY bits are set before/after MCU enters sleep mode.
Thanks in advance!
