Skip to content

Commit c4fd9ea

Browse files
sylvioalveskartben
authored andcommitted
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 <[email protected]>
1 parent 5d05e28 commit c4fd9ea

File tree

1 file changed

+10
-1
lines changed
  • samples/boards/espressif/deep_sleep/src

1 file changed

+10
-1
lines changed

samples/boards/espressif/deep_sleep/src/main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <esp_sleep.h>
1010
#include <driver/rtc_io.h>
1111

12-
#define WAKEUP_TIME_SEC (20)
12+
#include <esp_attr.h>
13+
14+
#define WAKEUP_TIME_SEC (5)
1315

1416
#ifdef CONFIG_EXAMPLE_EXT1_WAKEUP
1517
#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
2426
#endif
2527
#endif
2628

29+
/* keep data in RTC memory after deep-sleep */
30+
RTC_DATA_ATTR int s_rtc_data = 0;
31+
2732
int main(void)
2833
{
34+
#ifdef CONFIG_BOOTLOADER_MCUBOOT
35+
printk("ESP32 deep sleep example, current counter is %d\r\n", s_rtc_data++);
36+
#endif
37+
2938
switch (esp_sleep_get_wakeup_cause()) {
3039
#ifdef CONFIG_EXAMPLE_EXT1_WAKEUP
3140
case ESP_SLEEP_WAKEUP_EXT1:

0 commit comments

Comments
 (0)