stm32duino / STM32LowPower

Arduino Low Power library for STM32

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

STM32L4R5xx does not restart or resume code execution after wakeup from deep sleep

ssozonoff opened this issue · comments

Hi,

I have a STM32L4R5ZIY6 which I am trying to get working correctly with deep sleep mode. I can effectively put the MCU into deep sleep mode as observed by the low current readings and it appears to wake up as well per current readings but no code gets executed. According to your read me a wake-up from deep sleep will trigger a reboot.

I see neither this nor resuming from after the sleep statement.

Thanks for any pointers.
Serge

Further testing shows the following

idle(5000) works as expected
sleep(5000) works as expected

deepSleep(5000) the device seems to wakeup from a current consumption point of view but no code gets executed
shutdown(5000) the devices reboots immediately instead of respecting the timeout, shutdown() produces the same result

Tests were performed with example code ExternalWakeup.ino

Thanks,
Serge

With the stm32L4+ MCU, the low power mode DEEP SLEEP is STOP2 and it differs from STOP0 or STOP1 in the way SRAM3 is powered.
When the mcu enters the LowPower_stop(), then it seems that keeping the SRAM3 content with HAL_PWREx_EnableSRAM3ContentRetention can make the ExternalWakeup.ino work correclty

@@ -295,6 +295,10 @@ void LowPower_stop(serial_t *obj)
       || (WakeUpUart->Instance == (USART_TypeDef *)LPUART2_BASE)
 #endif
      ) {
+#if defined(PWR_CR1_RRSTP)
+    // STM32L4+ mcu must keep SRAM3 content
+    HAL_PWREx_EnableSRAM3ContentRetention();
+#endif /* PWR_CR1_RRSTP */
     // STM32L4xx supports STOP2 mode which halves consumption
     HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
   } else

Another approach for the stm32L4+ is to map the DEEP_SLEEP to the stm32 STOP1 low power mode: replaing the HAL_PWREx_EnterSTOP2Mode with HAL_PWREx_EnterSTOP1Mode for this serie.
In terms of current consumption: stop1 or stop2 + SRAM3 powered are similar.

Thanks I will try that then

In terms of current consumption: stop1 or stop2 + SRAM3 powered are similar.

Any difference in wake-up time or behaviour ?

Serge

The WakeUp time is not increased between STOP2 w or w/o SRAM3. WakeUp Time in STOP1 or STOP2 are similar.
(refer to the datasheet "Low-power mode wakeup timings")
Depending on your application (max ram size), you can choose to optimize the power consumption in limiting the SRAM to SRAM1+SRAM2. Then STOP2 is the deep_sleep with SRAM3 not powered at all.

OK thanks for your help. I can confirm that the MCU now seems to wake up correctly with the first change you suggested but I am not seeing anything close to the low power numbers in the datasheet.

2.8 μA Stop 2 with RTC

I am seeing ~300uA in LowPower_stop() running the TimedWakeup code with longer sleep times and no LED.

I am testing a bare board (Swan from blues io https://blues.io/products/swan/) with nothing but a battery hooked up to it.
The problem with these STM32's is the sleep modes are so complex and it's not really one size fits all.

Optimizing the power consumption is a long way and widely depends on the hardware. Does that value only reflect the mcu power consumption ?

@ssozonoff can you confirm that the changing the loop of the sketch in that way

@@ -46,8 +46,7 @@ void loop() {
   }
   // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources)
   // The power consumption of the chip will drop consistently
-  LowPower.sleep();
+  //  LowPower.sleep();
+  LowPower.deepSleep(6000);  /* deep sleep during 6 sec and exit on RTC Alarm */

 }

will enter/exit deep sleep (STOP2) correctly
This is the case on my target stm32l4s5 disco kit

Hi, yes that works.

Thanks

Good.
So this issue will be closed once the PR #66 is merged