ESP-C3 putting back to deep sleep keeps resetting

Supertramp4
Posts: 6
Joined: Sun May 29, 2022 6:40 pm

ESP-C3 putting back to deep sleep keeps resetting

Postby Supertramp4 » Sun Jun 19, 2022 2:51 pm

Hi,
I have a ESP32-C3 where i need to use the esp_wake_deep_sleep() stub to perform some tasks, and then return back to sleep, but every time i attempt to put it back to sleep, it just resets, and wakes up the system rather than returning to deep sleep,
I have simplified the code as much as possible and this code does not return back to sleep. It just keeps wakes up every 2 seconds.

Code: Select all

#include "esp32c3/rom/rtc.h"
/*
Simple Deep Sleep with Timer Wake Up for ESP32-C3
*/

#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  2        /* Time ESP32 will go to sleep (in seconds) */

RTC_DATA_ATTR int bootCount = 0;
RTC_DATA_ATTR int wakeupcount = 5;

void setup(){
  Serial.begin(115200);
  delay(1000); //Take some time to open up the Serial Monitor
  Serial.println("Boot number: " + String(bootCount));
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +  " Seconds");
  Serial.println("Going to sleep now");
  Serial.flush(); 
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void RTC_IRAM_ATTR esp_wake_deep_sleep()
{
  esp_default_wake_deep_sleep();
  //Increment boot number
  ++bootCount;  
  // check to see if time to wakeup ,or go back to sleep
  if (bootCount <= wakeupcount)
  {
      // Go to sleep.      
      set_rtc_memory_crc();
      CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);
      SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_SLEEP_EN);
      // A few CPU cycles may be necessary for the sleep to start...
      while (true) {
        ;
      }
  }
  else
  {
  // wake up normally
  return;
  }
}

void loop(){
  //This is not going to be called
}

This results in console output of :

Code: Select all

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x1 (POWERON),boot:0xd (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x438
load:0x403ce000,len:0x90c
load:0x403d0000,len:0x2358
SHA-256 comparison failed:
Calculated: a9753a4fc647c6545c1b919ef08db429130a48592727edca270f1e5a3da0d0a9
Expected: 3bf6ef2cf3b9eefcd4b3c70cc5d1ce5138292d101a5cb1d5db6fbebf081b0a19
Attempting to boot anyway...
entry 0x403ce000
Boot number: 0
Setup ESP32 to sleep for every 2 Seconds
Going to sleep now
ESP-ROM:esp32c3-api1-20210207
Build:Fe⸮ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x5 (DSLEEP),boot:0xd (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x438
load:0x403ce000,len:0x90c
load:0x403d0000,len:0x2358
SHA-256 comparison failed:
Calculated: a9753a4fc647c6545c1b919ef08db429130a48592727edca270f1e5a3da0d0a9
Expected: 3bf6ef2cf3b9eefcd4b3c70cc5d1ce5138292d101a5cb1d5db6fbebf081b0a19
Attempting to boot anyway...
entry 0x403ce000
Boot number: 1
Setup ESP32 to sleep for every 2 Seconds
Going to sleep now
ESP-ROM:esp32c3-api1-20210207
Build:Fe⸮ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x5 (DSLEEP),boot:0xd (SPI_FAST_FLASH_BOOT)
SPIWP:0xee

I've been trying to resolve this for weeks now and not getting anywhere,
Please can anyone help
Thanks

rpiloverbd
Posts: 101
Joined: Tue Mar 22, 2022 5:23 am

Re: ESP-C3 putting back to deep sleep keeps resetting

Postby rpiloverbd » Mon Jun 20, 2022 8:03 am

These old threads may give you some clues if you already have not checked them:

https://arduino.stackexchange.com/quest ... deep-sleep
https://www.esp8266.com/viewtopic.php?f=13&t=14836

Supertramp4
Posts: 6
Joined: Sun May 29, 2022 6:40 pm

Re: ESP-C3 putting back to deep sleep keeps resetting

Postby Supertramp4 » Mon Jun 20, 2022 1:07 pm

Hi, rpiloverbd
Thanks - I looked at the 2 posts, and don't believe these are contributory factors.
1) i am deliberately avoiding any GPIO pins, and my code does not enable any GPIO wake up
2) the board is powered directly from the USB port, so there shouldn't be any power spikes
3) i have tried using the set_rtc_memory_crc(); which others have mentioned for the C3.

Any other suggestions ?

Supertramp4
Posts: 6
Joined: Sun May 29, 2022 6:40 pm

Re: ESP-C3 putting back to deep sleep keeps resetting

Postby Supertramp4 » Sat Jun 25, 2022 3:29 pm

Bump, has anyone got any suggestions on this please?

Who is online

Users browsing this forum: No registered users and 55 guests