Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with deep sleep time (esp_sleep_enable_timer_wakeup() suddenly/randomly stops) (IDFGH-10717) #11939

Closed
3 tasks done
snehapawar221087 opened this issue Jul 24, 2023 · 36 comments
Assignees
Labels
Awaiting Response awaiting a response from the author Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally

Comments

@snehapawar221087
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

Hello All,

we have designed a data logger using esp32s3, and device wakes up after every set time, and collects data from sensor and goes to deep sleep.
But suddenly system is facing a issue where device is not waking from deep sleep after setting a time of 10mins.

ESP_IDF version is v4.4
please find sdkconfig file in an attachment.

Kindly note the below behaviour:
1] This issue is happening randomly.
2] device is waking up due to any external interrupts which we have set but timer wakeup
3] when device goes to deep sleep, unless and until external interrupt happens, device won't wakeup
4] when issue happens, device won't wakeup and collects data until external interrupt happens, before this issue and after external interrupt while device is in mode, device works fine, goes in deep sleep and comes out of it properly, and no data loss is been seen.

it's been found that when device won't wake up at set time, till external interrupt, that time device remains in deep sleep.

Please find the code below :

<-------------------------------------------------
sdkconfig_file.txt
sdkconfig_file.txt
------------------------------------------------------------->

//set deep sleep time as sleep_time -> seconds is user defined
uint64_t sleep_time = seconds * uS_TO_S_FACTOR;
esp_err_t err = esp_sleep_enable_timer_wakeup(sleep_time);
printf("SLEEPING FOR %d SECONDS: %d\r\n\r\n", seconds, err);

//external interrupts to wakeup device from deep sleep
const int ext_wakeup_pin_1 = 12;
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
const int ext_wakeup_pin_2 = 14;
const uint64_t ext_wakeup_pin_2_mask = 1ULL << ext_wakeup_pin_2;
const int ext_wakeup_pin_3 = 1;
const uint64_t ext_wakeup_pin_3_mask = 1ULL << ext_wakeup_pin_3;

esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask | ext_wakeup_pin_3_mask, ESP_EXT1_WAKEUP_ALL_LOW);

gettimeofday(&sleep_enter_time, NULL);

//delete/deinit watchdog timers
esp_task_wdt_reset();
esp_task_wdt_delete(NULL); //Unsubscribe Idle Task from TWDT
esp_task_wdt_status(NULL); //Confirm Idle task has unsubscribed
//Deinit TWDT after all tasks have unsubscribed
esp_task_wdt_deinit();
esp_task_wdt_status(NULL); //Confirm TWDT has been deinitialized

//start deep sleep
esp_deep_sleep_start();

<-------------------------------------------------------------------------------------------------------------->

Please let me know,
1] what is the cause of this issue AND
2] how to resolve this issue.

Thank you in advance.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Jul 24, 2023
@github-actions github-actions bot changed the title problem with deep sleep time (esp_sleep_enable_timer_wakeup() suddenly/randomly stops) problem with deep sleep time (esp_sleep_enable_timer_wakeup() suddenly/randomly stops) (IDFGH-10717) Jul 24, 2023
@esp-lis
Copy link
Collaborator

esp-lis commented Jul 24, 2023

I guess it may be due to the slow clock source you have chosen. Please refer to the following:

# CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC is not set
# CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS is not set
CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC=y
# CONFIG_ESP32S3_RTC_CLK_SRC_INT_8MD256 is not set

CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC It means you need to provide an external crystal oscillator as the slow clock source. Perhaps you can use Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC) to test.

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Jul 24, 2023
@snehapawar221087
Copy link
Author

Hello [esp-lis],
Thanks for your reply.

We used external crystal oscillator in our devices, so the setting.

@esp-lis
Copy link
Collaborator

esp-lis commented Jul 25, 2023

Hello [esp-lis], Thanks for your reply.

We used external crystal oscillator in our devices, so the setting.

image
Refer to the figure above to ensure that the GPIO functionality of the alternative XTAL PIN functionality is not initialized in the code.

In addition, I suggest that you use Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC) to test whether there is still the same problem.

@snehapawar221087
Copy link
Author

Hello [esp-lis],
Thanks for your reply.

Am positive that GPIO functionality of the alternative XTAL PIN functionality is not initialized in the code.

I will use Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC) to test whether there is still the same problem.

Thank you.

@snehapawar221087
Copy link
Author

Hello [esp-lis],

I tried Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC) to test whether there is still the same problem or not
and I got this data loss issue again with this same setting.

If this is not due to external/internal clock, then is it due to some firmware routine/flow?
what causes this?

Have already share the flow from timer set for waking up from deep sleep till calling deep_sleep function.

what might be wrong here?

Let me know what I can test/check to resolve this.

Thank you.

@esp-lis
Copy link
Collaborator

esp-lis commented Jul 26, 2023

Hello [esp-lis],

I tried Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC) to test whether there is still the same problem or not and I got this data loss issue again with this same setting.

If this is not due to external/internal clock, then is it due to some firmware routine/flow? what causes this?

Have already share the flow from timer set for waking up from deep sleep till calling deep_sleep function.

what might be wrong here?

Let me know what I can test/check to resolve this.

Thank you.

@snehapawar221087 When Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC) is used as a slow clock source compared to external 32k oscillator (CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC), there is a large time drift.

Or use external 32k crystal, e.g. 20 ppm (CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS), which we have tested over a long period of time.

@snehapawar221087
Copy link
Author

Hello [esp-lis],
Sorry, but I don't understand what you have said.
I don't see any time drift when I switched from external osc to internal rc clock.

please explain in brief

Thank you.

@esp-lis
Copy link
Collaborator

esp-lis commented Jul 27, 2023

@snehapawar221087 I suspect that the slow clock source may have lost its clock and want to replace a slow clock source test (such as Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC) or external 32k xtal (CONFIG_ESP32S3_RTC_CLK_SRC_EXT_CRYS)), which have longer tests

If it (the problem you describe) is still there, it could be something else and we need more information to diagnose it.

For example, this problem can occur in very few products, or it can occur in all products.

@snehapawar221087
Copy link
Author

Hello esp-lis,
We got this issue in few devices so far.

The device which i have with this issue(other devices are with customers) has frequent data loss issue when clock was external 32k oscillator (CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC).
When i changed clock to Internal 150 kHz OSC (CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC), i saw data loss once, but then onwards for almost 48 hours, data loss is not seen.

Another device which has got this loss issue on field and while with customer's, that device didn't report any data loss issue for more than a 15 days now, when clock was same external 32k oscillator (CONFIG_ESP32S3_RTC_CLK_SRC_EXT_OSC).

Device serial logs couldn't help as we can see that device went for deep sleep, but never wakeup at set time, but wakeup for set external GPIO wakeup sources.

I don't understand whether it's firmware or hardware issue.
If it's a firmware issue, then we must have seen frequent data losses in multiple devices with that firmware, which is not been seen. But getting loss while EXT as well as INT clock, doubting me on firmware.
If it's hardware issue, then we must get no data loss, when clock is internal RC.(i assumed it that device might work perfectly on internal RC,if it's hardware issue(?????))

What might be the issue here??

Thanks & Regards,
Sneha

@snehapawar221087
Copy link
Author

hello,
anything that might help me here??? any updated??

@esp-lis
Copy link
Collaborator

esp-lis commented Aug 1, 2023

hello, anything that might help me here??? any updated??

we can add some test code to collect some data with the following steps:

  1. Use the external 32k oscillator as the slow clock source
  2. When the data is read after the timer wakes up, call rtc_time_get() to record the slow clock tick. For example, output the slow clock tick to log file and record the system timestamp YYYY-MM-DD HH:mm:ss.SSS.
  3. Also record the slow clock tick when ext1 wakes up (same as step 2)
  4. Compare the system timestamp and expect the slow clock to be continuously timed (tick_count * period_us/tick = system_time_us, which requires the slow clock source to be stable enough).

@snehapawar221087
Copy link
Author

Hello esp-lis,

Please find the log, attached with this reply.

In this log, you can fine, sleep_time_ms as a time for which device was in deep sleep.
kv_save_time as a device's rtc time, read when device wakeup from deep sleep.
Used the external 32k oscillator as the slow clock source

according to log,

set time for Total time while Device time
deep sleep Device was in deep when wokeup
(in sec) sleep(in sec)
298 298 1690256400 Tue Jul 25 2023 09:10:00 GMT+0530
299 299 1690256701 Tue Jul 25 2023 09:15:01 GMT+0530
298 5923 1690262626 Tue Jul 25 2023 10:53:46 GMT+0530

It looks like, device's set rtc time is proper/stable.
But device didn't wakeup on set time using wakeup source as timer.

Please see attached log file, that might help you for analysis.
loss_issue_log.txt

loss_issue_log.txt

Thanks & Regards,
Sneha

@snehapawar221087
Copy link
Author

set time for total time while Device time when wokeup
deep sleep device was in deep sleep
(in seconds) (in seconds)

298 298 1690256400 (Tue Jul 25 2023 09:10:00 GMT+0530 (India Standard Time)
299 299 1690256701 (Tue Jul 25 2023 09:15:01 GMT+0530 (India Standard Time)
298 5923 1690262626 (Tue Jul 25 2023 10:53:46 GMT+0530 (India Standard Time)

@snehapawar221087
Copy link
Author

Hello esp-lis,

According to the logs, device won't loose it's time, when it skips timer wakeup.
But for some reason set timer is not invoked.

wakeup reason : Timer
set time to wakeup from deep sleep (in seconds) : 298
total time while device was in deep sleep (in seconds) : 298
Device time when wokeup : 1690256400 (Tue Jul 25 2023 09:10:00 GMT+0530 (India Standard Time)

wakeup reason : Timer
set time to wakeup from deep sleep (in seconds) :299
total time while device was in deep sleep (in seconds) : 299
Device time when wokeup : 1690256701 (Tue Jul 25 20 23 09:15:01 GMT+0530 (India Standard Time)

wakeup reason : Button press(external gpio wakeup
set time to wakeup from deep sleep (in seconds) : 298
total time while device was in deep sleep (in seconds) : 5923
Device time when wokeup : 1690262626 (Tue Jul 25 2023 10:53:46 GMT+0530 (India Standard Time)

As per the current flow, we set the timer wakeup in deep sleep, and then we set external gpio wakeups, as below

we have external wakeups on below gpios
const int ext_wakeup_pin_1 = 12; //light_interrupt
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
const int ext_wakeup_pin_2 = 14;    //button interrupt
const uint64_t ext_wakeup_pin_2_mask = 1ULL << ext_wakeup_pin_2;
const int ext_wakeup_pin_3 = 1;    //shock interrupt
const uint64_t ext_wakeup_pin_3_mask = 1ULL << ext_wakeup_pin_3;
const int ext_wakeup_pin_4 = 7;    //usb interrupt

enabling external wakeups using below
esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask | ext_wakeup_pin_3_mask, ESP_EXT1_WAKEUP_ALL_LOW);
esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_4, 1);

Please note below important observations:
1] We found some of the devices, where loose data because they didn't wakeup for set time, and started again working after sometime to collect data.
2] And some devices, sent data because they had CPU resets, and went in this no wakeup mode, just after that. These devices comes out of this issue, by external GPIO wakeup reason, always with button press(GPIO_14) or USB connection(GPIO_7) for charging.

What might be the issue here?

@esp-lis
Copy link
Collaborator

esp-lis commented Aug 3, 2023

Hello esp-lis,

According to the logs, device won't loose it's time, when it skips timer wakeup. But for some reason set timer is not invoked.

wakeup reason : Timer set time to wakeup from deep sleep (in seconds) : 298 total time while device was in deep sleep (in seconds) : 298 Device time when wokeup : 1690256400 (Tue Jul 25 2023 09:10:00 GMT+0530 (India Standard Time)

wakeup reason : Timer set time to wakeup from deep sleep (in seconds) :299 total time while device was in deep sleep (in seconds) : 299 Device time when wokeup : 1690256701 (Tue Jul 25 20 23 09:15:01 GMT+0530 (India Standard Time)

wakeup reason : Button press(external gpio wakeup set time to wakeup from deep sleep (in seconds) : 298 total time while device was in deep sleep (in seconds) : 5923 Device time when wokeup : 1690262626 (Tue Jul 25 2023 10:53:46 GMT+0530 (India Standard Time)

As per the current flow, we set the timer wakeup in deep sleep, and then we set external gpio wakeups, as below

we have external wakeups on below gpios
const int ext_wakeup_pin_1 = 12; //light_interrupt
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
const int ext_wakeup_pin_2 = 14;    //button interrupt
const uint64_t ext_wakeup_pin_2_mask = 1ULL << ext_wakeup_pin_2;
const int ext_wakeup_pin_3 = 1;    //shock interrupt
const uint64_t ext_wakeup_pin_3_mask = 1ULL << ext_wakeup_pin_3;
const int ext_wakeup_pin_4 = 7;    //usb interrupt

enabling external wakeups using below esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask | ext_wakeup_pin_3_mask, ESP_EXT1_WAKEUP_ALL_LOW); esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_4, 1);

Please note below important observations: 1] We found some of the devices, where loose data because they didn't wakeup for set time, and started again working after sometime to collect data. 2] And some devices, sent data because they had CPU resets, and went in this no wakeup mode, just after that. These devices comes out of this issue, by external GPIO wakeup reason, always with button press(GPIO_14) or USB connection(GPIO_7) for charging.

What might be the issue here?

@snehapawar221087 some few points to be noted, as follows:

  1. esp32s3 EXTx wake up only support ESP_EXT1_WAKEUP_ANY_HIGH or ESP_EXT1_WAKEUP_ANY_LOW, but not support ESP_EXT1_WAKEUP_ALL_LOW, refer to sleep_modes.rst#L119-L122.
  2. If you need to wake up with ext0, call esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); to ensure ESP_PD_DOMAIN_RTC_PERIPH is powered on during sleep.

In addition, I need to know what is the CPU reset reason you mentioned here (And some devices, sent data because they had CPU resets)?

@snehapawar221087
Copy link
Author

Hello esp-lis,

Below points are noted:
esp32s3 EXTx wake up only support ESP_EXT1_WAKEUP_ANY_HIGH or ESP_EXT1_WAKEUP_ANY_LOW, but not support ESP_EXT1_WAKEUP_ALL_LOW, refer to [sleep_modes.rst#L119-L122]
If you need to wake up with ext0, call esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); to ensure ESP_PD_DOMAIN_RTC_PERIPH is powered on during sleep.

In addition, I need to know what is the CPU reset reason you mentioned here (And some devices, sent data because they had CPU resets)?

  • We found that when device stops waking up for the set time, after a while device wakeups up because of CPU reset.
  • we got RESET_REASON from rtc_get_reset_reason(0) as RTC_SW_CPU_RESET, and device starts sending data now onwards.

So two behaviour has been found here:
1] device stops waking up for set timer, and after a while wakes up and starts collecting without any cpu/rtc/poweron resets
2] device stops waking up for set timer, and after a while wakes up due to CPU reset.

What is causing these kind of behaviours?

@esp-lis
Copy link
Collaborator

esp-lis commented Aug 8, 2023

Hello esp-lis,

Below points are noted: esp32s3 EXTx wake up only support ESP_EXT1_WAKEUP_ANY_HIGH or ESP_EXT1_WAKEUP_ANY_LOW, but not support ESP_EXT1_WAKEUP_ALL_LOW, refer to [sleep_modes.rst#L119-L122] If you need to wake up with ext0, call esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); to ensure ESP_PD_DOMAIN_RTC_PERIPH is powered on during sleep.

In addition, I need to know what is the CPU reset reason you mentioned here (And some devices, sent data because they had CPU resets)?

  • We found that when device stops waking up for the set time, after a while device wakeups up because of CPU reset.
  • we got RESET_REASON from rtc_get_reset_reason(0) as RTC_SW_CPU_RESET, and device starts sending data now onwards.

So two behaviour has been found here: 1] device stops waking up for set timer, and after a while wakes up and starts collecting without any cpu/rtc/poweron resets 2] device stops waking up for set timer, and after a while wakes up due to CPU reset.

What is causing these kind of behaviours?

RTC_SW_CPU_RESET, It looks like a software-triggered reset, for example, by calling esp_cpu_reset(int cpu_id).

@esp-lis
Copy link
Collaborator

esp-lis commented Aug 8, 2023

Hello esp-lis,
Below points are noted: esp32s3 EXTx wake up only support ESP_EXT1_WAKEUP_ANY_HIGH or ESP_EXT1_WAKEUP_ANY_LOW, but not support ESP_EXT1_WAKEUP_ALL_LOW, refer to [sleep_modes.rst#L119-L122] If you need to wake up with ext0, call esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); to ensure ESP_PD_DOMAIN_RTC_PERIPH is powered on during sleep.
In addition, I need to know what is the CPU reset reason you mentioned here (And some devices, sent data because they had CPU resets)?

  • We found that when device stops waking up for the set time, after a while device wakeups up because of CPU reset.
  • we got RESET_REASON from rtc_get_reset_reason(0) as RTC_SW_CPU_RESET, and device starts sending data now onwards.

So two behaviour has been found here: 1] device stops waking up for set timer, and after a while wakes up and starts collecting without any cpu/rtc/poweron resets 2] device stops waking up for set timer, and after a while wakes up due to CPU reset.
What is causing these kind of behaviours?

RTC_SW_CPU_RESET, It looks like a software-triggered reset, for example, by calling esp_cpu_reset(int cpu_id).

It might have called esp_restart() (ESP_SYSTEM_MEMPROT_FEATURE disabled in menuconfig) and triggered a RTC_SW_CPU_RESET.

@snehapawar221087
Copy link
Author

Hello esp-lis,

sorry, but may i know what is "ESP_SYSTEM_MEMPROT_FEATURE"?

have used watchdog in code flow, and before restarting due to it or due to fota, we set some flag in nvs, so we get status that this kind of cpu reset is because of watchdog or fota etc.
But we are not getting cpu resets due to fota or watchdog resets, when we found data loss.

While this issue,
1] device stops waking up for set timer, and all of sudden, it wakes up, starts collecting data
OR
2] device stops waking up for set timer, and after a while esp restarts due to cpu reset(am sure it;s not because of watchdog or fota, but unknown to me because those devices are with customers)

i don't understand case 1 and case 2 are happening due to the same reason?
Is this a hardware issue?? it's not with multiple devices, and it's rarely happens with same devices which has this dataloss issue.

Why esp timer stops working and device won't come out of deep sleep?

@esp-lis
Copy link
Collaborator

esp-lis commented Aug 9, 2023

Hello esp-lis,

sorry, but may i know what is "ESP_SYSTEM_MEMPROT_FEATURE"?

have used watchdog in code flow, and before restarting due to it or due to fota, we set some flag in nvs, so we get status that this kind of cpu reset is because of watchdog or fota etc. But we are not getting cpu resets due to fota or watchdog resets, when we found data loss.

While this issue, 1] device stops waking up for set timer, and all of sudden, it wakes up, starts collecting data OR 2] device stops waking up for set timer, and after a while esp restarts due to cpu reset(am sure it;s not because of watchdog or fota, but unknown to me because those devices are with customers)

i don't understand case 1 and case 2 are happening due to the same reason? Is this a hardware issue?? it's not with multiple devices, and it's rarely happens with same devices which has this dataloss issue.

Why esp timer stops working and device won't come out of deep sleep?

@snehapawar221087 Can you provide a simple example code that can reproduce the problem?

@snehapawar221087
Copy link
Author

Hello esp-lis,

am getting this issue in my project, which is huge code.
Instead, can you tell me what do you require to debug, so I will achieve that with my code, and give to you for analysis?

Thanks

@peter3099
Copy link

Hi guys

I'm getting a similar error, for some reason during deep sleep the RTC generates some issue that alters the time counting

image

Now is the time since boot and duration is the time while in deep sleep. It should wake up around every 5 minutes +5% random delay

only the button being pressed fixes this. I've tried using 5.0.3 and 5.1.1 and I get the same results. It happens randomly and I didn't have this issue with idf v4

Thanks

@peter3099
Copy link

peter3099 commented Aug 31, 2023

Code for deep sleep task

`
void deep_sleep_swt_task(void *parameter)
{
uint64_t msToSleep = (uint64_t *)parameter;
// ESP_LOGW(TAG, "Sleeping swtState: %d for %" PRIu64 "sec NoMotionFactor: %d",
// swtState, msToSleep / 1000, get_no_motion_factor());
if (swtState == SWT_WAIT_JOIN)
{ // deepsleep to wait for next lora Join request
turn_off_pin(POWER_VCC);
turn_off_pin(CO2_EN);
print_lora_vars();
}
else if (swtState == SWT_FAIL_JOIN)
{ // deepsleep to wait for next lora Join request
turn_off_pin(POWER_VCC);
turn_off_pin(CO2_EN);
print_lora_vars();
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(BTN2, 0));
}
else if (swtState == SWT_WAIT_CO2)
{ // deep sleep to wait for C02 sensor measurement
gpio_deep_sleep_hold_en();
gpio_hold_en(POWER_VCC);
gpio_hold_en(CO2_EN);
// gpio_num_t gpio_num_co2int = CO2_INT;
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(CO2_INT, 0)); // wake up when CO2 int is low
}
else if (swtState == SWT_SLEEP)
{ // deepsleep to wait for next sample
// vTaskDelay()
turn_off_pin(POWER_VCC);
turn_off_pin(CO2_EN);
init_ulp_program();
ESP_ERROR_CHECK(esp_sleep_enable_ulp_wakeup());
if (get_mot_en() == false)
{
ESP_LOGE(TAG, "MOT ROUTINE DISABLED");
// ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(BTN2, 0));
}
print_lora_vars();
}
esp_deep_sleep_disable_rom_logging(); // suppress boot messages
ESP_ERROR_CHECK(esp_sleep_enable_timer_wakeup(msToSleep * mS_TO_uS_FACTOR));
// esp_err_t setTimer = esp_sleep_enable_timer_wakeup(msToSleep * mS_TO_uS_FACTOR);
// if (setTimer != ESP_OK)
// {
// ESP_LOGE(TAG, "SetTimer Failed: %d", setTimer);
// }
rtc_gpio_isolate(GPIO_NUM_12);
// close_rak_uart();
// rtc_gpio_isolate(GPIO_NUM_15);
// rtc_gpio_isolate(GPIO_NUM_2);

gettimeofday(&sleepTime, NULL);
uptimeInMs += esp_timer_get_time() / 1000;
// printUptime(uptimeInMs);
if (swtState == SWT_SLEEP)
{
    ESP_LOGW(TAG, "### sample Total Time:  %" PRIu64 "ms  Sleeping for %" PRIu64 "sec noMotionFactor: %d",
             uptimeInMs - sampleInitialUptime, msToSleep / 1000, get_no_motion_factor());
    ESP_LOGW(TAG, "###################################");
}
else
{
    ESP_LOGI(TAG, "Awake Total Time:  %" PRIu64 "ms  Sleeping for %" PRIu64 "sec",
             uptimeInMs - sampleInitialUptime, msToSleep / 1000);
}
esp_deep_sleep_start();
vTaskDelete(NULL);

}`

Code after wake up

`void check_wakeup_reason()
{
ESP_LOGI(TAG, "Check Wake UP reason"); // BTN2 to ask for a new sample
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();

struct timeval timeNow;
struct timeval timeDiff;
gettimeofday(&timeNow, NULL);
timersub(&timeNow, &sleepTime, &timeDiff);
uptimeInMs += (timeDiff.tv_sec * (uint64_t)1000) + (timeDiff.tv_usec / 1000);
printf("WK reason %d Now: %" PRIu64 "ms, Duration: %" PRIu64 "ms\r\n",
       wakeup_reason, (timeNow.tv_sec * (uint64_t)1000) + (timeNow.tv_usec / 1000), (timeDiff.tv_sec * (uint64_t)1000) + (timeDiff.tv_usec / 1000));
// rtc_gpio_hold_dis(GPIO_NUM_15);
// rtc_gpio_hold_dis(GPIO_NUM_2);
stop_ulp();

// check wake up reason
}`

@peter3099
Copy link

sdkconfig.txt

@peter3099
Copy link

peter3099 commented Sep 1, 2023

My ESP32 module is ESP32-WROVER-E

Just to add that I've changed the RTC source to
image

And for the last 12 hours I haven't got the issue, could it be a bug with the 150kHz oscillator?

My problem is that now the RTC is draining more current, I don't need super high precision so for me the RC was ok

@snehapawar221087
Copy link
Author

Hello esp-lis,

We found some devices, where before going into 'not wakeup problem', quectel module stopped responding, and we got battery read from quectel is 65235(garbage). ESP file system didn't have saved files of that time, so it's because device didn't walkups for set time to collect sensor's reading.

can it be the issue due to battery/power related? OR some PCB track related issue??

what causes ESP32s3, not waking by set timer?? But system itself wakes up due to watchdog-cpu reset.

any help would be appreciated.

@esp-lis
Copy link
Collaborator

esp-lis commented Sep 14, 2023

quectel module stopped responding, and we got battery read from quectel is 65235(garbage)

@snehapawar221087 To quote your description (quectel module stopped responding, and we got battery read from quectel is 65235(garbage)), the quectel module stopped responding, why can you read the battery status?

@snehapawar221087
Copy link
Author

Hi esp-lis,
Device is in field, and it's a routine where we are turning on the Quectel module to read the battery. We don't verify it while reading whether it's genuine or garbage.
We have observed that rarely battery voltage reading comes as a garbage, during that time sending is also failed or no reply from AT commands.

I gave you quectel's reference to let you know the status of device while going into 'no wakeup state'(timer wakeup stops working but external interrupts like button press, USB etc working during this time), this will make me think if it's power or pcb level issue?

If we just ignore everything, and focus on this that in what circumstances, esp could go into no wakeup state, even if timer wakeup value is been set, and starts working normally after CPU reset???

@esp-lis
Copy link
Collaborator

esp-lis commented Jan 18, 2024

Hello esp-lis,

Please find the log, attached with this reply.

In this log, you can fine, sleep_time_ms as a time for which device was in deep sleep. kv_save_time as a device's rtc time, read when device wakeup from deep sleep. Used the external 32k oscillator as the slow clock source

according to log,

set time for Total time while Device time deep sleep Device was in deep when wokeup (in sec) sleep(in sec) 298 298 1690256400 Tue Jul 25 2023 09:10:00 GMT+0530 299 299 1690256701 Tue Jul 25 2023 09:15:01 GMT+0530 298 5923 1690262626 Tue Jul 25 2023 10:53:46 GMT+0530

It looks like, device's set rtc time is proper/stable. But device didn't wakeup on set time using wakeup source as timer.

Please see attached log file, that might help you for analysis. loss_issue_log.txt

loss_issue_log.txt

Thanks & Regards, Sneha

@snehapawar221087 I have given feedback on this problem. Could you please provide us with samples that can reproduce the problem.

@soroosha
Copy link

soroosha commented Mar 1, 2024

I'm facing the same issue with ESP32 and esp_sleep_enable_timer_wakeup. The board is powered (red LED is on) but the wake up timer stops randomly after a while. This defeats the whole purpose of the wake up timer and is a big issue. Any updates? Mine is a simple program that wakes up once every 30s, scans WiFi and sets a GPIO pin and goes to sleep.

@esp-lis
Copy link
Collaborator

esp-lis commented Mar 1, 2024

@soroosha Could you please provide us with samples that can reproduce the problem.

@soroosha
Copy link

soroosha commented Mar 6, 2024

@soroosha Could you please provide us with samples that can reproduce the problem.

Here is the entire code. Essentially all it does is wake up every 20 seconds, get the RSSI of a specific WiFi network, turn a GPIO on/off based on the RSSI value, then go back to sleep. And repeat.

#include "WiFi.h"

String MY_WIFI_SSID = "Sam's WiFi";
gpio_num_t mosfet = GPIO_NUM_4;
int wifiRssiThreshold = -68;

void setup(void) {
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  pinMode(mosfet, OUTPUT);
  
  esp_sleep_enable_timer_wakeup(20 * 1000000); 
}

void loop()
{
  int ssid_length  = MY_WIFI_SSID.length()+1;    //The +1 is for the 0x00h Terminator
  char ssid_char_array[ssid_length];
  MY_WIFI_SSID.toCharArray(ssid_char_array, ssid_length);
  int n = WiFi.scanNetworks(false, false, false, 100, 0, ssid_char_array);

  int min_rssi = -100;
  int best_rssi = min_rssi;
  for (int i = 0; i < n; ++i) {
    if (String(WiFi.SSID(i).c_str()) == MY_WIFI_SSID) {
      int rssi = int(WiFi.RSSI(i));
      if ( rssi > best_rssi ) {
        best_rssi = rssi;
      }
    }
  }
  WiFi.scanDelete();

  if(gpio_hold_dis(mosfet) != ESP_OK){
    Serial.println("\nFailed to stop holding pin");
  }

  if (best_rssi > wifiRssiThreshold){
    digitalWrite(mosfet, LOW);
  }else{
    digitalWrite(mosfet, HIGH);
  }

  if(gpio_hold_en(mosfet) != ESP_OK){
    Serial.println("\nFailed to hold pin");
  }

  esp_deep_sleep_start();  
}

@esp-lis
Copy link
Collaborator

esp-lis commented Mar 8, 2024

@soroosha

  1. Can you provide a simpler reproduce code?
  2. Is this issue on all chips? If it only exists on a small number of chips, you may need to provide a sample.

@soroosha
Copy link

soroosha commented Mar 8, 2024

The entire code is 50 lines of code so I'm not sure how simpler it can be. And I have not tested it on a large number of chips. I don't think you'll be able to help me specially since the issue is sporadic and the timer seems to stop working after a few days (making it hard to reproduce the issue quickly). Thanks anyway

@esp-lis
Copy link
Collaborator

esp-lis commented Mar 11, 2024

@soroosha I have reported this issue back to the digital engineer, we need a sample that can reproduce this issue, and the program to reproduce it is simple enough, such as using the deep_sleep example (disable some options of CONFIG_EXAMPLE_GPIO_WAKEUP, CONFIG_EXAMPLE_EXT0_WAKEUP, CONFIG_EXAMPLE_EXT1_WAKEUP and CONFIG_EXAMPLE_TOUCH_WAKEUP) to reproduce it.

@espressif-bot espressif-bot added the Awaiting Response awaiting a response from the author label Apr 23, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: In Progress Work is in progress labels Aug 16, 2024
@Sherry616
Copy link
Collaborator

Thanks for reporting, will close due to short of feedback, feel free to reopen with more updates.
Thanks for using our Espressif product!

@Sherry616 Sherry616 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Response awaiting a response from the author Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

6 participants