Merge branch 'esp32-crash-handler' into integration

This commit is contained in:
J. Nick Koston
2026-03-11 14:07:38 -10:00
7 changed files with 19 additions and 6 deletions
+2 -2
View File
@@ -14,7 +14,7 @@
#include "api_server.h"
#include "esphome/core/application.h"
#include "esphome/core/component.h"
#ifdef USE_ESP32
#ifdef USE_ESP32_CRASH_HANDLER
#include "esphome/components/esp32/crash_handler.h"
#endif
#include "esphome/core/entity_base.h"
@@ -238,7 +238,7 @@ class APIConnection final : public APIServerConnectionBase {
this->flags_.log_subscription = msg.level;
if (msg.dump_config)
App.schedule_dump_config();
#ifdef USE_ESP32
#ifdef USE_ESP32_CRASH_HANDLER
esp32::crash_handler_log();
#endif
}
+5 -1
View File
@@ -1442,7 +1442,11 @@ async def to_code(config):
cg.add_build_flag("-DUSE_ESP32")
cg.add_define("USE_NATIVE_64BIT_TIME")
cg.add_build_flag("-Wl,-z,noexecstack")
cg.add_build_flag("-Wl,--wrap=esp_panic_handler")
# Arduino already wraps esp_panic_handler for its own backtrace handler,
# so only add our wrap when using ESP-IDF framework to avoid linker conflicts.
if conf[CONF_TYPE] == FRAMEWORK_ESP_IDF:
cg.add_build_flag("-Wl,--wrap=esp_panic_handler")
cg.add_define("USE_ESP32_CRASH_HANDLER")
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
variant = config[CONF_VARIANT]
cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{variant}")
+3 -1
View File
@@ -1,7 +1,7 @@
#ifdef USE_ESP32
#include "crash_handler.h"
#include "esphome/core/defines.h"
#include "crash_handler.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "preferences.h"
@@ -37,8 +37,10 @@ void arch_restart() {
}
void arch_init() {
#ifdef USE_ESP32_CRASH_HANDLER
// Read crash data from previous boot before anything else
esp32::crash_handler_read_and_clear();
#endif
// Enable the task watchdog only on the loop task (from which we're currently running)
esp_task_wdt_add(nullptr);
@@ -1,5 +1,8 @@
#ifdef USE_ESP32
#include "esphome/core/defines.h"
#ifdef USE_ESP32_CRASH_HANDLER
#include "crash_handler.h"
#include "esphome/core/log.h"
@@ -348,4 +351,5 @@ void IRAM_ATTR __wrap_esp_panic_handler(panic_info_t *info) {
// NOLINTEND(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
} // extern "C"
#endif // USE_ESP32_CRASH_HANDLER
#endif // USE_ESP32
+2 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#ifdef USE_ESP32
#ifdef USE_ESP32_CRASH_HANDLER
namespace esphome::esp32 {
@@ -15,4 +15,4 @@ bool crash_handler_has_data();
} // namespace esphome::esp32
#endif // USE_ESP32
#endif // USE_ESP32_CRASH_HANDLER
@@ -118,7 +118,9 @@ void Logger::pre_setup() {
esp_log_set_vprintf(esp_idf_log_vprintf_);
ESP_LOGI(TAG, "Log initialized");
#ifdef USE_ESP32_CRASH_HANDLER
esp32::crash_handler_log();
#endif
}
void HOT Logger::write_msg_(const char *msg, uint16_t len) {
+1
View File
@@ -196,6 +196,7 @@
// ESP32-specific feature flags
#ifdef USE_ESP32
#define USE_ESP32_CRASH_HANDLER
#define USE_MQTT_IDF_ENQUEUE
#define USE_ESPHOME_TASK_LOG_BUFFER
#define USE_OTA_ROLLBACK