cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476RE immediately exits STOPMODE2 after entering, even though the HAL_SuspendTick() tick has been called prior to.

vanhorng
Associate

I have a small C application running on an STM32L476RE and I am using FreeRTOS as an OS. I want to periodically enter into a low power mode on the processor since this is an IoT battery device. I have tried entering the stopmode 2 by way of this code:

 

SEGGER_RTT_printf(0, "Entering STOP2 mode. %lu\r\n", HAL_GetTick());

   HAL_SuspendTick();

   HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x7FFF, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

   HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

   SEGGER_RTT_printf(0, "Exiting STOP2 mode. %lu\r\n", HAL_GetTick());

   HAL_ResumeTick();

 

I have also added a handler for the RTC wakeup ISR.

 

void RTC_WKUP_IRQHandler()

{

   HAL_RTCEx_WakeUpTimerIRQHandler(&hrtc);

}

 

Unfortunately, once the code gets to the HAL_PWREx_EnterSTOP2Mode() it returns immediately as if an interrupt had just occurred. I had a breakpoint set in the RTC_WKUP_IRQHandler and it doesn't break there until the expected amount of time has elapsed. In this case, it is something like 10 or 15 seconds. However, as mentioned previously the device had already moved on from low power mode since it exits that WFI instruction immediately. I have monitored the NVIC_ISPRx registers to see if any interrupt was pending, but I do not see a bit set in the registers.

 

I had the call to enter stopmode2 be at the end of a task once it had finished saving some data. As mentioned it doesn't work there, but if I place the code to enter stopmode2 prior to starting the freeRTOS scheduler it will stay in low power until the RTC wakeup counter expires. Do you think this is a clue?

 

I am using a gcc-arm-none-eabi with VSCode for my compiler.

 

Thanks,

Gerry

0 REPLIES 0