From 522bccb3e22bce30b76226282c06478daa230ae2 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 24 Apr 2022 17:36:10 +0200 Subject: [PATCH] Initial support for USB serial Initial support for USB serial when define ARDUINO_USB_CDC_ON_BOOT=1 --- lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp | 4 ++++ tasmota/support.ino | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp index 278acaabd..99dc6caeb 100644 --- a/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp @@ -153,6 +153,9 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) { #ifdef ESP32 if (TSerial == nullptr) { // Allow for dynamic change in baudrate or config if (freeUart()) { // We prefer UART1 and UART2 and keep UART0 for debugging +#ifdef ARDUINO_USB_CDC_ON_BOOT + TSerial = new HardwareSerial(m_uart); +#else if (0 == m_uart) { Serial.flush(); Serial.end(); @@ -161,6 +164,7 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) { } else { TSerial = new HardwareSerial(m_uart); } +#endif // ARDUINO_USB_CDC_ON_BOOT if (serial_buffer_size > 256) { // RX Buffer can't be resized when Serial is already running (HardwareSerial.cpp) TSerial->setRxBufferSize(serial_buffer_size); } diff --git a/tasmota/support.ino b/tasmota/support.ino index e124dd3cf..75f461fe5 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1901,7 +1901,11 @@ void SetSerialBegin(void) { delay(10); // Allow time to cleanup queues - if not used hangs ESP32 Serial.end(); delay(10); // Allow time to cleanup queues - if not used hangs ESP32 +#ifdef ARDUINO_USB_CDC_ON_BOOT + Serial.begin(TasmotaGlobal.baudrate); +#else Serial.begin(TasmotaGlobal.baudrate, ConvertSerialConfig(Settings->serial_config)); +#endif // ARDUINO_USB_CDC_ON_BOOT #endif // ESP32 }