From d3bac034fd4099304cde46ce68bb481bc91ec864 Mon Sep 17 00:00:00 2001 From: Ryan Powell Date: Fri, 19 Jul 2024 11:56:59 -0600 Subject: [PATCH] Wrap the panic handler to disable the gdo uart pins and prevent door openings. --- components/secplus_gdo/secplus_gdo.cpp | 20 +++++++++++++++++++- garage-door-GDOv2-Q.yaml | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/secplus_gdo/secplus_gdo.cpp b/components/secplus_gdo/secplus_gdo.cpp index a11ad93..5c36bc2 100644 --- a/components/secplus_gdo/secplus_gdo.cpp +++ b/components/secplus_gdo/secplus_gdo.cpp @@ -171,4 +171,22 @@ namespace secplus_gdo { } } // namespace secplus_gdo -} // namespace esphome \ No newline at end of file +} // namespace esphome + +// Need to wrap the panic handler to disable the GDO TX pin and pull the output high to +// prevent spuriously triggering the GDO to open when the ESP32 panics. +extern "C" { +#include "hal/gpio_hal.h" + +void __real_esp_panic_handler(void*); + +void __wrap_esp_panic_handler (void* info) { + esp_rom_printf("PANIC: DISABLING GDO UART TX PIN!\n"); + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[(gpio_num_t)GDO_UART_TX_PIN], PIN_FUNC_GPIO); + gpio_set_direction((gpio_num_t)GDO_UART_TX_PIN, GPIO_MODE_INPUT); + gpio_pulldown_en((gpio_num_t)GDO_UART_TX_PIN); + + // Call the original panic handler + __real_esp_panic_handler(info); +} +} //extern "C" diff --git a/garage-door-GDOv2-Q.yaml b/garage-door-GDOv2-Q.yaml index e6ff1f7..4ad6f0a 100644 --- a/garage-door-GDOv2-Q.yaml +++ b/garage-door-GDOv2-Q.yaml @@ -188,4 +188,5 @@ esphome: lib_deps: - https://github.com/konnected-io/gdolib#76ba232 build_flags: - - -DUART_SCLK_DEFAULT=UART_SCLK_APB \ No newline at end of file + - -DUART_SCLK_DEFAULT=UART_SCLK_APB + - -Wl,--wrap=esp_panic_handler \ No newline at end of file