Skip to content

Commit

Permalink
samples: boards: espressif: add deep sleep counter
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sylvioalves authored and kartben committed Jan 10, 2025
1 parent 5d05e28 commit c4fd9ea
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion samples/boards/espressif/deep_sleep/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <esp_sleep.h>
#include <driver/rtc_io.h>

#define WAKEUP_TIME_SEC (20)
#include <esp_attr.h>

#define WAKEUP_TIME_SEC (5)

#ifdef CONFIG_EXAMPLE_EXT1_WAKEUP
#define EXT_WAKEUP_PIN_1 (2)
Expand All @@ -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:
Expand Down

0 comments on commit c4fd9ea

Please sign in to comment.