From ed85d9717a5e2d8206f5d3dabfbdb56e69099d20 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Mon, 20 May 2024 20:41:43 +0200 Subject: [PATCH] work around with uart_driver_delete --- ESP32/comm_esp32_hardwareserial.cpp | 8 +++++++- ESP32/comm_esp32_hardwareserial.h | 9 +++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ESP32/comm_esp32_hardwareserial.cpp b/ESP32/comm_esp32_hardwareserial.cpp index ce6eb29..558d017 100644 --- a/ESP32/comm_esp32_hardwareserial.cpp +++ b/ESP32/comm_esp32_hardwareserial.cpp @@ -19,7 +19,8 @@ comm_esp32_hardwareserial::comm_esp32_hardwareserial(const int uart_nr, const in comm_esp32_hardwareserial::~comm_esp32_hardwareserial() { - ESP_ERROR_CHECK(uart_driver_delete(uart_nr)); + if (initialized) + ESP_ERROR_CHECK(uart_driver_delete(uart_nr)); } bool comm_esp32_hardwareserial::begin() @@ -44,6 +45,9 @@ bool comm_esp32_hardwareserial::begin() return false; } + // it already was at this point?! + uart_driver_delete(uart_nr); + // Setup UART buffered IO with event queue const int uart_buffer_size = 1024 * 2; static QueueHandle_t uart_queue; @@ -53,6 +57,8 @@ bool comm_esp32_hardwareserial::begin() return false; } + initialized = true; + return true; } diff --git a/ESP32/comm_esp32_hardwareserial.h b/ESP32/comm_esp32_hardwareserial.h index 953ddc7..4f233c7 100644 --- a/ESP32/comm_esp32_hardwareserial.h +++ b/ESP32/comm_esp32_hardwareserial.h @@ -9,10 +9,11 @@ class comm_esp32_hardwareserial: public comm { private: - const int uart_nr { 1 }; - const int rx_pin { -1 }; - const int tx_pin { -1 }; - const int bitrate { 38400 }; + const int uart_nr { 1 }; + const int rx_pin { -1 }; + const int tx_pin { -1 }; + const int bitrate { 38400 }; + bool initialized { false }; public: comm_esp32_hardwareserial(const int uart_nr, const int rx_pin, const int tx_pin, const int bps);