cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL31 fails to exit DEEPSTOP from RTC wakeup

marvdm
Associate II

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:

  • Clocked from HSI, RTC clocked from LSE with 32kHz xtal.
  • SMPS not implemented.
  • Basic project generated with STM32CubeMX 6.16.0 with MCU Package for STM32WL3 Series 1.3.0 installed.
  • IWDT active
  • MR_SUBG radio not yet implemented

 

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.

14 REPLIES 14

I traced the bootloader and found that it jumps directly to the application after a power-on reset. Upon the first wake-up, it reads the RCC_CSR register and interprets it as a reset rather than a wake-up event, consequently entering the application. It only reads the AppBase variable on the second wake-up. Therefore, the device can only wake up successfully once.

Thank you @xy3dg12, that did the trick.

For future reference, below is the working solution - the device successfully and repeatedly enters deepstop and then exits (after 2s) from RTC wakeup.

// ...

// Setup wakeup on RTC internal event
HAL_PWREx_EnableInternalWakeUpLine(PWR_WAKEUP_RTC, PWR_WUP_RISIEDG);
// Clear RTC internal wakeup flag
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_RTC);
// Setup RTC wakeup in 2s
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, (2-1), RTC_WAKEUPCLOCK_CK_SPRE_16BITS);

// Only RTC RAM is preserved through deepstop; write value to detect
// reset due to wake from deepstop
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR0, 0x1234);
	
// Setup deepstop with LSE clocking RTC
PWR_DEEPSTOPTypeDef sConfigDEEPSTOP;
sConfigDEEPSTOP.deepStopMode = PWR_DEEPSTOP_WITH_SLOW_CLOCK_ON;
HAL_PWR_ConfigDEEPSTOP(&sConfigDEEPSTOP);

// Setup application base (BL jumps here upon wakeup from deepstop)
*(uint32_t*)0x20000014 = 0x10040000;

// Enter deepstop
HAL_PWR_EnterDEEPSTOPMode();
	
// cpu resets upon wake from deepstop, never get here

 

Gyessine
ST Employee

Hello @marvdm@xy3dg12 and @sbelcatronic 

I would like to share an update following our internal review of this topic.

First, please note that after wake-up from DeepStop, the STM32LWL31 device is not intended to resume from the previous execution point. Instead, it is designed to restart from reset.

We also found that the proposed workaround from @xy3dg12 of manually writing AppBase may not be safe. It seemed to work only because the current STM32LWL31 linker file does not place the RAM_VR structure at the correct address.

A fix will be included in a future STM32CubeMX release. In the meantime, a practical workaround is to use the STM32LWL33 linker file.

BR
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.

Thank you Gyessine,

if writing the AppBase register by the instruction 

*(uint32_t*)0x20000014 = 0x10040000;

may not be safe, what is the safe workaround?

 

sbelcatronic

 

Gyessine
ST Employee

Hello @sbelcatronic 
For now, a fix in in working state, but a practical workaround is to use the STM32WL33 linker file.
BR
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.