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

Device resets instead of waking up from deep sleep (IDFGH-4341) #6179

Closed
Totalus opened this issue Nov 30, 2020 · 4 comments
Closed

Device resets instead of waking up from deep sleep (IDFGH-4341) #6179

Totalus opened this issue Nov 30, 2020 · 4 comments

Comments

@Totalus
Copy link

Totalus commented Nov 30, 2020

Problem Description

After deep sleep timeout, the device sometimes boots up as a reset rst:0x1 (POWERON) instead of waking up from deep sleep rst:0x5 (DSLEEP) as it should. I've observed that behavior with other wake up sources as well (e.g RTC GPIOs).

Environment

  • Development Kit: ESP32-S2-Saola-1 v1.2 (based on ESP32-S2-WROOM)
  • Module or chip used: ESP32-S2-WROOM
  • IDF version: v4.2-rc-5-g511965b26
  • Build System: idf.py
  • Compiler version: xtensa-esp32-elf-gcc.exe (crosstool-NG esp-2020r3) 8.4.0
  • Operating System: Windows
  • Environment type: MSYS2 mingw64
  • Using an IDE: No
  • Power Supply: USB

Expected Behavior

Device waking up from deep sleep rst:0x5 (DSLEEP).

Actual Behavior

Device often waking up in reset rst:0x1 (POWERON), which causes all the RTC memory to be lost (time is reset).

Steps and Code to reproduce this issue

Start from the hello_world example project and replace the main code by the following.

#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_log.h"
#include "esp_sleep.h"

void app_main(void)
{
    esp_reset_reason_t resetReason = esp_reset_reason();

    ESP_LOGI("test", "--- Woke up ---\n");

    if(resetReason != ESP_RST_DEEPSLEEP)
    {
        ESP_LOGE("test", "ERROR: Device reset\n");
    }

    ESP_LOGI("test", "--- Going to sleep ---\n");
    esp_deep_sleep(5*1000000UL); // 5 seconds
}

Flash this on the IC and check the logs. Once in a while I the ERROR: Device reset prints out (see log below).

  • The wake up happens after the deep sleep period (5 seconds) even when it is a reset, so it not likely caused by some other external event (supply glitch or else).
  • I don't have to wait very long to see it happen. It sometimes happens twice in a row. There do not seem to be a regular pattern to the occurrences.

Debug Logs

I won't attach all of the log because its the same thing over an over, but here's a snapshot where you can see some normal wake up rst:0x5 (DSLEEP) and a reset rst:0x1 (POWERON).

See highlighted lines:

[...]

ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
#rst:0x5 (DSLEEP),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x4
load:0x3ffe6104,len:0x18a4
load:0x4004c000,len:0x1688
load:0x40050000,len:0x20fc
entry 0x4004c324
I (46) boot: ESP-IDF v4.2-rc-5-g511965b26-dirty 2nd stage bootloader
I (46) boot: compile time 20:45:04
I (46) boot: chip revision: 0
I (49) boot.esp32s2: SPI Speed      : 80MHz
I (54) boot.esp32s2: SPI Mode       : DIO
I (59) boot.esp32s2: SPI Flash Size : 2MB
I (63) boot: Enabling RNG early entropy source...
I (69) boot: Partition Table:
I (72) boot: ## Label            Usage          Type ST Offset   Length
I (80) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (87) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (95) boot:  2 factory          factory app      00 00 00010000 00100000
I (102) boot: End of partition table
I (106) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x05aa0 ( 23200) map
I (120) esp_image: segment 1: paddr=0x00015ac8 vaddr=0x3ffbdf10 size=0x01d64 (  7524) load
I (126) esp_image: segment 2: paddr=0x00017834 vaddr=0x40024000 size=0x00404 (  1028) load
0x40024000: _WindowOverflow4 at G:/Autonom/Repositories/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730
I (133) esp_image: segment 3: paddr=0x00017c40 vaddr=0x40024404 size=0x083d8 ( 33752) load
I (151) esp_image: segment 4: paddr=0x00020020 vaddr=0x40080020 size=0x13528 ( 79144) map
0x40080020: _stext at ??:?
I (168) esp_image: segment 5: paddr=0x00033550 vaddr=0x4002c7dc size=0x0172c (  5932) load
0x4002c7dc: rtc_clk_cal at G:/Autonom/Repositories/esp-idf/components/soc/src/esp32s2/rtc_time.c:131
I (170) esp_image: segment 6: paddr=0x00034c84 vaddr=0x40070000 size=0x0001c (    28) 
I (180) boot: Loaded app from partition at offset 0x10000
I (180) boot: Disabling RNG early entropy source...
I (186) cache: Instruction cache 	: size 8KB, 4Ways, cache line size 32Byte
I (194) cpu_start: Pro cpu up.
I (197) cpu_start: Application information:
I (202) cpu_start: Project name:     hello-world
I (207) cpu_start: App version:      v4.2-rc-5-g511965b26-dirty
I (214) cpu_start: Compile time:     Nov 29 2020 20:44:37
I (220) cpu_start: ELF file SHA256:  21c27e11a7b7efe5...
I (226) cpu_start: ESP-IDF:          v4.2-rc-5-g511965b26-dirty
I (233) cpu_start: Single core mode
I (237) heap_init: Initializing. RAM available for dynamic allocation:
I (244) heap_init: At 3FFC0438 len 0003BBC8 (238 KiB): DRAM
I (250) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (256) cpu_start: Pro cpu start user code
I (314) spi_flash: detected chip: generic
I (314) spi_flash: flash io: dio
W (314) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (324) cpu_start: Starting scheduler on PRO CPU.
I (330) test: --- Woke up ---

I (330) test: --- Going to sleep ---

ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
#rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x4
load:0x3ffe6104,len:0x18a4
load:0x4004c000,len:0x1688
load:0x40050000,len:0x20fc
entry 0x4004c324
I (46) boot: ESP-IDF v4.2-rc-5-g511965b26-dirty 2nd stage bootloader
I (46) boot: compile time 20:45:04
I (46) boot: chip revision: 0
I (49) boot.esp32s2: SPI Speed      : 80MHz
I (54) boot.esp32s2: SPI Mode       : DIO
I (59) boot.esp32s2: SPI Flash Size : 2MB
I (64) boot: Enabling RNG early entropy source...
I (69) boot: Partition Table:
I (73) boot: ## Label            Usage          Type ST Offset   Length
I (80) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (87) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (95) boot:  2 factory          factory app      00 00 00010000 00100000
I (102) boot: End of partition table
I (106) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x05aa0 ( 23200) map
I (120) esp_image: segment 1: paddr=0x00015ac8 vaddr=0x3ffbdf10 size=0x01d64 (  7524) load
I (126) esp_image: segment 2: paddr=0x00017834 vaddr=0x40024000 size=0x00404 (  1028) load
0x40024000: _WindowOverflow4 at G:/Autonom/Repositories/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730
I (134) esp_image: segment 3: paddr=0x00017c40 vaddr=0x40024404 size=0x083d8 ( 33752) load
I (151) esp_image: segment 4: paddr=0x00020020 vaddr=0x40080020 size=0x13528 ( 79144) map
0x40080020: _stext at ??:?
I (168) esp_image: segment 5: paddr=0x00033550 vaddr=0x4002c7dc size=0x0172c (  5932) load
0x4002c7dc: rtc_clk_cal at G:/Autonom/Repositories/esp-idf/components/soc/src/esp32s2/rtc_time.c:131
I (170) esp_image: segment 6: paddr=0x00034c84 vaddr=0x40070000 size=0x0001c (    28) load
I (180) boot: Loaded app from partition at offset 0x10000
I (181) boot: Disabling RNG early entropy source...
I (186) cache: Instruction cache 	: size 8KB, 4Ways, cache line size 32Byte
I (194) cpu_start: Pro cpu up.
I (198) cpu_start: Application information:
I (203) cpu_start: Project name:     hello-world
I (208) cpu_start: App version:      v4.2-rc-5-g511965b26-dirty
I (214) cpu_start: Compile time:     Nov 29 2020 20:44:37
I (220) cpu_start: ELF file SHA256:  21c27e11a7b7efe5...
I (226) cpu_start: ESP-IDF:          v4.2-rc-5-g511965b26-dirty
I (233) cpu_start: Single core mode
I (237) heap_init: Initializing. RAM available for dynamic allocation:
I (244) heap_init: At 3FFC0438 len 0003BBC8 (238 KiB): DRAM
I (251) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (257) cpu_start: Pro cpu start user code
I (316) spi_flash: detected chip: generic
I (316) spi_flash: flash io: dio
W (316) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (327) cpu_start: Starting scheduler on PRO CPU.
I (332) test: --- Woke up ---

#E (332) test: ERROR: Device reset

I (332) test: --- Going to sleep ---

ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
#rst:0x5 (DSLEEP),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x4
load:0x3ffe6104,len:0x18a4
load:0x4004c000,len:0x1688
load:0x40050000,len:0x20fc
entry 0x4004c324
I (46) boot: ESP-IDF v4.2-rc-5-g511965b26-dirty 2nd stage bootloader
I (46) boot: compile time 20:45:04
I (46) boot: chip revision: 0
I (49) boot.esp32s2: SPI Speed      : 80MHz
I (54) boot.esp32s2: SPI Mode       : DIO
I (59) boot.esp32s2: SPI Flash Size : 2MB
I (63) boot: Enabling RNG early entropy source...
I (69) boot: Partition Table:
I (72) boot: ## Label            Usage          Type ST Offset   Length
I (80) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (87) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (95) boot:  2 factory          factory app      00 00 00010000 00100000
I (102) boot: End of partition table
I (106) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x05aa0 ( 23200) map
I (120) esp_image: segment 1: paddr=0x00015ac8 vaddr=0x3ffbdf10 size=0x01d64 (  7524) load
I (126) esp_image: segment 2: paddr=0x00017834 vaddr=0x40024000 size=0x00404 (  1028) load
0x40024000: _WindowOverflow4 at G:/Autonom/Repositories/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730
I (133) esp_image: segment 3: paddr=0x00017c40 vaddr=0x40024404 size=0x083d8 ( 33752) load
I (151) esp_image: segment 4: paddr=0x00020020 vaddr=0x40080020 size=0x13528 ( 79144) map
0x40080020: _stext at ??:?
I (168) esp_image: segment 5: paddr=0x00033550 vaddr=0x4002c7dc size=0x0172c (  5932) load
0x4002c7dc: rtc_clk_cal at G:/Autonom/Repositories/esp-idf/components/soc/src/esp32s2/rtc_time.c:131
I (170) esp_image: segment 6: paddr=0x00034c84 vaddr=0x40070000 size=0x0001c (    28) 
I (180) boot: Loaded app from partition at offset 0x10000
I (180) boot: Disabling RNG early entropy source...
I (186) cache: Instruction cache 	: size 8KB, 4Ways, cache line size 32Byte
I (194) cpu_start: Pro cpu up.
I (197) cpu_start: Application information:
I (202) cpu_start: Project name:     hello-world
I (207) cpu_start: App version:      v4.2-rc-5-g511965b26-dirty
I (214) cpu_start: Compile time:     Nov 29 2020 20:44:37
I (220) cpu_start: ELF file SHA256:  21c27e11a7b7efe5...
I (226) cpu_start: ESP-IDF:          v4.2-rc-5-g511965b26-dirty
I (233) cpu_start: Single core mode
I (237) heap_init: Initializing. RAM available for dynamic allocation:
I (244) heap_init: At 3FFC0438 len 0003BBC8 (238 KiB): DRAM
I (250) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (256) cpu_start: Pro cpu start user code
I (314) spi_flash: detected chip: generic
I (314) spi_flash: flash io: dio
W (314) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (324) cpu_start: Starting scheduler on PRO CPU.
I (330) test: --- Woke up ---

I (330) test: --- Going to sleep ---

[...]
@github-actions github-actions bot changed the title Device resets instead of waking up from deep sleep Device resets instead of waking up from deep sleep (IDFGH-4341) Nov 30, 2020
@igrr
Copy link
Member

igrr commented Nov 30, 2020

@Totalus Could you please try turning off the brownout detector in menuconfig, under Component config -> ESP32-S2 specific, and see the problem still exists?

@Totalus
Copy link
Author

Totalus commented Nov 30, 2020

@igrr It solved the issue. Nice catch !

How do you explain that the brown out detector triggers this easily ? I wouldn't expect it to do so on a simple boot of the IC.

@igrr
Copy link
Member

igrr commented Nov 30, 2020

@Totalus Thanks for the confirmation. This might be a hardware issue. I'll follow up internally to see whether this is something we can work around in ESP-IDF.

@Totalus Totalus closed this as completed Nov 30, 2020
@Totalus
Copy link
Author

Totalus commented Dec 2, 2020

I'm wondering, why does it not reset with the ESP_RST_BROWNOUT flag instead, since it seems to be a brownout detection issue ?

I think I also had brownout issues elsewhere, but they were never flagged as brownouts, just as simple resets, which makes it harder to figure out.

espressif-bot pushed a commit that referenced this issue Mar 11, 2021
On S2 the brown out detector would occasionally trigger erroneously during deep sleep.

Disable it before sleeping to circumvent this issue.

Closes #6179
espressif-bot pushed a commit that referenced this issue Mar 12, 2021
On S2 the brown out detector would occasionally trigger erroneously during deep sleep.

Disable it before sleeping to circumvent this issue.

Closes #6179
espressif-bot pushed a commit that referenced this issue Mar 12, 2021
On S2 the brown out detector would occasionally trigger erroneously during deep sleep.

Disable it before sleeping to circumvent this issue.

Closes #6179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants