m5stack / M5Unified

Unified library for M5Stack series
MIT License
313 stars 58 forks source link

Deep sleep on CoreInk #57

Closed pguyot closed 1 year ago

pguyot commented 1 year ago

Using tag 0.1.6.

Calling M5.Power.timerSleep(int) puts a CoreInk to deep sleep, but when it wakes up, if it is running on battery, the reboot reason (result of esp_reset_reason()) is not ESP_RST_DEEPSLEEP but ESP_RST_WDT or ESP_RST_POWERON and any RTC Slow memory variable (RTC_NOINIT_ATTR) is lost.

The problem doesn't happen if the CoreInk is plugged on USB. The problem doesn't happen if the following two lines are commented:

  void Power_Class::timerSleep( int seconds )
  {
-    M5.Rtc.clearIRQ();
-    M5.Rtc.setAlarmIRQ(seconds);
+//    M5.Rtc.clearIRQ();
+//    M5.Rtc.setAlarmIRQ(seconds);
    esp_sleep_enable_timer_wakeup(seconds * 1000000ULL);
    _timerSleep();
  }

Also, I haven't been able to get M5.Power.timerSleep(const rtc_time_t&) on the CoreInk to work at all.

lovyan03 commented 1 year ago

Thank you for your report...! I will check and adjust.

patfelst commented 1 year ago

Hi this may be related, also on CoreInk, when I use:

  M5.Power.deepSleep(10 * 1000000);

it works correctly on USB power, that is, wakes up after 10 seconds. On battery, it goes to sleep but never wakes up. A single push of the power button wakes it up again.

patfelst commented 1 year ago

Hi guys, I found a solution here https://github.com/m5stack/M5Core-Ink/issues/8

Although note that it does keep the port power on so your external sensors will not power down.

patfelst commented 1 year ago

thankyou @lovyan03 👍

lovyan03 commented 1 year ago

I was a bit mistaken. It seems @pguyot 's first post contains a misunderstanding of the spec. The timerSleep is intended to be started using the I2C RTC timer, not a function intended to make it deepSleep. If you want ESP32 to do deepSleep, use M5.Power.deepSleep.

Although the designation of deepSleep is not originally necessary in the timerSleep function, it is included as a fallback action because the ESP32 will not be able to return from timerSleep on models that do not have an RTC.