2025-11-20 7:24 AM
Good day,
I have a simple custom board with a STM32WL31 that needs to cyclically enter DEEPSTOP mode and then wake by means of RTC internal wakeup. It seems the device enters DEEPSTOP, but does not wake from it.
Basic setup:
I can confirm RTC runs, RTC interrupt occurs every 1s, and HAL_PWR_EnterSLEEPMode() behaves correctly.
However, when I enter DEEPSTOP with the sequence below, then the code never gets to HAL_ResumeTick() (reset after a few seconds by IWDT):
PWR_DEEPSTOPTypeDef sConfigDEEPSTOP;
sConfigDEEPSTOP.deepStopMode = PWR_DEEPSTOP_WITH_SLOW_CLOCK_ON;
HAL_PWR_ConfigDEEPSTOP(&sConfigDEEPSTOP);
HAL_SuspendTick();
HAL_PWR_EnterDEEPSTOPMode();
HAL_ResumeTick();
Below is a reg dump of possible relevant registers just before calling SET_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk) in HAL_PWR_EnterDEEPSTOPMode().
PWR_CR1=0x00000114
PWR_CR2=0x00000120
PWR_IEWU=0x00000002
PWR_IWUP=0x00000002
PWR_IWUF=0x00000000
PWR_SR2=0x0000F3F0
PWR_CR5=0x00006514
PWR_DBGR=0x00000000
PWR_EXTSRR=0x00000000
RCC_CR=0x00001430
RCC_CFGR=0x00008000
RTC_CR=0x00005504
RTC_ISR=0x00000023
RTC_WUTR=0x00000001
Kindly advise any fixes or suggestions - thank you.
2025-11-21 7:17 AM
hello @marvdm
and welcome to ST community!
are you using the RTC in internal wakeup mode? and can u try to implement these lines of code to your project ?
HAL_PWREx_EnableInternalWakeUpLine(PWR_WAKEUP_RTC, PWR_WUP_RISIEDG);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_RTC);
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x555, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
Hope that helps
Gyessine
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-11-23 6:28 AM - edited 2025-11-23 6:30 AM
Hi Gyessine,
Thank you very much for your reply. Yes, I am using the RTC in internal wakeup mode.
I've implemented your lines, but unfortunately no change in behavior. My main code now is:
HAL_PWREx_EnableInternalWakeUpLine(PWR_WAKEUP_RTC, PWR_WUP_RISIEDG);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_RTC);
// Setup to wake every 2s
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, (2-1), RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK)
{
Error_Handler();
}
// Restart IWDT 8s timeout
HAL_IWDG_Refresh(&hiwdg);
PWR_DEEPSTOPTypeDef sConfigDEEPSTOP = {.deepStopMode = PWR_DEEPSTOP_WITH_SLOW_CLOCK_ON};
HAL_PWR_ConfigDEEPSTOP(&sConfigDEEPSTOP);
HAL_PWR_EnterDEEPSTOPMode();The code executes into DEEPSTOP mode, but instead of waking after 2s, the IWDT triggers after about 8s.
I did see something interesting - when I program the board with STM32CubeProgrammer, then it works correctly (i.e. wake after 2s) for only the first cycle; after that the IWDT always triggers after 8s. When I power cycle the board, the IWDT always triggers after 8s. It is almost as if the STM32CubeProgrammer clears some flag/state so that it works correctly once.
2025-11-24 5:08 AM
hello @marvdm
At this point, I suspect that the issue is related to your clock frequency. It appears to be operating at a quarter of the expected speed (0.25 Hz) instead of 1 Hz.
Can you verify the content of the RTC_WAKEUPCLOCK_CK_SPRE_16BITS register at the start of each cycle and double-check the RTC prescalers to ensure that the output is actually 1 Hz?
Hope that helps
Gyessine
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-11-25 7:36 AM - edited 2025-11-25 10:11 AM
Hi Gyessine,
Thank you for your feedback. I've checked the RTC, and I can confirm that it output frequency is correct.
I've taken a step back and setup a loop to test the RTC wakeup timer without DEEPSTOP:
while (1) {
// Toggle LED
HAL_GPIO_TogglePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin);
HAL_PWREx_EnableInternalWakeUpLine(PWR_WAKEUP_RTC, PWR_WUP_RISIEDG);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_RTC);
// Setup wakeup after 3s: 32kHz/16 = 500us * 6000 = ~3s
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 6000, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
// Wait for RTC wakeup flag
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_RTC));
}For above code I observe the BLUE LED toggle every 3s, as expected. I also confirmed RTC_IRQHandler() fires correctly.
However, when I add the code to config & enter DEEPSTOP, I get the same problem.
I've profiled the current consumption (see picture below), and it seems as if the device exits DEEPSTOP correctly the first time after programming. However, it seems to not exit DEEPSTOP the second time - it goes into an unknown state indefinitely where it draws ~7mA, and no code is executed.
I don't know if this is relevant, but the hardware platform does not implement the SMPS - there is no specific setup made in code for this, and I don't know if it is relevant to the behavior in DEEPSTOP.
Thank you,
Marius
2025-11-26 6:30 AM
Hi Gyessine,
Just as a quick follow-up to the above feedback. I'm wondering if my problem is not related to the power configuration. My hardware platform does not implement the SMPS (i.e. designed as per Fig 9 of the datasheet, "STM32WL31xx application circuit without SMPS"). I've now added the following lines:
MODIFY_REG(PWR->CR5, PWR_CR5_NOSMPS, (SMPS_OFF<<PWR_CR5_NOSMPS_Pos));
MODIFY_REG(PWR->CR5, PWR_CR5_SMPSLPOPEN, (SMPS_LOW_POWER_OPEN<<PWR_CR5_SMPSLPOPEN_Pos));Unfortunately I still get the same behavior (i.e. failure to exit DEEPSTOP). Is there perhaps any additional configuration I need to make in order to run & DEEPSTOP without SMPS?