Skip to content

Commit

Permalink
Merge branch 'feature/add_wakeup_cost_info_to_dslp_wakestub_example' …
Browse files Browse the repository at this point in the history
…into 'master'

feature: add wake up time cost info to deep_sleep_wake_stub example

See merge request espressif/esp-idf!22683
  • Loading branch information
esp-wzh committed Mar 11, 2023
2 parents 9e0502d + e489902 commit c8364fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
8 changes: 7 additions & 1 deletion components/esp_hw_support/sleep_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,13 @@ static uint32_t get_power_down_flags(void)
return pd_flags;
}

void esp_deep_sleep_disable_rom_logging(void)
#if CONFIG_IDF_TARGET_ESP32
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_IRAM_ATTR */
void
#else
void RTC_IRAM_ATTR
#endif
esp_deep_sleep_disable_rom_logging(void)
{
rtc_suppress_rom_log();
}
Expand Down
35 changes: 22 additions & 13 deletions examples/system/deep_sleep_wake_stub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In this example, the `CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP` Kconfig opt

### Hardware Required

This example should be able to run on any commonly available ESP32/ESP32-S2/ESP32-S3/ESP32-C3 development board without any extra hardware if only **Timer** wake up sources are used.
This example should be able to run on any commonly available ESP32/ESP32-S2/ESP32-S3/ESP32-C3/ESP32-C6 development board without any extra hardware if only **Timer** wake up sources are used.

### Configure the project

Expand Down Expand Up @@ -57,19 +57,28 @@ The ESP chips will then enter deep sleep. When a timer wake up occurs, if deep s

```
...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x5 (DSLEEP),boot:0x8 (SPI_FAST_FLASH_BOOT)
wake stub: wakeup count is 1, wakeup cause is 8
ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x5 (SLEEP_WAKEUP),boot:0x2c (SPI_FAST_FLASH_BOOT)
wake stub: wakeup count is 1, wakeup cause is 16, wakeup cost 6505 us
wake stub: going to deep sleep
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x5 (DSLEEP),boot:0x8 (SPI_FAST_FLASH_BOOT)
wake stub: wakeup count is 2, wakeup cause is 8
ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x5 (SLEEP_WAKEUP),boot:0x2c (SPI_FAST_FLASH_BOOT)
wake stub: wakeup count is 2, wakeup cause is 16, wakeup cost 6506 us
wake stub: going to deep sleep
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x5 (DSLEEP),boot:0x8 (SPI_FAST_FLASH_BOOT)
wake stub: wakeup count is 3, wakeup cause is 8
ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x5 (SLEEP_WAKEUP),boot:0x2c (SPI_FAST_FLASH_BOOT)
wake stub: wakeup count is 3, wakeup cause is 16, wakeup cost 6505 us
wake stub: going to deep sleep
```

> Note:
> 1. The wakeup time cost printed in this example is not accurate, it does not take into account the hardware initialization time before the CPU starts, for most esp chips the initialization time cost is about 280us.
> 2. And the wake-up time shown in this example is not the optimal wake-up time, because the ROM printing before the wake stub occupies most of the wake-up time, for most esp chips this ROM printing takes about 6100us. In the product firmware, users can temporarily or permanently turn off ROM printing via call `esp_deep_sleep_disable_rom_logging` or set `menuconfig->Boot ROM Behavior->Permanently disable logging` to speed up the wake-up time.
> 3. A method for roughly estimating optimal wake-up time: Taking esp32c6 as example, the wake-up time from stub printing is about 6500us, minus the ROM printing overhead of 6100us, plus the system initialization overhead of 280us, its optimal wake-up overhead is about 680us. Users also can modify the example to configure GPIO wake-up, and obtain a more realistic and accurate wake-up time by grabbing GPIO signals
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <inttypes.h>
#include "esp_sleep.h"
#include "esp_cpu.h"
#include "esp_rom_sys.h"
#include "esp_wake_stub.h"
#include "sdkconfig.h"

Expand Down Expand Up @@ -33,15 +35,20 @@ static const uint32_t s_max_count = 20;
// wakeup_cause stored in RTC memory
static uint32_t wakeup_cause;

// wakeup_time from CPU start to wake stub
static uint32_t wakeup_time;

// wake up stub function stored in RTC memory
void wake_stub_example(void)
{
// Get wakeup time.
wakeup_time = esp_cpu_get_cycle_count() / esp_rom_get_cpu_ticks_per_us();
// Get wakeup cause.
wakeup_cause = esp_wake_stub_get_wakeup_cause();
// Increment the counter.
s_count++;
// Print the counter value and wakeup cause.
ESP_RTC_LOGI("wake stub: wakeup count is %d, wakeup cause is %d", s_count, wakeup_cause);
ESP_RTC_LOGI("wake stub: wakeup count is %d, wakeup cause is %d, wakeup cost %ld us", s_count, wakeup_cause, wakeup_time);

if (s_count >= s_max_count) {
// Reset s_count
Expand Down

0 comments on commit c8364fb

Please sign in to comment.