Getting Wake Cause in Wake Stub not working on S3
Posted: Tue Nov 21, 2023 5:37 pm
I have switched a project from ESP32 to ESP32-S3 and can't figure out why I can't get a correct wake cause in my wake stub. It only returns 0 for the wake cause value when waking from EXT0 input. Can anyone see what I am missing here? Again, this code works fine on the ESP32 such as the TTGO T-Display. I am thinking it must be in the line:
but why is that working on other processors but not on the S3?
(I have googled extensively on this and tried many alternative approaches, but to no avail).
Here is a reduced code example:
THANKS!
and my platformio.ini
Code: Select all
uint32_t _wakeup_cause = REG_GET_FIELD(RTC_CNTL_WAKEUP_STATE_REG, RTC_CNTL_WAKEUP_CAUSE);
but why is that working on other processors but not on the S3?
(I have googled extensively on this and tried many alternative approaches, but to no avail).
Here is a reduced code example:
THANKS!
Code: Select all
#include <Arduino.h>
#include "esp_sleep.h"
#include "esp_cpu.h"
#include "esp_rom_sys.h"
#include "rom\rtc.h" // needed for rtc_get_reset_reason, DEEPSLEEP_RESET, RTC_ENTRY_ADDR_REG
#include "driver\rtc_io.h" // needed for rtc_gpio_pullup_en
#include "soc/rtc.h" // needed for RTC_EXT0_TRIG_EN, RTC_EXT1_TRIG_EN, RTC_TIMER_TRIG_EN, RTC_TOUCH_TRIG_EN, RTC_ULP_TRIG_EN
void setup()
{
rtc_gpio_init(GPIO_NUM)_17;
rtc_gpio_set_direction(GPIO_NUM_17, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pulldown_dis(GPIO_NUM_17);
rtc_gpio_pullup_en(GPIO_NUM_17);
esp_sleep_enable_timer_wakeup(wakeup_time_sec * uS_TO_S_FACTOR);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_17, 0); // 1 = High, 0 = Low
esp_set_deep_sleep_wake_stub(&wake_stub);
esp_deep_sleep_start();
}
RTC_IRAM_ATTR esp_sleep_wakeup_cause_t stub_esp_sleep_get_wakeup_cause()
{
uint32_t _wakeup_cause = REG_GET_FIELD(RTC_CNTL_WAKEUP_STATE_REG, RTC_CNTL_WAKEUP_CAUSE);
if (_wakeup_cause & RTC_EXT0_TRIG_EN)
{
return ESP_SLEEP_WAKEUP_EXT0; // 2
}
else if (_wakeup_cause & RTC_EXT1_TRIG_EN)
{
return ESP_SLEEP_WAKEUP_EXT1; // 3
}
else if (_wakeup_cause & RTC_TIMER_TRIG_EN)
{
return ESP_SLEEP_WAKEUP_TIMER; // 4
}
else if (_wakeup_cause & RTC_TOUCH_TRIG_EN)
{
return ESP_SLEEP_WAKEUP_TOUCHPAD; // 5
}
else if (_wakeup_cause & RTC_ULP_TRIG_EN)
{
return ESP_SLEEP_WAKEUP_ULP; // 6
}
else
{
return ESP_SLEEP_WAKEUP_UNDEFINED; // 0
}
}
//! Begin Wake Stub content
static const char RTC_RODATA_ATTR wakeup_cause_number_str[] = "Wakeup cause = %d\n";
static RTC_DATA_ATTR uint32_t wakeup_cause;
static void RTC_IRAM_ATTR wake_stub(void)
{
esp_default_wake_deep_sleep();
wakeup_cause = stub_esp_sleep_get_wakeup_cause();
ets_printf(wakeup_cause_number_str, wakeup_cause);
//... the rest does not really matter.... if ext0 is the wake cause, I wait for it to return high, then go back to sleep
// ... and if the cause is the timer or undefined, I wake up completely with a "return"
}
Code: Select all
[env:esp32-s3-devkitc-1]
platform = espressif32@6.4.0
board = esp32-s3-devkitc-1
board_build.arduino.memory_type = dio_opi
monitor_speed = 115200
framework = arduino
board_build.partitions = default_partitions.csv
build_flags =
-I./src/
-DCORE_DEBUG_LEVEL=5
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-fmax-errors=5