From 36eaa2c4a11e844f98b2a13d480851a24e56fb40 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Tue, 12 Aug 2025 11:30:15 +0200 Subject: [PATCH] fix(panic_handler): Fixed a issue where the system reboots before halt This commit fixes an issue where the panic handler may reboot even if it is configured to halt the CPU. Closes https://github.com/espressif/esp-idf/issues/17260 --- components/esp_system/panic.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index 23cb2abfc2..38044b70d9 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -262,6 +262,14 @@ static inline void disable_all_wdts(void) wdt_hal_write_protect_enable(&rtc_wdt_ctx); } +/* IRAM-only halt stub: reset modules, then loop */ +void IRAM_ATTR esp_panic_handler_reset_modules_on_exit_and_halt(void) +{ + // Do not print or call non-IRAM functions beyond this point + esp_system_reset_modules_on_exit(); + ESP_INFINITE_LOOP(); +} + /********************** Panic handler functions **********************/ /* This function is called from the panic handler entry point to increment the panic entry count */ @@ -455,10 +463,10 @@ void esp_panic_handler(panic_info_t *info) panic_print_str("Rebooting...\r\n"); panic_restart(); #else /* CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT || CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT */ + esp_panic_handler_feed_wdts(); panic_print_str("CPU halted.\r\n"); - esp_system_reset_modules_on_exit(); disable_all_wdts(); - ESP_INFINITE_LOOP(); + esp_panic_handler_reset_modules_on_exit_and_halt(); #endif /* CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT || CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT */ #endif /* CONFIG_ESP_SYSTEM_PANIC_GDBSTUB */ }