From a1bef8b5c3a156e8a0a9c56011849b7f1efd2d3c Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 2 Aug 2017 00:32:42 +0300 Subject: [PATCH] improve Serial repeated begin/baud change --- cores/esp32/HardwareSerial.cpp | 3 +++ cores/esp32/esp32-hal-uart.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 84124bd40..18d44a29a 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -11,6 +11,9 @@ HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL) {} void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin) { + if(_uart) { + end(); + } if(_uart_nr == 0 && rxPin < 0 && txPin < 0) { rxPin = 3; txPin = 1; diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 4730720bd..055e4fc68 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -223,6 +223,8 @@ void uartEnd(uart_t* uart) UART_MUTEX_LOCK(); if(uart->queue != NULL) { + uint8_t c; + while(xQueueReceive(uart->queue, &c, 0)); vQueueDelete(uart->queue); } -- GitLab