Wow, great find!! Well that certainly made a difference! Yes, I think it's the same issue. I have the same concern as the person at the bottom of that thread, why is it signaling POWERON instead of brownout?
Now it seems to have a new weird behavior... The same code that was sleeping fine and waking up on a touch pad before (when the brownout was still enabled), is now sleeping just great the first time. However, once I touch the touchpad and wake it up, it wakes up great, DSLEEP, reason=touch wakeup, but it reinitializes the touch pad and tries to go back to sleep and just ends up in a VERY fast infinite loop waking up with touch wakeup constantly...
What's strange is that this same code worked fine (from the touchpad wakeup perspective) a minute ago...
main.c:
Code: Select all
#include <string.h>
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/rtc_io.h"
#include "sleep.h"
static const char *TAG = "Main";
extern "C" void app_main(void)
{
int reason = Wakeup();
ESP_LOGI(TAG, "Wake reason=%d", reason);
GoToSleep();
}
sleep.c:
Code: Select all
// sleep.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_sleep.h"
#include "esp_log.h"
#include "driver/touch_pad.h"
#include "driver/rtc_io.h"
#include "driver/touch_pad.h"
#include "driver/adc.h"
#include "esp_wifi.h"
#include "soc/rtc.h"
static const char *TAG = "Sleep";
static RTC_DATA_ATTR struct timeval sleep_enter_time;
int Wakeup()
{
struct timeval now;
gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
int cause = esp_sleep_get_wakeup_cause();
esp_reset_reason_t reset_reason = esp_reset_reason();
ESP_LOGI(TAG, "esp_reset_reason=%d Timespent in deep sleep=%dms", reset_reason, sleep_time_ms);
switch (cause) {
case ESP_SLEEP_WAKEUP_TIMER: {
ESP_LOGI(TAG, "Wake up from timer. Time spent in deep sleep: %dms", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_TOUCHPAD: {
ESP_LOGI(TAG, "Wake up from touch on pad %d", esp_sleep_get_touchpad_wakeup_status());
break;
}
case ESP_SLEEP_WAKEUP_ULP: {
ESP_LOGI(TAG, "Wake up from ULP. Time spent in deep sleep: %dms", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
ESP_LOGI(TAG, "Not a deep sleep reset");
}
return cause;
}
void GoToSleep()
{
/* Initialize touch pad peripheral. */
touch_pad_init();
/* Only support one touch channel in sleep mode. */
touch_pad_config(TOUCH_PAD_NUM13);
/* Denoise setting at TouchSensor 0. */
touch_pad_denoise_t denoise = {
/* The bits to be cancelled are determined according to the noise level. */
.grade = TOUCH_PAD_DENOISE_BIT4,
.cap_level = TOUCH_PAD_DENOISE_CAP_L4,
};
touch_pad_denoise_set_config(&denoise);
touch_pad_denoise_enable();
/* Filter setting */
touch_filter_config_t filter_info = {
.mode = TOUCH_PAD_FILTER_IIR_16,
.debounce_cnt = 1, // 1 time count.
.noise_thr = 0, // 50%
.jitter_step = 4, // use for jitter mode.
.smh_lvl = TOUCH_PAD_SMOOTH_IIR_2,
};
touch_pad_filter_set_config(&filter_info);
touch_pad_filter_enable();
/* Set sleep touch pad. */
touch_pad_sleep_channel_enable(TOUCH_PAD_NUM13, true);
touch_pad_sleep_channel_enable_proximity(TOUCH_PAD_NUM13, false);
/* Enable touch sensor clock. Work mode is "timer trigger". */
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
touch_pad_fsm_start();
vTaskDelay(100 / portTICK_RATE_MS);
/* read sleep touch pad value */
uint32_t touch_value;
touch_pad_sleep_channel_read_smooth(TOUCH_PAD_NUM13, &touch_value);
touch_pad_sleep_set_threshold(TOUCH_PAD_NUM13, touch_value * 0.1); //10%
ESP_LOGI(TAG, "test init: touch pad [%d] slp %d, thresh %d",
TOUCH_PAD_NUM13, touch_value, (uint32_t)(touch_value * 0.1));
uint32_t sleep_time_in_ms = 1000;
uint32_t touchpad_sleep_ticks = (uint32_t)((uint64_t)sleep_time_in_ms * rtc_clk_slow_freq_get_hz() / 1000);
uint16_t oldslp, oldmeas;
touch_pad_get_meas_time(&oldslp, &oldmeas);
ESP_LOGI(TAG, "oldslp=%d newslp=%d oldmeas=%d", oldslp, touchpad_sleep_ticks, oldmeas);
touch_pad_set_meas_time(touchpad_sleep_ticks, 500);
ESP_LOGI(TAG, "Enabling touch pad wakeup");
esp_sleep_enable_touchpad_wakeup();
// Enable timer wake up
const uint64_t wakeup_time_sec = 3600*24; // 1 day
ESP_LOGI(TAG, "Enabling timer wakeup, %llds", wakeup_time_sec);
esp_sleep_enable_timer_wakeup(wakeup_time_sec * 1000000);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
esp_wifi_stop();
adc_power_off();
ESP_LOGI(TAG, "Entering deep sleep\n");
gettimeofday(&sleep_enter_time, NULL);
esp_deep_sleep_start();
}
i:\w\sleeponly>idf.py monitor
Executing action: monitor
Choosing default port b'COM3' (use '-p PORT' option to set a specific serial port)
Running idf_monitor in directory i:\w\sleeponly
Executing "C:\Users\scott\.espressif\python_env\idf4.2_py3.7_env\Scripts\python.exe i:\repos\esp-idf-fork\tools/idf_monitor.py -p COM3 -b 115200 --toolchain-prefix xtensa-esp32s2-elf- i:\w\sleeponly\build\remote-scale.elf -m 'C:\Users\scott\.espressif\python_env\idf4.2_py3.7_env\Scripts\python.exe' 'i:\repos\esp-idf-fork\tools\idf.py'"...
←[0;33m--- WARNING: GDB cannot open serial ports accessed as COMx←[0m
←[0;33m--- Using \\.\COM3 instead...←[0m
--- idf_monitor on \\.\COM3 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
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:0x1868
load:0x4004c000,len:0x1688
load:0x40050000,len:0x20fc
entry 0x4004c324
I (47) boot: ESP-IDF v4.2-dev-2488-gce5608c8f 2nd stage bootloader
I (48) boot: compile time 17:38:09
I (48) boot: chip revision: 0
I (51) boot.esp32s2: SPI Speed : 80MHz
I (56) boot.esp32s2: SPI Mode : DIO
I (60) boot.esp32s2: SPI Flash Size : 4MB
I (65) boot: Enabling RNG early entropy source...
I (70) boot: Partition Table:
I (74) boot: ## Label Usage Type ST Offset Length
I (81) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (89) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (96) boot: 2 factory factory app 00 00 00010000 00100000
I (104) boot: End of partition table
I (108) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x0cad8 ( 51928) map
I (128) esp_image: segment 1: paddr=0x0001cb00 vaddr=0x3ffc46d0 size=0x02eb0 ( 11952) load
I (131) esp_image: segment 2: paddr=0x0001f9b8 vaddr=0x40024000 size=0x00404 ( 1028) load
0x40024000: _WindowOverflow4 at I:/repos/esp-idf-fork/components/freertos/xtensa/xtensa_vectors.S:1730
I (135) esp_image: segment 3: paddr=0x0001fdc4 vaddr=0x40024404 size=0x00254 ( 596) load
I (144) esp_image: segment 4: paddr=0x00020020 vaddr=0x40080020 size=0x34724 (214820) map
0x40080020: _stext at ??:?
I (197) esp_image: segment 5: paddr=0x0005474c vaddr=0x40024658 size=0x10078 ( 65656) load
I (215) esp_image: segment 6: paddr=0x000647cc vaddr=0x40070000 size=0x0001c ( 28) load
I (216) esp_image: segment 7: paddr=0x000647f0 vaddr=0x50000000 size=0x00008 ( 8) load
I (231) boot: Loaded app from partition at offset 0x10000
I (231) boot: Disabling RNG early entropy source...
I (234) cache: Instruction cache : size 8KB, 4Ways, cache line size 32Byte
I (241) cpu_start: Pro cpu up.
I (245) cpu_start: Application information:
I (250) cpu_start: Project name: remote-scale
I (255) cpu_start: App version: 1
I (260) cpu_start: Compile time: Jan 25 2021 17:38:05
I (266) cpu_start: ELF file SHA256: 9bdc21c4abeebd43...
I (272) cpu_start: ESP-IDF: v4.2-dev-2488-gce5608c8f
I (278) cpu_start: Single core mode
I (282) heap_init: Initializing. RAM available for dynamic allocation:
I (289) heap_init: At 3FFCA688 len 00031978 (198 KiB): DRAM
I (296) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (302) cpu_start: Pro cpu start user code
I (368) spi_flash: detected chip: generic
I (368) spi_flash: flash io: dio
I (368) cpu_start: Starting scheduler on PRO CPU.
I (372) Sleep: esp_reset_reason=1 Timespent in deep sleep=8ms
I (372) Sleep: Not a deep sleep reset
I (382) Main: Wake reason=0
I (482) Sleep: test init: touch pad [13] slp 21120, thresh 2112
I (482) Sleep: oldslp=15 newslp=90000 oldmeas=500
I (482) Sleep: Enabling touch pad wakeup
I (482) Sleep: Enabling timer wakeup, 86400s
I (492) Sleep: Entering deep 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:0x1868
load:0x4004c000,len:0x1688
load:0x40050000,len:0x20fc
entry 0x4004c324
I (47) boot: ESP-IDF v4.2-dev-2488-gce5608c8f 2nd stage bootloader
I (47) boot: compile time 17:38:09
I (48) boot: chip revision: 0
I (51) boot.esp32s2: SPI Speed : 80MHz
I (56) boot.esp32s2: SPI Mode : DIO
I (60) boot.esp32s2: SPI Flash Size : 4MB
I (65) boot: Enabling RNG early entropy source...
I (70) boot: Partition Table:
I (74) boot: ## Label Usage Type ST Offset Length
I (81) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (89) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (96) boot: 2 factory factory app 00 00 00010000 00100000
I (104) boot: End of partition table
I (108) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x0cad8 ( 51928) map
I (128) esp_image: segment 1: paddr=0x0001cb00 vaddr=0x3ffc46d0 size=0x02eb0 ( 11952) load
I (131) esp_image: segment 2: paddr=0x0001f9b8 vaddr=0x40024000 size=0x00404 ( 1028) load
0x40024000: _WindowOverflow4 at I:/repos/esp-idf-fork/components/freertos/xtensa/xtensa_vectors.S:1730
I (135) esp_image: segment 3: paddr=0x0001fdc4 vaddr=0x40024404 size=0x00254 ( 596) load
I (144) esp_image: segment 4: paddr=0x00020020 vaddr=0x40080020 size=0x34724 (214820) map
0x40080020: _stext at ??:?
I (197) esp_image: segment 5: paddr=0x0005474c vaddr=0x40024658 size=0x10078 ( 65656) load
I (215) esp_image: segment 6: paddr=0x000647cc vaddr=0x40070000 size=0x0001c ( 28)
I (215) esp_image: segment 7: paddr=0x000647f0 vaddr=0x50000000 size=0x00008 ( 8)
I (230) boot: Loaded app from partition at offset 0x10000
I (230) boot: Disabling RNG early entropy source...
I (233) cache: Instruction cache : size 8KB, 4Ways, cache line size 32Byte
I (240) cpu_start: Pro cpu up.
I (244) cpu_start: Application information:
I (249) cpu_start: Project name: remote-scale
I (254) cpu_start: App version: 1
I (259) cpu_start: Compile time: Jan 25 2021 17:38:05
I (265) cpu_start: ELF file SHA256: 9bdc21c4abeebd43...
I (271) cpu_start: ESP-IDF: v4.2-dev-2488-gce5608c8f
I (277) cpu_start: Single core mode
I (282) heap_init: Initializing. RAM available for dynamic allocation:
I (289) heap_init: At 3FFCA688 len 00031978 (198 KiB): DRAM
I (295) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (301) cpu_start: Pro cpu start user code
I (365) spi_flash: detected chip: generic
I (366) spi_flash: flash io: dio
I (366) cpu_start: Starting scheduler on PRO CPU.
I (369) Sleep: esp_reset_reason=8 Timespent in deep sleep=336352ms
I (369) Sleep: Wake up from touch on pad 13
I (379) Main: Wake reason=5
I (479) Sleep: test init: touch pad [13] slp 21357, thresh 2135
I (479) Sleep: oldslp=15 newslp=90000 oldmeas=500
I (479) Sleep: Enabling touch pad wakeup
I (479) Sleep: Enabling timer wakeup, 86400s
I (489) Sleep: Entering deep 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:0x1868
load:0x4004c000,len:0x1688
load:0x40050000,len:0x20fc
entry 0x4004c324
I (47) boot: ESP-IDF v4.2-dev-2488-gce5608c8f 2nd stage bootloader
I (47) boot: compile time 17:38:09
I (48) boot: chip revision: 0
I (51) boot.esp32s2: SPI Speed : 80MHz
I (56) boot.esp32s2: SPI Mode : DIO
I (60) boot.esp32s2: SPI Flash Size : 4MB
I (65) boot: Enabling RNG early entropy source...
I (70) boot: Partition Table:
I (74) boot: ## Label Usage Type ST Offset Length
I (81) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (89) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (96) boot: 2 factory factory app 00 00 00010000 00100000
I (104) boot: End of partition table
I (108) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x0cad8 ( 51928) map
I (128) esp_image: segment 1: paddr=0x0001cb00 vaddr=0x3ffc46d0 size=0x02eb0 ( 11952) load
I (131) esp_image: segment 2: paddr=0x0001f9b8 vaddr=0x40024000 size=0x00404 ( 1028) load
0x40024000: _WindowOverflow4 at I:/repos/esp-idf-fork/components/freertos/xtensa/xtensa_vectors.S:1730
I (135) esp_image: segment 3: paddr=0x0001fdc4 vaddr=0x40024404 size=0x00254 ( 596) load
I (144) esp_image: segment 4: paddr=0x00020020 vaddr=0x40080020 size=0x34724 (214820) map
0x40080020: _stext at ??:?
I (197) esp_image: segment 5: paddr=0x0005474c vaddr=0x40024658 size=0x10078 ( 65656) load
I (215) esp_image: segment 6: paddr=0x000647cc vaddr=0x40070000 size=0x0001c ( 28)
I (215) esp_image: segment 7: paddr=0x000647f0 vaddr=0x50000000 size=0x00008 ( 8)
I (230) boot: Loaded app from partition at offset 0x10000
I (230) boot: Disabling RNG early entropy source...
I (233) cache: Instruction cache : size 8KB, 4Ways, cache line size 32Byte
I (240) cpu_start: Pro cpu up.
I (244) cpu_start: Application information:
I (249) cpu_start: Project name: remote-scale
I (254) cpu_start: App version: 1
I (259) cpu_start: Compile time: Jan 25 2021 17:38:05
I (265) cpu_start: ELF file SHA256: 9bdc21c4abeebd43...
I (271) cpu_start: ESP-IDF: v4.2-dev-2488-gce5608c8f
I (277) cpu_start: Single core mode
I (282) heap_init: Initializing. RAM available for dynamic allocation:
I (289) heap_init: At 3FFCA688 len 00031978 (198 KiB): DRAM
I (295) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (301) cpu_start: Pro cpu start user code
I (365) spi_flash: detected chip: generic
I (366) spi_flash: flash io: dio
I (366) cpu_start: Starting scheduler on PRO CPU.
I (369) Sleep: esp_reset_reason=8 Timespent in deep sleep=382ms
I (369) Sleep: Wake up from touch on pad 13
I (379) Main: Wake reason=5
I (479) Sleep: test init: touch pad [13] slp 21323, thresh 2132
I (479) Sleep: oldslp=15 newslp=90000 oldmeas=500
I (479) Sleep: Enabling touch pad wakeup
I (479) Sleep: Enabling timer wakeup, 86400s
I (489) Sleep: Entering deep sleep
Any ideas?
Thanks,
- Scott