From c4fd9eac4c25f311b9a7bf31f4d3c698e3d21aea Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Tue, 7 Jan 2025 11:50:34 -0300 Subject: [PATCH] samples: boards: espressif: add deep sleep counter Includes a RTC attribute as counter value to demonstrate data being kept in memory after deep sleep reset. This is only valid when MCUboot is enabled. Signed-off-by: Sylvio Alves --- samples/boards/espressif/deep_sleep/src/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/samples/boards/espressif/deep_sleep/src/main.c b/samples/boards/espressif/deep_sleep/src/main.c index 519a1a550df9..5cf93c6a98cd 100644 --- a/samples/boards/espressif/deep_sleep/src/main.c +++ b/samples/boards/espressif/deep_sleep/src/main.c @@ -9,7 +9,9 @@ #include #include -#define WAKEUP_TIME_SEC (20) +#include + +#define WAKEUP_TIME_SEC (5) #ifdef CONFIG_EXAMPLE_EXT1_WAKEUP #define EXT_WAKEUP_PIN_1 (2) @@ -24,8 +26,15 @@ static const struct gpio_dt_spec wakeup_button = GPIO_DT_SPEC_GET(DT_ALIAS(wakeu #endif #endif +/* keep data in RTC memory after deep-sleep */ +RTC_DATA_ATTR int s_rtc_data = 0; + int main(void) { +#ifdef CONFIG_BOOTLOADER_MCUBOOT + printk("ESP32 deep sleep example, current counter is %d\r\n", s_rtc_data++); +#endif + switch (esp_sleep_get_wakeup_cause()) { #ifdef CONFIG_EXAMPLE_EXT1_WAKEUP case ESP_SLEEP_WAKEUP_EXT1: