refactor(system): guard WDT with SoC capability macros

Wrap MWDT-related code under SOC_WDT_SUPPORTED so targets without a main
watchdog can compile.

Add SOC_RTC_WDT_SUPPORTED for RTC watchdog usage (bootloader, slow-clock
paths) and regenerate Kconfig.soc_caps.in. Bootloader RWDT setup stays
under SOC_RTC_WDT_SUPPORTED; MWDT flashboot teardown stays under
SOC_WDT_SUPPORTED.

ESP_INT_WDT, ESP_TASK_WDT_EN, and BOOTLOADER_WDT_ENABLE depend on
SOC_WDT_SUPPORTED where applicable. Build xt_wdt.c only when
SOC_XT_WDT_SUPPORTED. Provide no-op panic WDT helpers when
SOC_WDT_SUPPORTED is disabled.
This commit is contained in:
Meet Patel
2026-03-23 14:38:01 +05:30
parent a02fd7e33b
commit c4e2fe2c8b
76 changed files with 495 additions and 83 deletions
+1
View File
@@ -284,6 +284,7 @@ menu "Bootloader config"
config BOOTLOADER_WDT_ENABLE config BOOTLOADER_WDT_ENABLE
bool "Use RTC watchdog in start code" bool "Use RTC watchdog in start code"
depends on SOC_RTC_WDT_SUPPORTED
default y default y
help help
Tracks the execution time of startup code. Tracks the execution time of startup code.
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -16,8 +16,11 @@
#include "bootloader_common.h" #include "bootloader_common.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/efuse_hal.h" #include "hal/efuse_hal.h"
#include "hal/cache_hal.h" #include "hal/cache_hal.h"
#include "hal/mmu_hal.h" #include "hal/mmu_hal.h"
@@ -72,6 +75,7 @@ esp_err_t bootloader_check_bootloader_validity(void)
void bootloader_config_wdt(void) void bootloader_config_wdt(void)
{ {
#if SOC_RTC_WDT_SUPPORTED
/* /*
* At this point, the flashboot protection of RWDT and MWDT0 will have been * At this point, the flashboot protection of RWDT and MWDT0 will have been
* automatically enabled. We can disable flashboot protection as it's not * automatically enabled. We can disable flashboot protection as it's not
@@ -95,11 +99,16 @@ void bootloader_config_wdt(void)
wdt_hal_write_protect_enable(&rwdt_ctx); wdt_hal_write_protect_enable(&rwdt_ctx);
#endif #endif
//Disable MWDT0 flashboot protection. But only after we've enabled the RWDT first so that there's not gap in WDT protection. #endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
//Disable MWDT0 flashboot protection. When RTC WDT is present, run this after RWDT
//setup above so there is no gap in WDT protection during bootloader.
wdt_hal_context_t mwdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t mwdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&mwdt_ctx); wdt_hal_write_protect_disable(&mwdt_ctx);
wdt_hal_set_flashboot_en(&mwdt_ctx, false); wdt_hal_set_flashboot_en(&mwdt_ctx, false);
wdt_hal_write_protect_enable(&mwdt_ctx); wdt_hal_write_protect_enable(&mwdt_ctx);
#endif /* SOC_WDT_SUPPORTED */
} }
void bootloader_enable_random(void) void bootloader_enable_random(void)
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2019-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -24,6 +24,8 @@
#include "soc/gpio_sig_map.h" #include "soc/gpio_sig_map.h"
#include "soc/io_mux_reg.h" #include "soc/io_mux_reg.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "hal/gpio_hal.h" #include "hal/gpio_hal.h"
#include "hal/mmu_hal.h" #include "hal/mmu_hal.h"
#include "xtensa/config/core.h" #include "xtensa/config/core.h"
@@ -88,6 +90,7 @@ static inline esp_err_t bootloader_check_rated_cpu_clock(void)
return ESP_OK; return ESP_OK;
} }
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
//We do not reset core1 info here because it didn't work before cpu1 was up. So we put it into call_start_cpu1. //We do not reset core1 info here because it didn't work before cpu1 was up. So we put it into call_start_cpu1.
@@ -168,6 +171,7 @@ static void bootloader_check_wdt_reset(void)
} }
wdt_reset_cpu0_info_enable(); wdt_reset_cpu0_info_enable();
} }
#endif // SOC_RTC_WDT_SUPPORTED
esp_err_t bootloader_init(void) esp_err_t bootloader_init(void)
{ {
@@ -240,10 +244,14 @@ esp_err_t bootloader_init(void)
} }
#endif // #if !CONFIG_APP_BUILD_TYPE_RAM #endif // #if !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
return ret; return ret;
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,6 +18,8 @@
#include "soc/assist_debug_reg.h" #include "soc/assist_debug_reg.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/extmem_reg.h" #include "soc/extmem_reg.h"
#include "soc/system_reg.h" #include "soc/system_reg.h"
#include "esp32c2/rom/ets_sys.h" #include "esp32c2/rom/ets_sys.h"
@@ -39,6 +41,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32c2"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32c2");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(SYSTEM_CPU_PERI_CLK_EN_REG, SYSTEM_CLK_EN_ASSIST_DEBUG); REG_SET_BIT(SYSTEM_CPU_PERI_CLK_EN_REG, SYSTEM_CLK_EN_ASSIST_DEBUG);
@@ -75,6 +78,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN); REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN);
REG_WRITE(RTC_CNTL_SWD_WPROTECT_REG, 0); REG_WRITE(RTC_CNTL_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_ana_reset_config(void) static inline void bootloader_ana_reset_config(void)
{ {
@@ -89,7 +93,9 @@ esp_err_t bootloader_init(void)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -135,10 +141,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
return ret; return ret;
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -19,6 +19,8 @@
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_reg.h"
#include "soc/soc_caps.h"
#include "soc/extmem_reg.h" #include "soc/extmem_reg.h"
#include "soc/system_reg.h" #include "soc/system_reg.h"
#include "soc/chip_revision.h" #include "soc/chip_revision.h"
@@ -44,6 +46,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32c3"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32c3");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(SYSTEM_CPU_PERI_CLK_EN_REG, SYSTEM_CLK_EN_ASSIST_DEBUG); REG_SET_BIT(SYSTEM_CPU_PERI_CLK_EN_REG, SYSTEM_CLK_EN_ASSIST_DEBUG);
@@ -80,6 +83,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN); REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN);
REG_WRITE(RTC_CNTL_SWD_WPROTECT_REG, 0); REG_WRITE(RTC_CNTL_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -128,7 +132,9 @@ esp_err_t bootloader_init(void)
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -179,10 +185,14 @@ esp_err_t bootloader_init(void)
} }
#endif //#if !CONFIG_APP_BUILD_TYPE_RAM #endif //#if !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -14,6 +14,7 @@
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#include "esp_rom_spiflash.h" #include "esp_rom_spiflash.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "soc/gpio_sig_map.h" #include "soc/gpio_sig_map.h"
#include "soc/io_mux_reg.h" #include "soc/io_mux_reg.h"
#include "soc/assist_debug_reg.h" #include "soc/assist_debug_reg.h"
@@ -45,6 +46,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32c5"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32c5");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN); REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN);
@@ -81,6 +83,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -113,7 +116,9 @@ esp_err_t bootloader_init(void)
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -164,10 +169,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,6 +18,8 @@
#include "soc/assist_debug_reg.h" #include "soc/assist_debug_reg.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/extmem_reg.h" #include "soc/extmem_reg.h"
#include "soc/pcr_reg.h" #include "soc/pcr_reg.h"
#include "esp32c6/rom/ets_sys.h" #include "esp32c6/rom/ets_sys.h"
@@ -46,6 +48,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32c6"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32c6");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN); REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN);
@@ -82,6 +85,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -112,7 +116,9 @@ esp_err_t bootloader_init(void)
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -163,10 +169,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,6 +18,8 @@
#include "soc/assist_debug_reg.h" #include "soc/assist_debug_reg.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/cache_reg.h" #include "soc/cache_reg.h"
#include "soc/pcr_reg.h" #include "soc/pcr_reg.h"
#include "esp32c61/rom/ets_sys.h" #include "esp32c61/rom/ets_sys.h"
@@ -46,6 +48,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32c61"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32c61");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN); REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN);
@@ -82,6 +85,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -104,7 +108,9 @@ esp_err_t bootloader_init(void)
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -155,10 +161,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,6 +18,8 @@
#include "soc/assist_debug_reg.h" #include "soc/assist_debug_reg.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/extmem_reg.h" #include "soc/extmem_reg.h"
#include "soc/pcr_reg.h" #include "soc/pcr_reg.h"
#include "esp32h2/rom/ets_sys.h" #include "esp32h2/rom/ets_sys.h"
@@ -45,6 +47,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32h2"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32h2");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN); REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN);
@@ -81,6 +84,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -109,7 +113,9 @@ esp_err_t bootloader_init(void)
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -161,9 +167,13 @@ esp_err_t bootloader_init(void)
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happened // check whether a WDT reset happened
#if SOC_RTC_WDT_SUPPORTED
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,6 +18,8 @@
#include "soc/assist_debug_reg.h" #include "soc/assist_debug_reg.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/cache_reg.h" #include "soc/cache_reg.h"
#include "soc/pcr_reg.h" #include "soc/pcr_reg.h"
#include "rom/ets_sys.h" #include "rom/ets_sys.h"
@@ -44,6 +46,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32h21"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32h21");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN); REG_SET_BIT(PCR_ASSIST_CONF_REG, PCR_ASSIST_CLK_EN);
@@ -80,6 +83,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -106,7 +110,9 @@ esp_err_t bootloader_init(void)
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -157,10 +163,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -16,6 +16,8 @@
#include "soc/gpio_sig_map.h" #include "soc/gpio_sig_map.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/cache_reg.h" #include "soc/cache_reg.h"
#include "soc/io_mux_reg.h" #include "soc/io_mux_reg.h"
#include "soc/pcr_reg.h" #include "soc/pcr_reg.h"
@@ -42,6 +44,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32h4"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32h4");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
assist_debug_ll_enable_bus_clock(0, true); assist_debug_ll_enable_bus_clock(0, true);
@@ -77,6 +80,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -120,7 +124,9 @@ esp_err_t bootloader_init(void)
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -172,10 +178,14 @@ esp_err_t bootloader_init(void)
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
bootloader_config_dcache(); bootloader_config_dcache();
bootloader_config_icache1(); bootloader_config_icache1();
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,6 +18,8 @@
#include "soc/assist_debug_reg.h" #include "soc/assist_debug_reg.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/cache_reg.h" #include "soc/cache_reg.h"
#include "esp32p4/rom/ets_sys.h" #include "esp32p4/rom/ets_sys.h"
#include "esp32p4/rom/spi_flash.h" #include "esp32p4/rom/spi_flash.h"
@@ -52,6 +54,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32p4"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32p4");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
_assist_debug_ll_enable_bus_clock(0, true); _assist_debug_ll_enable_bus_clock(0, true);
@@ -90,6 +93,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(LP_WDT_SWD_CONFIG_REG, LP_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(LP_WDT_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_hardware_init(void) static inline void bootloader_hardware_init(void)
{ {
@@ -129,7 +133,9 @@ esp_err_t bootloader_init(void)
bootloader_hardware_init(); bootloader_hardware_init();
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -181,10 +187,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2019-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -33,12 +33,15 @@
#include "soc/extmem_reg.h" #include "soc/extmem_reg.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_reg.h"
#include "soc/soc_caps.h"
#include "esp_efuse.h" #include "esp_efuse.h"
#include "hal/mmu_hal.h" #include "hal/mmu_hal.h"
#include "hal/cache_hal.h" #include "hal/cache_hal.h"
ESP_LOG_ATTR_TAG(TAG, "boot.esp32s2"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32s2");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
DPORT_REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_ASSIST_DEBUG); DPORT_REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_ASSIST_DEBUG);
@@ -100,11 +103,14 @@ static void bootloader_super_wdt_auto_feed(void)
{ {
REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN); REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN);
} }
#endif // SOC_RTC_WDT_SUPPORTED
esp_err_t bootloader_init(void) esp_err_t bootloader_init(void)
{ {
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// protect memory region // protect memory region
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
@@ -163,10 +169,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,6 +18,8 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_reg.h"
#include "soc/extmem_reg.h" #include "soc/extmem_reg.h"
#include "soc/soc_caps.h"
#include "esp_rom_gpio.h" #include "esp_rom_gpio.h"
#include "esp_rom_efuse.h" #include "esp_rom_efuse.h"
@@ -45,6 +47,7 @@
ESP_LOG_ATTR_TAG(TAG, "boot.esp32s3"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32s3");
#if SOC_RTC_WDT_SUPPORTED
static void wdt_reset_cpu0_info_enable(void) static void wdt_reset_cpu0_info_enable(void)
{ {
REG_SET_BIT(SYSTEM_CPU_PERI_CLK_EN_REG, SYSTEM_CLK_EN_ASSIST_DEBUG); REG_SET_BIT(SYSTEM_CPU_PERI_CLK_EN_REG, SYSTEM_CLK_EN_ASSIST_DEBUG);
@@ -128,6 +131,7 @@ static void bootloader_super_wdt_auto_feed(void)
REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN); REG_SET_BIT(RTC_CNTL_SWD_CONF_REG, RTC_CNTL_SWD_AUTO_FEED_EN);
REG_WRITE(RTC_CNTL_SWD_WPROTECT_REG, 0); REG_WRITE(RTC_CNTL_SWD_WPROTECT_REG, 0);
} }
#endif // SOC_RTC_WDT_SUPPORTED
static inline void bootloader_ana_reset_config(void) static inline void bootloader_ana_reset_config(void)
{ {
@@ -147,7 +151,9 @@ esp_err_t bootloader_init(void)
#endif // XCHAL_ERRATUM_572 #endif // XCHAL_ERRATUM_572
bootloader_ana_reset_config(); bootloader_ana_reset_config();
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -202,10 +208,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
bootloader_check_wdt_reset(); bootloader_check_wdt_reset();
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
return ret; return ret;
@@ -11,6 +11,7 @@
#include "flash_qio_mode.h" #include "flash_qio_mode.h"
#include "bootloader_common.h" #include "bootloader_common.h"
#include "bootloader_init.h" #include "bootloader_init.h"
#include "soc/soc_caps.h"
#include "bootloader_clock.h" #include "bootloader_clock.h"
#include "bootloader_flash_config.h" #include "bootloader_flash_config.h"
#include "bootloader_mem.h" #include "bootloader_mem.h"
@@ -18,24 +19,30 @@
#include "bootloader_flash_priv.h" #include "bootloader_flash_priv.h"
#include "bootloader_soc.h" #include "bootloader_soc.h"
#include "esp_private/bootloader_flash_internal.h" #include "esp_private/bootloader_flash_internal.h"
#if SOC_RTC_WDT_SUPPORTED
#include "soc/rtc_wdt_reg.h" #include "soc/rtc_wdt_reg.h"
#include "hal/rwdt_ll.h" #include "hal/rwdt_ll.h"
#endif
ESP_LOG_ATTR_TAG(TAG, "boot.esp32s31"); ESP_LOG_ATTR_TAG(TAG, "boot.esp32s31");
#if SOC_RTC_WDT_SUPPORTED
static void bootloader_super_wdt_auto_feed(void) static void bootloader_super_wdt_auto_feed(void)
{ {
REG_WRITE(RTC_WDT_SWD_WPROTECT_REG, RTC_WDT_SWD_WKEY_VALUE); REG_WRITE(RTC_WDT_SWD_WPROTECT_REG, RTC_WDT_SWD_WKEY_VALUE);
REG_SET_BIT(RTC_WDT_SWD_CONFIG_REG, RTC_WDT_SWD_AUTO_FEED_EN); REG_SET_BIT(RTC_WDT_SWD_CONFIG_REG, RTC_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(RTC_WDT_SWD_WPROTECT_REG, 0); REG_WRITE(RTC_WDT_SWD_WPROTECT_REG, 0);
} }
#endif
esp_err_t bootloader_init(void) esp_err_t bootloader_init(void)
{ {
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
// bootloader_hardware_init(); // TODO: IDF-14696 // bootloader_hardware_init(); // TODO: IDF-14696
#if SOC_RTC_WDT_SUPPORTED
bootloader_super_wdt_auto_feed(); bootloader_super_wdt_auto_feed();
#endif
// In RAM_APP, memory will be initialized in `call_start_cpu0` // In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM #if !CONFIG_APP_BUILD_TYPE_RAM
@@ -89,10 +96,14 @@ esp_err_t bootloader_init(void)
} }
#endif // !CONFIG_APP_BUILD_TYPE_RAM #endif // !CONFIG_APP_BUILD_TYPE_RAM
#if SOC_RTC_WDT_SUPPORTED
// check whether a WDT reset happened // check whether a WDT reset happened
// bootloader_check_wdt_reset(); // TODO: IDF-14678 // bootloader_check_wdt_reset(); // TODO: IDF-14678
#endif
#if SOC_RTC_WDT_SUPPORTED || SOC_WDT_SUPPORTED
// config WDT // config WDT
bootloader_config_wdt(); bootloader_config_wdt();
#endif
// enable RNG early entropy source // enable RNG early entropy source
bootloader_enable_random(); bootloader_enable_random();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -14,7 +14,9 @@
#include "esp_efuse.h" #include "esp_efuse.h"
#include "esp_efuse_table.h" #include "esp_efuse_table.h"
#include "esp_log.h" #include "esp_log.h"
#if SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
@@ -675,12 +677,16 @@ esp_err_t esp_flash_encrypt_region(uint32_t src_addr, size_t data_length)
return ESP_FAIL; return ESP_FAIL;
} }
#if SOC_RTC_WDT_SUPPORTED
wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
#endif
for (size_t i = 0; i < data_length; i += FLASH_SECTOR_SIZE) { for (size_t i = 0; i < data_length; i += FLASH_SECTOR_SIZE) {
#if SOC_RTC_WDT_SUPPORTED
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
wdt_hal_feed(&rtc_wdt_ctx); wdt_hal_feed(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif
uint32_t sec_start = i + src_addr; uint32_t sec_start = i + src_addr;
err = bootloader_flash_read(sec_start, buf, FLASH_SECTOR_SIZE, false); err = bootloader_flash_read(sec_start, buf, FLASH_SECTOR_SIZE, false);
if (err != ESP_OK) { if (err != ESP_OK) {
+18
View File
@@ -20,7 +20,9 @@
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "soc/interrupts.h" #include "soc/interrupts.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#if GDBSTUB_QXFER_FEATURES_ENABLED #if GDBSTUB_QXFER_FEATURES_ENABLED
#define GDBSTUB_QXFER_SUPPORTED_STR ";qXfer:features:read+" #define GDBSTUB_QXFER_SUPPORTED_STR ";qXfer:features:read+"
@@ -125,26 +127,35 @@ static uint32_t gdbstub_hton(uint32_t i)
return __builtin_bswap32(i); return __builtin_bswap32(i);
} }
#if SOC_RTC_WDT_SUPPORTED
static wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); static wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
static bool rtc_wdt_ctx_enabled = false; static bool rtc_wdt_ctx_enabled = false;
#endif
#if SOC_WDT_SUPPORTED
static wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; static wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
static bool wdt0_context_enabled = false; static bool wdt0_context_enabled = false;
#if TIMG_LL_GET(INST_NUM) >= 2 #if TIMG_LL_GET(INST_NUM) >= 2
static wdt_hal_context_t wdt1_context = {.inst = WDT_MWDT1, .mwdt_dev = &TIMERG1}; static wdt_hal_context_t wdt1_context = {.inst = WDT_MWDT1, .mwdt_dev = &TIMERG1};
static bool wdt1_context_enabled = false; static bool wdt1_context_enabled = false;
#endif // TIMG_LL_GET(INST_NUM) #endif // TIMG_LL_GET(INST_NUM)
#endif // SOC_WDT_SUPPORTED
/** /**
* Disable all enabled WDTs * Disable all enabled WDTs
*/ */
static inline void disable_all_wdts(void) static inline void disable_all_wdts(void)
{ {
#if SOC_WDT_SUPPORTED
wdt0_context_enabled = wdt_hal_is_enabled(&wdt0_context); wdt0_context_enabled = wdt_hal_is_enabled(&wdt0_context);
#if TIMG_LL_GET(INST_NUM) >= 2 #if TIMG_LL_GET(INST_NUM) >= 2
wdt1_context_enabled = wdt_hal_is_enabled(&wdt1_context); wdt1_context_enabled = wdt_hal_is_enabled(&wdt1_context);
#endif #endif
#endif // SOC_WDT_SUPPORTED
#if SOC_RTC_WDT_SUPPORTED
rtc_wdt_ctx_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx); rtc_wdt_ctx_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx);
#endif
#if SOC_WDT_SUPPORTED
/*Task WDT is the Main Watchdog Timer of Timer Group 0 */ /*Task WDT is the Main Watchdog Timer of Timer Group 0 */
if (true == wdt0_context_enabled) { if (true == wdt0_context_enabled) {
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -162,13 +173,16 @@ static inline void disable_all_wdts(void)
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
} }
#endif // TIMG_LL_GET(INST_NUM) >= 2 #endif // TIMG_LL_GET(INST_NUM) >= 2
#endif // SOC_WDT_SUPPORTED
#if SOC_RTC_WDT_SUPPORTED
if (true == rtc_wdt_ctx_enabled) { if (true == rtc_wdt_ctx_enabled) {
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
wdt_hal_disable(&rtc_wdt_ctx); wdt_hal_disable(&rtc_wdt_ctx);
wdt_hal_feed(&rtc_wdt_ctx); wdt_hal_feed(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
} }
#endif // SOC_RTC_WDT_SUPPORTED
} }
/** /**
@@ -176,6 +190,7 @@ static inline void disable_all_wdts(void)
*/ */
static inline void enable_all_wdts(void) static inline void enable_all_wdts(void)
{ {
#if SOC_WDT_SUPPORTED
/* Task WDT is the Main Watchdog Timer of Timer Group 0 */ /* Task WDT is the Main Watchdog Timer of Timer Group 0 */
if (false == wdt0_context_enabled) { if (false == wdt0_context_enabled) {
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -190,12 +205,15 @@ static inline void enable_all_wdts(void)
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
} }
#endif // TIMG_LL_GET(INST_NUM) >= 2 #endif // TIMG_LL_GET(INST_NUM) >= 2
#endif // SOC_WDT_SUPPORTED
#if SOC_RTC_WDT_SUPPORTED
if (false == rtc_wdt_ctx_enabled) { if (false == rtc_wdt_ctx_enabled) {
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
wdt_hal_enable(&rtc_wdt_ctx); wdt_hal_enable(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
} }
#endif // SOC_RTC_WDT_SUPPORTED
} }
int getActiveTaskNum(void); int getActiveTaskNum(void);
+18 -4
View File
@@ -68,7 +68,9 @@
#include "hal/cache_ll.h" #include "hal/cache_ll.h"
#include "hal/clk_tree_ll.h" #include "hal/clk_tree_ll.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED || SOC_SLEEP_TGWDT_STOP_WORKAROUND
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_hal.h" #include "hal/uart_hal.h"
#if SOC_TOUCH_SENSOR_SUPPORTED #if SOC_TOUCH_SENSOR_SUPPORTED
#include "hal/touch_sens_hal.h" #include "hal/touch_sens_hal.h"
@@ -367,7 +369,7 @@ void esp_sleep_overhead_out_time_refresh(void)
static uint32_t get_power_down_flags(void); static uint32_t get_power_down_flags(void);
static uint32_t get_sleep_flags(uint32_t pd_flags, bool deepsleep); static uint32_t get_sleep_flags(uint32_t pd_flags, bool deepsleep);
static uint32_t get_sleep_clock_icg_flags(void); static uint32_t get_sleep_clock_icg_flags(void);
#if CONFIG_ESP_SLEEP_ENABLE_RTC_WDT_IN_SLEEP #if CONFIG_ESP_SLEEP_ENABLE_RTC_WDT_IN_SLEEP && SOC_RTC_WDT_SUPPORTED
static uint32_t get_sleep_rtc_wdt_timeout(uint64_t sleep_duration); static uint32_t get_sleep_rtc_wdt_timeout(uint64_t sleep_duration);
static uint32_t calc_sleep_slow_clk_required_cycles(uint32_t timeout, uint32_t rtc_slow_clk_cal_period); static uint32_t calc_sleep_slow_clk_required_cycles(uint32_t timeout, uint32_t rtc_slow_clk_cal_period);
#endif #endif
@@ -740,7 +742,7 @@ static SLEEP_FN_ATTR void misc_modules_wake_prepare(uint32_t sleep_flags)
pvt_func_enable(true); pvt_func_enable(true);
#endif #endif
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP #if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_WDT_SUPPORTED
if (sleep_flags & PMU_SLEEP_PD_TOP) { if (sleep_flags & PMU_SLEEP_PD_TOP) {
// There is no driver to manage the flashboot watchdog, and it is definitely be in off state when // There is no driver to manage the flashboot watchdog, and it is definitely be in off state when
// the system is running, after waking up from pd_top sleep, shut it down by software here. // the system is running, after waking up from pd_top sleep, shut it down by software here.
@@ -796,6 +798,7 @@ static SLEEP_FN_ATTR void misc_modules_wake_prepare(uint32_t sleep_flags)
*/ */
static SLEEP_FN_ATTR void sleep_rtc_wdt_prepare(bool enable) static SLEEP_FN_ATTR void sleep_rtc_wdt_prepare(bool enable)
{ {
#if SOC_RTC_WDT_SUPPORTED
wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
if (enable) { if (enable) {
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -816,6 +819,9 @@ static SLEEP_FN_ATTR void sleep_rtc_wdt_prepare(bool enable)
wdt_hal_disable(&rtc_wdt_ctx); wdt_hal_disable(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
} }
#else
(void)enable;
#endif /* SOC_RTC_WDT_SUPPORTED */
} }
static SLEEP_FN_ATTR void sleep_low_power_clock_calibration(bool is_dslp) static SLEEP_FN_ATTR void sleep_low_power_clock_calibration(bool is_dslp)
@@ -1288,6 +1294,7 @@ static esp_err_t FORCE_IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
s_config.sleep_time_adjustment = DEEP_SLEEP_TIME_OVERHEAD_US; s_config.sleep_time_adjustment = DEEP_SLEEP_TIME_OVERHEAD_US;
// Safety net: enable WDT in case exit from deep sleep fails // Safety net: enable WDT in case exit from deep sleep fails
#if SOC_RTC_WDT_SUPPORTED
wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
bool rtc_wdt_was_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx); // If WDT was enabled in the user code, then do not change it here. bool rtc_wdt_was_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx); // If WDT was enabled in the user code, then do not change it here.
if (!rtc_wdt_was_enabled) { if (!rtc_wdt_was_enabled) {
@@ -1295,6 +1302,7 @@ static esp_err_t FORCE_IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
} else { } else {
ESP_EARLY_LOGW(TAG, "RTC WDT is enabled and will not be reconfigured again!"); ESP_EARLY_LOGW(TAG, "RTC WDT is enabled and will not be reconfigured again!");
} }
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_PMU_SUPPORTED #if SOC_PMU_SUPPORTED
uint32_t force_pd_flags = PMU_SLEEP_PD_TOP | PMU_SLEEP_PD_VDDSDIO | PMU_SLEEP_PD_MODEM | PMU_SLEEP_PD_HP_PERIPH \ uint32_t force_pd_flags = PMU_SLEEP_PD_TOP | PMU_SLEEP_PD_VDDSDIO | PMU_SLEEP_PD_MODEM | PMU_SLEEP_PD_HP_PERIPH \
@@ -1342,9 +1350,11 @@ static esp_err_t FORCE_IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
ESP_INFINITE_LOOP(); ESP_INFINITE_LOOP();
} }
// Never returns here, except that the sleep is rejected. // Never returns here, except that the sleep is rejected.
#if SOC_RTC_WDT_SUPPORTED
if (!rtc_wdt_was_enabled) { if (!rtc_wdt_was_enabled) {
sleep_rtc_wdt_prepare(false); sleep_rtc_wdt_prepare(false);
} }
#endif /* SOC_RTC_WDT_SUPPORTED */
#if CONFIG_ESP_INT_WDT && CONFIG_ESP32_ECO3_CACHE_LOCK_FIX #if CONFIG_ESP_INT_WDT && CONFIG_ESP32_ECO3_CACHE_LOCK_FIX
// Configure WDT to use livelock workaround timeout after releasing other CPU // Configure WDT to use livelock workaround timeout after releasing other CPU
@@ -1636,6 +1646,7 @@ esp_err_t esp_light_sleep_start(void)
periph_inform_out_light_sleep_overhead(s_config.sleep_time_adjustment - sleep_time_overhead_in); periph_inform_out_light_sleep_overhead(s_config.sleep_time_adjustment - sleep_time_overhead_in);
// Safety net: enable WDT in case exit from light sleep fails // Safety net: enable WDT in case exit from light sleep fails
#if SOC_RTC_WDT_SUPPORTED
wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
bool rtc_wdt_was_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx); // If WDT was enabled in the user code, then do not change it here. bool rtc_wdt_was_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx); // If WDT was enabled in the user code, then do not change it here.
if (!rtc_wdt_was_enabled) { if (!rtc_wdt_was_enabled) {
@@ -1643,6 +1654,7 @@ esp_err_t esp_light_sleep_start(void)
} else { } else {
ESP_EARLY_LOGW(TAG, "RTC WDT is enabled and will not be reconfigured again!"); ESP_EARLY_LOGW(TAG, "RTC WDT is enabled and will not be reconfigured again!");
} }
#endif /* SOC_RTC_WDT_SUPPORTED */
esp_err_t err = ESP_OK; esp_err_t err = ESP_OK;
int64_t final_sleep_duration_us = (int64_t)s_config.sleep_duration - (int64_t)s_config.sleep_time_adjustment; int64_t final_sleep_duration_us = (int64_t)s_config.sleep_duration - (int64_t)s_config.sleep_time_adjustment;
@@ -1724,9 +1736,11 @@ esp_err_t esp_light_sleep_start(void)
#endif #endif
#endif #endif
#if SOC_RTC_WDT_SUPPORTED
if (!rtc_wdt_was_enabled) { if (!rtc_wdt_was_enabled) {
sleep_rtc_wdt_prepare(false); sleep_rtc_wdt_prepare(false);
} }
#endif /* SOC_RTC_WDT_SUPPORTED */
#if CONFIG_ESP_TASK_WDT_USE_ESP_TIMER #if CONFIG_ESP_TASK_WDT_USE_ESP_TIMER
/* Restart the Task Watchdog timer as it was stopped before sleeping. */ /* Restart the Task Watchdog timer as it was stopped before sleeping. */
@@ -3016,7 +3030,7 @@ static SLEEP_FN_ATTR uint32_t get_sleep_flags(uint32_t sleep_flags, bool deepsle
} }
#endif #endif
#if CONFIG_ESP_SLEEP_ENABLE_RTC_WDT_IN_SLEEP #if CONFIG_ESP_SLEEP_ENABLE_RTC_WDT_IN_SLEEP && SOC_RTC_WDT_SUPPORTED
if (s_config.wakeup_triggers & RTC_TIMER_TRIG_EN) { if (s_config.wakeup_triggers & RTC_TIMER_TRIG_EN) {
sleep_flags |= RTC_SLEEP_USE_RTC_WDT; sleep_flags |= RTC_SLEEP_USE_RTC_WDT;
} else { } else {
@@ -3075,7 +3089,7 @@ static SLEEP_FN_ATTR uint32_t get_sleep_clock_icg_flags(void)
return clk_flags; return clk_flags;
} }
#if CONFIG_ESP_SLEEP_ENABLE_RTC_WDT_IN_SLEEP #if CONFIG_ESP_SLEEP_ENABLE_RTC_WDT_IN_SLEEP && SOC_RTC_WDT_SUPPORTED
/* TODO: PM-609 */ /* TODO: PM-609 */
/* Calculate drift cycles of rtc slow clock in long-term working scenarios. */ /* Calculate drift cycles of rtc slow clock in long-term working scenarios. */
static SLEEP_FN_ATTR uint32_t calc_sleep_slow_clk_required_cycles(uint32_t timeout, uint32_t rtc_slow_clk_cal_period) static SLEEP_FN_ATTR uint32_t calc_sleep_slow_clk_required_cycles(uint32_t timeout, uint32_t rtc_slow_clk_cal_period)
+7 -3
View File
@@ -37,15 +37,19 @@ else()
"esp_ipc.c" "esp_ipc.c"
"esp_err.c" "esp_err.c"
"freertos_hooks.c" "freertos_hooks.c"
"int_wdt.c"
"panic.c" "panic.c"
"esp_system.c" "esp_system.c"
"startup.c" "startup.c"
"startup_funcs.c" "startup_funcs.c"
"system_time.c" "system_time.c"
"stack_check.c" "stack_check.c"
"ubsan.c" "ubsan.c")
"xt_wdt.c") if(CONFIG_SOC_WDT_SUPPORTED)
list(APPEND srcs "int_wdt.c")
endif()
if(CONFIG_SOC_XT_WDT_SUPPORTED)
list(APPEND srcs "xt_wdt.c")
endif()
if(CONFIG_ESP_TASK_WDT_EN) if(CONFIG_ESP_TASK_WDT_EN)
list(APPEND srcs "task_wdt/task_wdt.c") list(APPEND srcs "task_wdt/task_wdt.c")
+2
View File
@@ -269,6 +269,7 @@ menu "ESP System Settings"
config ESP_INT_WDT config ESP_INT_WDT
bool "Interrupt watchdog" bool "Interrupt watchdog"
depends on SOC_WDT_SUPPORTED
default y default y
help help
This watchdog timer can detect if the FreeRTOS tick interrupt has not been called for a certain time, This watchdog timer can detect if the FreeRTOS tick interrupt has not been called for a certain time,
@@ -294,6 +295,7 @@ menu "ESP System Settings"
config ESP_TASK_WDT_EN config ESP_TASK_WDT_EN
bool "Enable Task Watchdog Timer" bool "Enable Task Watchdog Timer"
depends on SOC_WDT_SUPPORTED
default y default y
help help
The Task Watchdog Timer can be used to make sure individual tasks are still The Task Watchdog Timer can be used to make sure individual tasks are still
+38 -2
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -16,8 +16,10 @@
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "hal/timer_hal.h" #include "hal/timer_hal.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_types.h" #include "hal/wdt_types.h"
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/esp_int_wdt.h" #include "esp_private/esp_int_wdt.h"
#include "esp_private/panic_internal.h" #include "esp_private/panic_internal.h"
@@ -72,7 +74,9 @@
bool g_panic_abort = false; bool g_panic_abort = false;
char *g_panic_abort_details = NULL; char *g_panic_abort_details = NULL;
#if SOC_RTC_WDT_SUPPORTED
static wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); static wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
#endif
static uint32_t DRAM_ATTR g_panic_entry_count[CONFIG_FREERTOS_NUMBER_OF_CORES] = {0}; // Number of times panic handler has been entered per core since multiple cores can enter the panic handler simultaneously static uint32_t DRAM_ATTR g_panic_entry_count[CONFIG_FREERTOS_NUMBER_OF_CORES] = {0}; // Number of times panic handler has been entered per core since multiple cores can enter the panic handler simultaneously
@@ -177,6 +181,7 @@ static void print_abort_details(const void *f)
/********************** Panic handler watchdog timer functions **********************/ /********************** Panic handler watchdog timer functions **********************/
#if SOC_WDT_SUPPORTED
/* This function disables the Timer Group WDTs */ /* This function disables the Timer Group WDTs */
void esp_panic_handler_disable_timg_wdts(void) void esp_panic_handler_disable_timg_wdts(void)
{ {
@@ -192,7 +197,13 @@ void esp_panic_handler_disable_timg_wdts(void)
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* TIMG_LL_GET(INST_NUM) >= 2 */ #endif /* TIMG_LL_GET(INST_NUM) >= 2 */
} }
#else /* SOC_WDT_SUPPORTED */
void esp_panic_handler_disable_timg_wdts(void)
{
}
#endif /* SOC_WDT_SUPPORTED */
#if SOC_RTC_WDT_SUPPORTED
/* This function enables the RTC WDT with the given timeout in milliseconds */ /* This function enables the RTC WDT with the given timeout in milliseconds */
void esp_panic_handler_enable_rtc_wdt(uint32_t timeout_ms) void esp_panic_handler_enable_rtc_wdt(uint32_t timeout_ms)
{ {
@@ -204,7 +215,14 @@ void esp_panic_handler_enable_rtc_wdt(uint32_t timeout_ms)
wdt_hal_enable(&rtc_wdt_ctx); wdt_hal_enable(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
} }
#else /* SOC_RTC_WDT_SUPPORTED */
void esp_panic_handler_enable_rtc_wdt(uint32_t timeout_ms)
{
(void)timeout_ms;
}
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
/* Feed the watchdogs if they are enabled and if we are not already in the panic handler */ /* Feed the watchdogs if they are enabled and if we are not already in the panic handler */
void esp_panic_handler_feed_wdts(void) void esp_panic_handler_feed_wdts(void)
{ {
@@ -217,6 +235,7 @@ void esp_panic_handler_feed_wdts(void)
return; return;
} }
#if SOC_WDT_SUPPORTED
// Feed Timer Group 0 WDT // Feed Timer Group 0 WDT
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
if (wdt_hal_is_enabled(&wdt0_context)) { if (wdt_hal_is_enabled(&wdt0_context)) {
@@ -234,26 +253,43 @@ void esp_panic_handler_feed_wdts(void)
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
} }
#endif /* TIMG_LL_GET(INST_NUM) >= 2 */ #endif /* TIMG_LL_GET(INST_NUM) >= 2 */
#endif /* SOC_WDT_SUPPORTED */
#if SOC_RTC_WDT_SUPPORTED
// Feed RTC WDT // Feed RTC WDT
if (wdt_hal_is_enabled(&rtc_wdt_ctx)) { if (wdt_hal_is_enabled(&rtc_wdt_ctx)) {
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
wdt_hal_feed(&rtc_wdt_ctx); wdt_hal_feed(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
} }
#endif /* SOC_RTC_WDT_SUPPORTED */
} }
#else /* SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED */
void esp_panic_handler_feed_wdts(void)
{
}
#endif /* SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
/* This function disables all the watchdogs */ /* This function disables all the watchdogs */
static inline void disable_all_wdts(void) static inline void disable_all_wdts(void)
{ {
#if SOC_WDT_SUPPORTED
//Disable Timer Group WDTs //Disable Timer Group WDTs
esp_panic_handler_disable_timg_wdts(); esp_panic_handler_disable_timg_wdts();
#endif /* SOC_WDT_SUPPORTED */
#if SOC_RTC_WDT_SUPPORTED
//Disable RTC WDT //Disable RTC WDT
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
wdt_hal_disable(&rtc_wdt_ctx); wdt_hal_disable(&rtc_wdt_ctx);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
} }
#else /* SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED */
static inline void disable_all_wdts(void)
{
}
#endif /* SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED */
/* IRAM-only halt stub: reset modules, then loop */ /* IRAM-only halt stub: reset modules, then loop */
void IRAM_ATTR esp_panic_handler_reset_modules_on_exit_and_halt(void) void IRAM_ATTR esp_panic_handler_reset_modules_on_exit_and_halt(void)
+7 -1
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -64,8 +64,10 @@
#include "esp_memprot.h" #include "esp_memprot.h"
#elif CONFIG_IDF_TARGET_ESP32H4 #elif CONFIG_IDF_TARGET_ESP32H4
#include "esp_memprot.h" #include "esp_memprot.h"
#elif CONFIG_IDF_TARGET_ESP32S31
#endif #endif
#include "rom/ets_sys.h"
#include "esp_private/cache_utils.h" #include "esp_private/cache_utils.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "esp_rtc_time.h" #include "esp_rtc_time.h"
@@ -92,7 +94,9 @@
#include "esp_private/crosscore_int.h" #include "esp_private/crosscore_int.h"
#include "esp_private/sleep_gpio.h" #include "esp_private/sleep_gpio.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "soc/rtc.h" #include "soc/rtc.h"
#include "hal/cache_hal.h" #include "hal/cache_hal.h"
#include "hal/cache_ll.h" #include "hal/cache_ll.h"
@@ -564,6 +568,7 @@ FORCE_INLINE_ATTR IRAM_ATTR void ext_mem_init(void)
MSPI_INIT_ATTR void sys_rtc_init(const soc_reset_reason_t *rst_reas) MSPI_INIT_ATTR void sys_rtc_init(const soc_reset_reason_t *rst_reas)
{ {
#if SOC_RTC_WDT_SUPPORTED
#if CONFIG_IDF_TARGET_ESP32P4 #if CONFIG_IDF_TARGET_ESP32P4
#define RWDT_RESET RESET_REASON_CORE_RWDT #define RWDT_RESET RESET_REASON_CORE_RWDT
#define MWDT_RESET RESET_REASON_CORE_MWDT #define MWDT_RESET RESET_REASON_CORE_MWDT
@@ -585,6 +590,7 @@ MSPI_INIT_ATTR void sys_rtc_init(const soc_reset_reason_t *rst_reas)
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
} }
#endif #endif
#endif /* SOC_RTC_WDT_SUPPORTED */
// Configure the power related stuff. After this the MSPI timing tuning can be done. // Configure the power related stuff. After this the MSPI timing tuning can be done.
esp_rtc_init(); esp_rtc_init();
+9 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -27,8 +27,10 @@
#include "esp_private/panic_internal.h" #include "esp_private/panic_internal.h"
#include "esp_private/panic_reason.h" #include "esp_private/panic_reason.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_types.h" #include "hal/wdt_types.h"
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD #if CONFIG_ESP_SYSTEM_HW_STACK_GUARD
#include "esp_private/hw_stack_guard.h" #include "esp_private/hw_stack_guard.h"
@@ -137,9 +139,9 @@ static void panic_handler(void *frame, bool pseudo_excause)
* *
* We do this before we increment the panic handler entry count to ensure that the WDTs are fed. * We do this before we increment the panic handler entry count to ensure that the WDTs are fed.
*/ */
#if CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE #if (SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED) && CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
esp_panic_handler_feed_wdts(); esp_panic_handler_feed_wdts();
#endif // CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE #endif // (SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED) && CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
/* Increment the panic handler entry count */ /* Increment the panic handler entry count */
esp_panic_handler_increment_entry_count(); esp_panic_handler_increment_entry_count();
@@ -213,18 +215,22 @@ static void panic_handler(void *frame, bool pseudo_excause)
* TODO: Make the timeout configurable or more intelligent based on the panic reason and the * TODO: Make the timeout configurable or more intelligent based on the panic reason and the
* config options. * config options.
*/ */
#if SOC_RTC_WDT_SUPPORTED
#if CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS #if CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS
esp_panic_handler_enable_rtc_wdt((CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS + 10) * 1000); esp_panic_handler_enable_rtc_wdt((CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS + 10) * 1000);
#else #else
esp_panic_handler_enable_rtc_wdt(10000); esp_panic_handler_enable_rtc_wdt(10000);
#endif /* CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS */ #endif /* CONFIG_ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS */
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
/* Before we stall the other CPU, we need to disable all WDTs except the RTC WDT. /* Before we stall the other CPU, we need to disable all WDTs except the RTC WDT.
* This is because the TIMG WDTs cannot reset the RTC subsystem, which stores the CPU stalling * This is because the TIMG WDTs cannot reset the RTC subsystem, which stores the CPU stalling
* configuration. If the other CPU is stalled and the TIMG WDTs trigger before we can unstall the * configuration. If the other CPU is stalled and the TIMG WDTs trigger before we can unstall the
* CPU then we have a chance of locking up the system without rebooting it. * CPU then we have a chance of locking up the system without rebooting it.
*/ */
esp_panic_handler_disable_timg_wdts(); esp_panic_handler_disable_timg_wdts();
#endif /* SOC_WDT_SUPPORTED */
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE #if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
esp_rom_delay_us(1); esp_rom_delay_us(1);
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -10,7 +10,9 @@
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
#include "bootloader_clock.h" #include "bootloader_clock.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/spi_share_hw_ctrl.h" #include "esp_private/spi_share_hw_ctrl.h"
@@ -140,7 +142,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_8m_enable(true, rc_fast_d256_is_enabled); rtc_clk_8m_enable(true, rc_fast_d256_is_enabled);
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -165,7 +167,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SLOW_CLK_150K); select_rtc_slow_clk(SLOW_CLK_150K);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -12,6 +12,7 @@
#include "esp_log.h" #include "esp_log.h"
#include "esp_ipc_isr.h" #include "esp_ipc_isr.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/soc_caps.h"
#include "esp_rom_serial_output.h" #include "esp_rom_serial_output.h"
#include "soc/dport_reg.h" #include "soc/dport_reg.h"
#include "soc/gpio_reg.h" #include "soc/gpio_reg.h"
@@ -19,7 +20,9 @@
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "soc/soc_memory_layout.h" #include "soc/soc_memory_layout.h"
#include "esp_private/cache_err_int.h" #include "esp_private/cache_err_int.h"
@@ -72,6 +75,7 @@ void esp_restart_noos(void)
// Disable interrupts // Disable interrupts
esp_cpu_intr_disable(0xFFFFFFFF); esp_cpu_intr_disable(0xFFFFFFFF);
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -82,6 +86,7 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
#endif /* SOC_RTC_WDT_SUPPORTED */
// Reset and stall the other CPU. // Reset and stall the other CPU.
// CPU must be reset before stalling, in case it was running a s32c1i // CPU must be reset before stalling, in case it was running a s32c1i
@@ -95,6 +100,7 @@ void esp_restart_noos(void)
// Other core is now stalled, can access DPORT registers directly // Other core is now stalled, can access DPORT registers directly
esp_ipc_isr_stall_abort(); esp_ipc_isr_stall_abort();
#if SOC_WDT_SUPPORTED
//Todo: Refactor to use Interrupt or Task Watchdog API, and a system level WDT context //Todo: Refactor to use Interrupt or Task Watchdog API, and a system level WDT context
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
@@ -106,6 +112,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
#ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM #ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
if (esp_ptr_external_ram(esp_cpu_get_sp())) { if (esp_ptr_external_ram(esp_cpu_get_sp())) {
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -21,7 +21,9 @@
#include "soc/soc.h" #include "soc/soc.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "bootloader_clock.h" #include "bootloader_clock.h"
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
@@ -86,7 +88,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec on 40MHz XTAL and 2.5 sec on 26MHz XTAL). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec on 40MHz XTAL and 2.5 sec on 26MHz XTAL).
@@ -114,7 +116,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SLOW_CLK_RTC); select_rtc_slow_clk(SLOW_CLK_RTC);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,11 +1,12 @@
/* /*
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <string.h> #include <string.h>
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/soc_caps.h"
#include "esp_macros.h" #include "esp_macros.h"
#include "esp_system.h" #include "esp_system.h"
#include "esp_private/system_internal.h" #include "esp_private/system_internal.h"
@@ -20,7 +21,9 @@
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
#include "soc/system_reg.h" #include "soc/system_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "esp_private/cache_err_int.h" #include "esp_private/cache_err_int.h"
@@ -59,6 +62,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -69,12 +73,15 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
wdt_hal_disable(&wdt0_context); wdt_hal_disable(&wdt0_context);
wdt_hal_write_protect_enable(&wdt0_context); wdt_hal_write_protect_enable(&wdt0_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_ICache(); Cache_Disable_ICache();
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -20,7 +20,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#include "soc/i2s_reg.h" #include "soc/i2s_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/usb_serial_jtag_ll.h" #include "hal/usb_serial_jtag_ll.h"
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
@@ -81,7 +83,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -106,7 +108,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SLOW_CLK_RTC); select_rtc_slow_clk(SLOW_CLK_RTC);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,11 +1,12 @@
/* /*
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <string.h> #include <string.h>
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/soc_caps.h"
#include "esp_macros.h" #include "esp_macros.h"
#include "esp_system.h" #include "esp_system.h"
#include "esp_private/system_internal.h" #include "esp_private/system_internal.h"
@@ -21,7 +22,9 @@
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
#include "soc/system_reg.h" #include "soc/system_reg.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "esp_private/cache_err_int.h" #include "esp_private/cache_err_int.h"
@@ -68,6 +71,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -78,7 +82,9 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -89,6 +95,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_ICache(); Cache_Disable_ICache();
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -22,7 +22,9 @@
#include "soc/chip_revision.h" #include "soc/chip_revision.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "hal/efuse_hal.h" #include "hal/efuse_hal.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/clk_tree_ll.h" #include "hal/clk_tree_ll.h"
#if SOC_MODEM_CLOCK_SUPPORTED #if SOC_MODEM_CLOCK_SUPPORTED
#include "hal/modem_lpcon_ll.h" #include "hal/modem_lpcon_ll.h"
@@ -74,7 +76,7 @@ __attribute__((weak)) void esp_clk_init(void)
#endif #endif
#endif //!CONFIG_IDF_ENV_FPGA #endif //!CONFIG_IDF_ENV_FPGA
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -98,7 +100,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -20,7 +20,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#if SOC_MODEM_CLOCK_SUPPORTED #if SOC_MODEM_CLOCK_SUPPORTED
#include "hal/modem_syscon_ll.h" #include "hal/modem_syscon_ll.h"
@@ -107,6 +109,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -117,9 +120,11 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
// C5 is a single core SoC, no need to reset and stall the other CPU // C5 is a single core SoC, no need to reset and stall the other CPU
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -130,6 +135,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_Cache(); Cache_Disable_Cache();
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -13,7 +13,9 @@
#include "soc/soc.h" #include "soc/soc.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/clk_gate_ll.h" #include "hal/clk_gate_ll.h"
#include "hal/pmu_ll.h" #include "hal/pmu_ll.h"
#include "esp_private/esp_modem_clock.h" #include "esp_private/esp_modem_clock.h"
@@ -56,7 +58,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -80,7 +82,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -15,12 +15,15 @@
#include "riscv/rv_utils.h" #include "riscv/rv_utils.h"
#include "esp_rom_serial_output.h" #include "esp_rom_serial_output.h"
#include "soc/gpio_reg.h" #include "soc/gpio_reg.h"
#include "soc/soc_caps.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "hal/modem_syscon_ll.h" #include "hal/modem_syscon_ll.h"
#include "hal/modem_lpcon_ll.h" #include "hal/modem_lpcon_ll.h"
@@ -95,6 +98,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -105,9 +109,11 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
// C6 is a single core SoC, no need to reset and stall the other CPU // C6 is a single core SoC, no need to reset and stall the other CPU
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -118,6 +124,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_ICache(); Cache_Disable_ICache();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,7 +18,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/esp_modem_clock.h" #include "esp_private/esp_modem_clock.h"
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
@@ -54,7 +56,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -78,7 +80,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -15,12 +15,15 @@
#include "riscv/rv_utils.h" #include "riscv/rv_utils.h"
#include "esp_rom_serial_output.h" #include "esp_rom_serial_output.h"
#include "soc/gpio_reg.h" #include "soc/gpio_reg.h"
#include "soc/soc_caps.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "esp_private/cache_err_int.h" #include "esp_private/cache_err_int.h"
@@ -107,6 +110,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -117,9 +121,11 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
// C61 is a single core SoC, no need to reset and stall the other CPU // C61 is a single core SoC, no need to reset and stall the other CPU
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -130,6 +136,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_Cache(); Cache_Disable_Cache();
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -19,7 +19,9 @@
#include "soc/soc.h" #include "soc/soc.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/clk_gate_ll.h" #include "hal/clk_gate_ll.h"
#include "hal/pmu_ll.h" #include "hal/pmu_ll.h"
#include "esp_private/esp_modem_clock.h" #include "esp_private/esp_modem_clock.h"
@@ -63,7 +65,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (2 sec). // Therefore, for the time of frequency change, set a new lower timeout value (2 sec).
@@ -89,7 +91,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -16,11 +16,14 @@
#include "riscv/interrupt.h" #include "riscv/interrupt.h"
#include "esp_rom_serial_output.h" #include "esp_rom_serial_output.h"
#include "soc/gpio_reg.h" #include "soc/gpio_reg.h"
#include "soc/soc_caps.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "hal/spimem_flash_ll.h" #include "hal/spimem_flash_ll.h"
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
@@ -93,6 +96,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -103,7 +107,9 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -114,6 +120,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_ICache(); Cache_Disable_ICache();
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,7 +18,9 @@
#include "soc/soc.h" #include "soc/soc.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/esp_modem_clock.h" #include "esp_private/esp_modem_clock.h"
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
@@ -54,7 +56,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (2 sec). // Therefore, for the time of frequency change, set a new lower timeout value (2 sec).
@@ -80,7 +82,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW_D4); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW_D4);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -21,8 +21,9 @@
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#include "hal/uart_ll.h" #endif
#include "hal/spimem_flash_ll.h" #include "hal/spimem_flash_ll.h"
#include "esp_private/cache_err_int.h" #include "esp_private/cache_err_int.h"
@@ -98,6 +99,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -108,7 +110,9 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -119,6 +123,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_ICache(); Cache_Disable_ICache();
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -18,7 +18,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
#include "esp_private/esp_pmu.h" #include "esp_private/esp_pmu.h"
@@ -55,7 +57,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (2 sec). // Therefore, for the time of frequency change, set a new lower timeout value (2 sec).
@@ -78,7 +80,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW_D4); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW_D4);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -20,10 +20,13 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "esp32h4/rom/cache.h" #include "esp32h4/rom/cache.h"
#include "esp32h4/rom/ets_sys.h"
// TODO: IDF-11911 need refactor // TODO: IDF-11911 need refactor
void esp_system_reset_modules_on_exit(void) void esp_system_reset_modules_on_exit(void)
@@ -92,6 +95,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -102,6 +106,7 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
const uint32_t core_id = esp_cpu_get_core_id(); const uint32_t core_id = esp_cpu_get_core_id();
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE #if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
@@ -110,6 +115,7 @@ void esp_restart_noos(void)
esp_cpu_stall(other_core_id); esp_cpu_stall(other_core_id);
#endif #endif
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -120,6 +126,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
Cache_Disable_Cache(CACHE_MAP_ALL); Cache_Disable_Cache(CACHE_MAP_ALL);
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -21,7 +21,9 @@
#include "esp_cpu.h" #include "esp_cpu.h"
#include "mspi_timing_tuning_configs.h" #include "mspi_timing_tuning_configs.h"
#include "hal/clk_gate_ll.h" #include "hal/clk_gate_ll.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/esp_sleep_internal.h" #include "esp_private/esp_sleep_internal.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
#include "esp_private/esp_pmu.h" #include "esp_private/esp_pmu.h"
@@ -64,7 +66,7 @@ __attribute__((weak)) void esp_clk_init(void)
#error "No RTC fast clock source configured" #error "No RTC fast clock source configured"
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -85,7 +87,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -15,14 +15,18 @@
#include "riscv/rv_utils.h" #include "riscv/rv_utils.h"
#include "esp_rom_serial_output.h" #include "esp_rom_serial_output.h"
#include "soc/gpio_reg.h" #include "soc/gpio_reg.h"
#include "soc/soc_caps.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/cache_err_int.h" #include "esp_private/cache_err_int.h"
#include "esp32p4/rom/cache.h" #include "esp32p4/rom/cache.h"
#include "esp32p4/rom/ets_sys.h"
#include "esp32p4/rom/rtc.h" #include "esp32p4/rom/rtc.h"
#include "soc/hp_sys_clkrst_reg.h" #include "soc/hp_sys_clkrst_reg.h"
#include "soc/lp_clkrst_reg.h" #include "soc/lp_clkrst_reg.h"
@@ -157,6 +161,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -167,6 +172,7 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
const uint32_t core_id = esp_cpu_get_core_id(); const uint32_t core_id = esp_cpu_get_core_id();
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE #if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
@@ -175,6 +181,7 @@ void esp_restart_noos(void)
esp_cpu_stall(other_core_id); esp_cpu_stall(other_core_id);
#endif #endif
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -185,6 +192,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
#if CONFIG_SPIRAM #if CONFIG_SPIRAM
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -21,7 +21,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#include "soc/i2s_reg.h" #include "soc/i2s_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
#include "bootloader_clock.h" #include "bootloader_clock.h"
@@ -81,7 +83,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_8m_enable(true, rc_fast_d256_is_enabled); rtc_clk_8m_enable(true, rc_fast_d256_is_enabled);
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 90kHz to 32kHz, then the timeout set for the WDT will increase 2.8 times. // If the frequency changes from 90kHz to 32kHz, then the timeout set for the WDT will increase 2.8 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -106,7 +108,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SLOW_CLK_RTC); select_rtc_slow_clk(SLOW_CLK_RTC);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000ULL); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000ULL);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,11 +1,12 @@
/* /*
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <string.h> #include <string.h>
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/soc_caps.h"
#include "esp_macros.h" #include "esp_macros.h"
#include "esp_system.h" #include "esp_system.h"
#include "esp_private/system_internal.h" #include "esp_private/system_internal.h"
@@ -20,7 +21,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "soc/soc_memory_layout.h" #include "soc/soc_memory_layout.h"
@@ -69,6 +72,7 @@ void esp_restart_noos(void)
// Disable interrupts // Disable interrupts
esp_cpu_intr_disable(0xFFFFFFFF); esp_cpu_intr_disable(0xFFFFFFFF);
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -79,7 +83,9 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
//Todo: Refactor to use Interrupt or Task Watchdog API, and a system level WDT context //Todo: Refactor to use Interrupt or Task Watchdog API, and a system level WDT context
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
@@ -91,6 +97,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
#ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM #ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
if (esp_ptr_external_ram(esp_cpu_get_sp())) { if (esp_ptr_external_ram(esp_cpu_get_sp())) {
+5 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -20,7 +20,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#include "soc/i2s_reg.h" #include "soc/i2s_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/usb_serial_jtag_ll.h" #include "hal/usb_serial_jtag_ll.h"
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
@@ -83,7 +85,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_8m_enable(true, rc_fast_d256_is_enabled); rtc_clk_8m_enable(true, rc_fast_d256_is_enabled);
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST); rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -108,7 +110,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SLOW_CLK_RTC); select_rtc_slow_clk(SLOW_CLK_RTC);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000ULL); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000ULL);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,6 +1,6 @@
/* /*
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -21,7 +21,9 @@
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "soc/soc_memory_layout.h" #include "soc/soc_memory_layout.h"
@@ -75,6 +77,7 @@ void esp_restart_noos(void)
// Disable interrupts // Disable interrupts
esp_cpu_intr_disable(0xFFFFFFFF); esp_cpu_intr_disable(0xFFFFFFFF);
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -85,7 +88,9 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -96,6 +101,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
#ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM #ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
if (esp_ptr_external_ram(esp_cpu_get_sp())) { if (esp_ptr_external_ram(esp_cpu_get_sp())) {
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -29,7 +29,9 @@
#include "soc/usb_serial_jtag_reg.h" #include "soc/usb_serial_jtag_reg.h"
#include "soc/hp_alive_sys_reg.h" #include "soc/hp_alive_sys_reg.h"
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/esp_sleep_internal.h" #include "esp_private/esp_sleep_internal.h"
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "esp_private/esp_clk.h" #include "esp_private/esp_clk.h"
@@ -63,7 +65,7 @@ __attribute__((weak)) void esp_clk_init(void)
rtc_clk_8m_enable(true); rtc_clk_8m_enable(true);
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed. // WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times. // If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
@@ -84,7 +86,7 @@ __attribute__((weak)) void esp_clk_init(void)
select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW); select_rtc_slow_clk(SOC_RTC_SLOW_CLK_SRC_RC_SLOW);
#endif #endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE #if defined(CONFIG_BOOTLOADER_WDT_ENABLE) && SOC_RTC_WDT_SUPPORTED
// After changing a frequency WDT timeout needs to be set for new frequency. // After changing a frequency WDT timeout needs to be set for new frequency.
stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_write_protect_disable(&rtc_wdt_ctx);
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -15,15 +15,19 @@
#include "riscv/rv_utils.h" #include "riscv/rv_utils.h"
#include "esp_rom_serial_output.h" #include "esp_rom_serial_output.h"
#include "soc/gpio_reg.h" #include "soc/gpio_reg.h"
#include "soc/soc_caps.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "esp_private/rtc_clk.h" #include "esp_private/rtc_clk.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "esp_private/cache_err_int.h" #include "esp_private/cache_err_int.h"
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
#include "esp32s31/rom/cache.h" #include "esp32s31/rom/cache.h"
#include "esp32s31/rom/ets_sys.h"
#include "esp32s31/rom/rtc.h" #include "esp32s31/rom/rtc.h"
#include "soc/hp_sys_clkrst_reg.h" #include "soc/hp_sys_clkrst_reg.h"
#include "soc/lp_clkrst_reg.h" #include "soc/lp_clkrst_reg.h"
@@ -49,6 +53,7 @@ void esp_restart_noos(void)
{ {
// Disable interrupts // Disable interrupts
rv_utils_intr_global_disable(); rv_utils_intr_global_disable();
#if SOC_RTC_WDT_SUPPORTED
// Enable RTC watchdog for 1 second // Enable RTC watchdog for 1 second
wdt_hal_context_t rtc_wdt_ctx; wdt_hal_context_t rtc_wdt_ctx;
wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
@@ -60,6 +65,7 @@ void esp_restart_noos(void)
//Enable flash boot mode so that flash booting after restart is protected by the RTC WDT. //Enable flash boot mode so that flash booting after restart is protected by the RTC WDT.
wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true); wdt_hal_set_flashboot_en(&rtc_wdt_ctx, true);
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
#endif /* SOC_RTC_WDT_SUPPORTED */
const uint32_t core_id = esp_cpu_get_core_id(); const uint32_t core_id = esp_cpu_get_core_id();
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE #if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
@@ -68,6 +74,7 @@ void esp_restart_noos(void)
esp_cpu_stall(other_core_id); esp_cpu_stall(other_core_id);
#endif #endif
#if SOC_WDT_SUPPORTED
// Disable TG0/TG1 watchdogs // Disable TG0/TG1 watchdogs
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&wdt0_context); wdt_hal_write_protect_disable(&wdt0_context);
@@ -78,6 +85,7 @@ void esp_restart_noos(void)
wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_write_protect_disable(&wdt1_context);
wdt_hal_disable(&wdt1_context); wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context);
#endif /* SOC_WDT_SUPPORTED */
// Disable cache // Disable cache
#if CONFIG_SPIRAM #if CONFIG_SPIRAM
+4 -2
View File
@@ -19,7 +19,9 @@
#include "esp_private/startup_internal.h" #include "esp_private/startup_internal.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#if SOC_WDT_SUPPORTED || SOC_RTC_WDT_SUPPORTED
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#endif
#include "hal/uart_types.h" #include "hal/uart_types.h"
#include "hal/uart_ll.h" #include "hal/uart_ll.h"
@@ -134,7 +136,7 @@ ESP_SYSTEM_INIT_FN(init_bootloader_offset, SECONDARY, BIT(0), 205)
} }
#endif // SOC_RECOVERY_BOOTLOADER_SUPPORTED #endif // SOC_RECOVERY_BOOTLOADER_SUPPORTED
#ifndef CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE #if SOC_RTC_WDT_SUPPORTED && !defined(CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE)
ESP_SYSTEM_INIT_FN(init_disable_rtc_wdt, SECONDARY, BIT(0), 999) ESP_SYSTEM_INIT_FN(init_disable_rtc_wdt, SECONDARY, BIT(0), 999)
{ {
wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
@@ -143,4 +145,4 @@ ESP_SYSTEM_INIT_FN(init_disable_rtc_wdt, SECONDARY, BIT(0), 999)
wdt_hal_write_protect_enable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx);
return ESP_OK; return ESP_OK;
} }
#endif // CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE #endif // SOC_RTC_WDT_SUPPORTED && !CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE
@@ -167,6 +167,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -107,6 +107,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_MPU_SUPPORTED 1 #define SOC_MPU_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -115,6 +115,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -51,6 +51,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -171,6 +171,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -68,6 +68,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -235,6 +235,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SDIO_SLAVE_SUPPORTED config SOC_SDIO_SLAVE_SUPPORTED
bool bool
default y default y
@@ -81,6 +81,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SDIO_SLAVE_SUPPORTED 1 #define SOC_SDIO_SLAVE_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_ECDSA_SUPPORTED 1 #define SOC_ECDSA_SUPPORTED 1
@@ -227,6 +227,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -79,6 +79,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -143,6 +143,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -59,6 +59,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_MODEM_CLOCK_SUPPORTED 1 #define SOC_MODEM_CLOCK_SUPPORTED 1
#define SOC_REG_I2C_SUPPORTED 1 #define SOC_REG_I2C_SUPPORTED 1
@@ -223,6 +223,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -94,6 +94,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -135,6 +135,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -67,6 +67,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 //TODO: [ESP32H21] IDF-11526 #define SOC_SPI_FLASH_SUPPORTED 1 //TODO: [ESP32H21] IDF-11526
// #define SOC_RNG_SUPPORTED 1 //TODO: [ESP32H21] IDF-11503 // #define SOC_RNG_SUPPORTED 1 //TODO: [ESP32H21] IDF-11503
#define SOC_MODEM_CLOCK_SUPPORTED 1 #define SOC_MODEM_CLOCK_SUPPORTED 1
@@ -167,6 +167,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -85,6 +85,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_SPIRAM_SUPPORTED 1 #define SOC_SPIRAM_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -335,6 +335,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -106,6 +106,7 @@
#define SOC_ASSIST_DEBUG_SUPPORTED 1 #define SOC_ASSIST_DEBUG_SUPPORTED 1
#define SOC_DEBUG_PROBE_SUPPORTED 1 #define SOC_DEBUG_PROBE_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_TOUCH_SENSOR_SUPPORTED 1 #define SOC_TOUCH_SENSOR_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
@@ -203,6 +203,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -93,6 +93,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_MPU_SUPPORTED 1 #define SOC_MPU_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -235,6 +235,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -86,6 +86,7 @@
#define SOC_CLK_TREE_SUPPORTED 1 #define SOC_CLK_TREE_SUPPORTED 1
#define SOC_MPU_SUPPORTED 1 #define SOC_MPU_SUPPORTED 1
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 #define SOC_SPI_FLASH_SUPPORTED 1
#define SOC_RNG_SUPPORTED 1 #define SOC_RNG_SUPPORTED 1
#define SOC_LIGHT_SLEEP_SUPPORTED 1 #define SOC_LIGHT_SLEEP_SUPPORTED 1
@@ -75,6 +75,10 @@ config SOC_WDT_SUPPORTED
bool bool
default y default y
config SOC_RTC_WDT_SUPPORTED
bool
default y
config SOC_SPI_FLASH_SUPPORTED config SOC_SPI_FLASH_SUPPORTED
bool bool
default y default y
@@ -87,6 +87,7 @@
// #define SOC_ASSIST_DEBUG_SUPPORTED 1 // TODO: [ESP32S31] IDF-14675 // #define SOC_ASSIST_DEBUG_SUPPORTED 1 // TODO: [ESP32S31] IDF-14675
// #define SOC_DEBUG_PROBE_SUPPORTED 1 // TODO: [ESP32S31] IDF-14798 // #define SOC_DEBUG_PROBE_SUPPORTED 1 // TODO: [ESP32S31] IDF-14798
#define SOC_WDT_SUPPORTED 1 #define SOC_WDT_SUPPORTED 1
#define SOC_RTC_WDT_SUPPORTED 1
#define SOC_SPI_FLASH_SUPPORTED 1 // TODO: [ESP32S31] IDF-14777 #define SOC_SPI_FLASH_SUPPORTED 1 // TODO: [ESP32S31] IDF-14777
// #define SOC_TOUCH_SENSOR_SUPPORTED 1 // TODO: [ESP32S31] IDF-14796 // #define SOC_TOUCH_SENSOR_SUPPORTED 1 // TODO: [ESP32S31] IDF-14796
// #define SOC_RNG_SUPPORTED 1 // TODO: [ESP32S31] IDF-14632 // #define SOC_RNG_SUPPORTED 1 // TODO: [ESP32S31] IDF-14632