From a2ca229d2a0cf3f3aad5771e61c05ebf14c40825 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 20 Nov 2025 10:47:42 +0800 Subject: [PATCH 01/13] change(esp_hw_support): add kconfig option to put rtc clock module into iram --- components/esp_hw_support/Kconfig | 6 ++++++ components/esp_hw_support/linker.lf | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index d10007399d..241415ecc0 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -219,6 +219,12 @@ menu "Hardware Settings" menu "RTC Clock Config" orsource "./port/$IDF_TARGET/Kconfig.rtc" + + config RTC_CLK_FUNC_IN_IRAM + bool "Place RTC clock module functions into IRAM" + default y + help + Place RTC clock module (all rtc clock functions and const data) into IRAM. endmenu menu "Peripheral Control" diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index 48fb35f098..f19df19e5d 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -14,9 +14,10 @@ entries: esp_memory_utils (noflash) clk_utils (noflash) if PM_SLP_IRAM_OPT = y: - rtc_clk (noflash) rtc_time (noflash_text) esp_clk_tree: esp_clk_tree_enable_src (noflash) + if RTC_CLK_FUNC_IN_IRAM = y: + rtc_clk (noflash) if IDF_TARGET_ESP32 = y: rtc_clk:rtc_clk_cpu_freq_to_pll_mhz (noflash) rtc_clk:rtc_clk_cpu_freq_to_xtal (noflash) From 2efc896aec79661bd5419fa9967d5cd5ad8dac1d Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 20 Nov 2025 10:51:34 +0800 Subject: [PATCH 02/13] change(esp_hw_support): add kconfig option to put rtc time module into iram --- components/esp_hw_support/Kconfig | 6 ++++++ components/esp_hw_support/linker.lf | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 241415ecc0..a2d5fcc245 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -225,6 +225,12 @@ menu "Hardware Settings" default y help Place RTC clock module (all rtc clock functions and const data) into IRAM. + + config RTC_TIME_FUNC_IN_IRAM + bool "Place RTC time module functions into IRAM" + default y + help + Place RTC time module (all rtc clock functions) into IRAM. endmenu menu "Peripheral Control" diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index f19df19e5d..676f475450 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -14,13 +14,14 @@ entries: esp_memory_utils (noflash) clk_utils (noflash) if PM_SLP_IRAM_OPT = y: - rtc_time (noflash_text) esp_clk_tree: esp_clk_tree_enable_src (noflash) if RTC_CLK_FUNC_IN_IRAM = y: rtc_clk (noflash) if IDF_TARGET_ESP32 = y: rtc_clk:rtc_clk_cpu_freq_to_pll_mhz (noflash) rtc_clk:rtc_clk_cpu_freq_to_xtal (noflash) + if RTC_TIME_FUNC_IN_IRAM = y: + rtc_time (noflash_text) if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED = y: rtc_init:rtc_vddsdio_get_config (noflash) rtc_init:rtc_vddsdio_set_config (noflash) From 72895e7b718b100b87141b5d5bb5c921ae98cfba Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 20 Nov 2025 11:00:42 +0800 Subject: [PATCH 03/13] change(esp_hw_support): modify the default value of the kconfig option for place peripheral control module into iram to y --- components/esp_hw_support/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index a2d5fcc245..24c349b768 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -236,7 +236,7 @@ menu "Hardware Settings" menu "Peripheral Control" config ESP_PERIPH_CTRL_FUNC_IN_IRAM bool "Place peripheral control functions into IRAM" - default n + default y help Place peripheral control functions (e.g. periph_module_reset) into IRAM, so that these functions can be IRAM-safe and able to be called in the other IRAM interrupt context. From 613f0051f263684627ccd952974317a9ca170bea Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 20 Nov 2025 11:08:37 +0800 Subject: [PATCH 04/13] change(esp_pm): add dependencies on the rtc clock and rtc_time modules for power managment module --- components/esp_pm/Kconfig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/esp_pm/Kconfig b/components/esp_pm/Kconfig index ca843fff48..6986cccff5 100644 --- a/components/esp_pm/Kconfig +++ b/components/esp_pm/Kconfig @@ -1,12 +1,14 @@ menu "Power Management" config PM_SLEEP_FUNC_IN_IRAM - bool "Place Power Management module functions in IRAM" if IDF_TARGET_ESP32C2 - default y + bool "Place Power Management module functions in IRAM" + default n select PM_SLP_IRAM_OPT if SOC_LIGHT_SLEEP_SUPPORTED select PM_RTOS_IDLE_OPT if FREERTOS_USE_TICKLESS_IDLE select ESP_PERIPH_CTRL_FUNC_IN_IRAM select ESP_REGI2C_CTRL_FUNC_IN_IRAM + select RTC_CLK_FUNC_IN_IRAM + select RTC_TIME_FUNC_IN_IRAM config PM_ENABLE From d80819f6d713f0511fb32efe0a4c57a36c148c16 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 20 Nov 2025 11:23:14 +0800 Subject: [PATCH 05/13] change(esp_pm): add an option associated with flash auto suspend and make it dependent on the hardware support modules --- components/esp_hw_support/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 24c349b768..efaf9a418a 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -1,5 +1,14 @@ menu "Hardware Settings" + config ESP_HW_SUPPORT_FUNC_IN_IRAM + bool + default n if SPI_FLASH_AUTO_SUSPEND + default y + select ESP_PERIPH_CTRL_FUNC_IN_IRAM + select ESP_REGI2C_CTRL_FUNC_IN_IRAM + select RTC_CLK_FUNC_IN_IRAM + select RTC_TIME_FUNC_IN_IRAM + menu "Chip revision" # Insert chip-specific HW config orsource "./port/$IDF_TARGET/Kconfig.hw_support" From 9ed3a7a49abacb5d58593c2241d152fcab8c715b Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 20 Nov 2025 11:59:28 +0800 Subject: [PATCH 06/13] change(tools): disable place rtc clock and rtc time modules into iram for flash auto suspend test --- .../configs/sdkconfig.flash_auto_suspend_iram_reduction | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction b/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction index 0e1236fa14..09019098d4 100644 --- a/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction +++ b/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction @@ -72,6 +72,8 @@ CONFIG_ESP_REGI2C_CTRL_FUNC_IN_IRAM=n # System common CONFIG_ESP_PERIPH_CTRL_FUNC_IN_IRAM=n +CONFIG_RTC_CLK_FUNC_IN_IRAM=n +CONFIG_RTC_TIME_FUNC_IN_IRAM=n # Phy related options CONFIG_ESP_PHY_IRAM_OPT=n From c2de93eca926dd75a91e9f19e31dedeaf8d7e475 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Fri, 21 Nov 2025 15:31:25 +0800 Subject: [PATCH 07/13] change(example): sleep iram optimization support for esp_timer demo --- examples/system/esp_timer/main/esp_timer_example_main.c | 1 - examples/system/esp_timer/sdkconfig.defaults | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/system/esp_timer/main/esp_timer_example_main.c b/examples/system/esp_timer/main/esp_timer_example_main.c index 54183cb8a3..30da583018 100644 --- a/examples/system/esp_timer/main/esp_timer_example_main.c +++ b/examples/system/esp_timer/main/esp_timer_example_main.c @@ -71,7 +71,6 @@ void app_main(void) int64_t t2 = esp_timer_get_time(); ESP_LOGI(TAG, "Woke up from light sleep, time since boot: %lld us", t2); - // TODO: PM-232 assert(((t2 - t1 - 500000) < 1000) && ((t2 - t1 - 500000) > -2000)); #endif diff --git a/examples/system/esp_timer/sdkconfig.defaults b/examples/system/esp_timer/sdkconfig.defaults index c4a1e55cf8..3c7b19a00f 100644 --- a/examples/system/esp_timer/sdkconfig.defaults +++ b/examples/system/esp_timer/sdkconfig.defaults @@ -4,3 +4,6 @@ CONFIG_ESP_TIMER_PROFILING=y # NEWLIB_NANO_FORMAT is enabled by default on ESP32-C2 # This example needs 64-bit integer formatting, this is why this option is disabled CONFIG_NEWLIB_NANO_FORMAT=n + +# Put sleep related source code in IRAM +CONFIG_PM_SLP_IRAM_OPT=y From ea6b0ff2da51198dea50a6dfd3bbdfea7095901a Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Mon, 24 Nov 2025 17:49:32 +0800 Subject: [PATCH 08/13] fix(esp_hw_support): fix the esp32h2 sleep TG0 watchdog reset issue caused by power down the top domain --- components/esp_hw_support/sleep_modes.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index b7f54b6e1e..f7c21485ab 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -948,6 +948,9 @@ static esp_err_t FORCE_IRAM_ATTR esp_sleep_start_safe(uint32_t sleep_flags, uint #if SOC_PM_MMU_TABLE_RETENTION_WHEN_TOP_PD esp_sleep_mmu_retention(false); #endif +#if SOC_PM_RETENTION_SW_TRIGGER_REGDMA + sleep_retention_do_system_retention(false); +#endif #if CONFIG_IDF_TARGET_ESP32P4 && (CONFIG_ESP_REV_MIN_FULL == 300) sleep_flash_p4_rev3_workaround(); sleep_retention_do_extra_retention(false); @@ -1176,11 +1179,6 @@ static esp_err_t SLEEP_FN_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t cl cache_ll_invalidate_all(CACHE_LL_LEVEL_ALL, CACHE_TYPE_ALL, CACHE_LL_ID_ALL); #endif s_config.ccount_ticks_record = esp_cpu_get_cycle_count(); -#if SOC_PM_RETENTION_SW_TRIGGER_REGDMA - if (sleep_flags & PMU_SLEEP_PD_TOP) { - sleep_retention_do_system_retention(false); - } -#endif } misc_modules_wake_prepare(sleep_flags); } From bb5e96f5968c0beff415b238dfbce9fc497d4429 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Tue, 25 Nov 2025 12:13:16 +0800 Subject: [PATCH 09/13] fix(esp_hw_support): fix cpu lockup reset issue caused by i-cache illegal access during esp_restart --- components/esp_hw_support/linker.lf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index 676f475450..c5c80bdff1 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -13,8 +13,7 @@ entries: cpu: esp_cpu_compare_and_set (noflash) esp_memory_utils (noflash) clk_utils (noflash) - if PM_SLP_IRAM_OPT = y: - esp_clk_tree: esp_clk_tree_enable_src (noflash) + esp_clk_tree: esp_clk_tree_enable_src (noflash) if RTC_CLK_FUNC_IN_IRAM = y: rtc_clk (noflash) if IDF_TARGET_ESP32 = y: From 12d208bc1543df25417b75d28b0372f14758f7e4 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Tue, 25 Nov 2025 20:44:49 +0800 Subject: [PATCH 10/13] fix(esp_hw_support): fix esp32p4 HP_SYS_HP_WDT_RESET issue caused by cache invalid all --- components/esp_hw_support/sleep_modes.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index f7c21485ab..78c1162354 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1163,13 +1163,10 @@ static esp_err_t SLEEP_FN_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t cl if (!deep_sleep) { if (result == ESP_OK) { -#if !CONFIG_PM_SLP_IRAM_OPT && !CONFIG_IDF_TARGET_ESP32 +#if !CONFIG_PM_SLP_IRAM_OPT && !(CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32P4) #if CONFIG_SPIRAM -# if CONFIG_IDF_TARGET_ESP32P4 - cache_ll_writeback_all(CACHE_LL_LEVEL_ALL, CACHE_TYPE_DATA, CACHE_LL_ID_ALL); -# else + // TODO: PM-651 Cache_WriteBack_All(); -# endif #endif /* When the IRAM optimization for the sleep flow is disabled, all * cache contents are forcibly invalidated before exiting the sleep From bbba2471eaf177c20a0fae7718a9d0d7e939e00b Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 27 Nov 2025 17:52:28 +0800 Subject: [PATCH 11/13] change(esp_hw_support): update some sleep parameters when sleep iram optimization is disabled --- components/esp_hw_support/sleep_modes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 78c1162354..f71edb65b5 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -164,6 +164,10 @@ #elif CONFIG_IDF_TARGET_ESP32S3 #define DEFAULT_SLEEP_OUT_OVERHEAD_US (382) #define DEFAULT_HARDWARE_OUT_OVERHEAD_US (133) +# if !CONFIG_PM_SLP_IRAM_OPT + #undef DEFAULT_SLEEP_OUT_OVERHEAD_US + #define DEFAULT_SLEEP_OUT_OVERHEAD_US (8628) +# endif #elif CONFIG_IDF_TARGET_ESP32C3 #define DEFAULT_SLEEP_OUT_OVERHEAD_US (105) #define DEFAULT_HARDWARE_OUT_OVERHEAD_US (37) @@ -1163,6 +1167,7 @@ static esp_err_t SLEEP_FN_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t cl if (!deep_sleep) { if (result == ESP_OK) { + s_config.ccount_ticks_record = esp_cpu_get_cycle_count(); #if !CONFIG_PM_SLP_IRAM_OPT && !(CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32P4) #if CONFIG_SPIRAM // TODO: PM-651 @@ -1175,7 +1180,6 @@ static esp_err_t SLEEP_FN_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t cl * dynamically calculate the sleep adjustment time. */ cache_ll_invalidate_all(CACHE_LL_LEVEL_ALL, CACHE_TYPE_ALL, CACHE_LL_ID_ALL); #endif - s_config.ccount_ticks_record = esp_cpu_get_cycle_count(); } misc_modules_wake_prepare(sleep_flags); } From 52bc4e27fd0b8b3d5a25f9c6a538da2792a092b2 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Wed, 31 Dec 2025 15:17:10 +0800 Subject: [PATCH 12/13] change(example): change for pre-commit check pass of some Kconfig options are deprecated --- examples/system/esp_timer/sdkconfig.defaults | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/system/esp_timer/sdkconfig.defaults b/examples/system/esp_timer/sdkconfig.defaults index 3c7b19a00f..dfd208c65a 100644 --- a/examples/system/esp_timer/sdkconfig.defaults +++ b/examples/system/esp_timer/sdkconfig.defaults @@ -3,7 +3,7 @@ CONFIG_ESP_TIMER_PROFILING=y # NEWLIB_NANO_FORMAT is enabled by default on ESP32-C2 # This example needs 64-bit integer formatting, this is why this option is disabled -CONFIG_NEWLIB_NANO_FORMAT=n +CONFIG_LIBC_NEWLIB_NANO_FORMAT=n # Put sleep related source code in IRAM CONFIG_PM_SLP_IRAM_OPT=y From 1f95182e555bc7a00b40f8a56229cf33141f0c66 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Wed, 5 Nov 2025 20:53:49 +0800 Subject: [PATCH 13/13] fix(ld): fix cannot move location counter backwards (from 3fc88000 to 3fc87a00) --- components/esp_system/ld/esp32s3/sections.ld.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/esp_system/ld/esp32s3/sections.ld.in b/components/esp_system/ld/esp32s3/sections.ld.in index c6649ba3a6..f293976428 100644 --- a/components/esp_system/ld/esp32s3/sections.ld.in +++ b/components/esp_system/ld/esp32s3/sections.ld.in @@ -205,7 +205,8 @@ SECTIONS */ .dram0.dummy (NOLOAD): { - . = ORIGIN(dram0_0_seg) + MAX(_iram_end - _diram_i_start, 0); + /* MAX() uses unsigned long arithmetic. Add offset to prevent underflow when _iram_end < _diram_i_start */ + . = ORIGIN(dram0_0_seg) + MAX(_iram_end - _diram_i_start + (_diram_i_start - ORIGIN(iram0_0_seg)), (_diram_i_start - ORIGIN(iram0_0_seg))) - (_diram_i_start - ORIGIN(iram0_0_seg)); } > dram0_0_seg .dram0.data :