From 6d66c58d683968981d02e688141f1ff6b5b71498 Mon Sep 17 00:00:00 2001 From: WereCatf Date: Fri, 13 Oct 2017 10:11:06 +0300 Subject: [PATCH 1/3] Add a workaround-delay in Serial.flush() In relation to #2536 and #2502 Tested at 80MHz and 160MHz with flash-frequency at both 40MHz and 80MHz, the bug mentioned in the above issues manifests in all cases. The proposed workaround seems to work fine, I tested at 2400bps, 9600bps, 115200bps, 230400bps and 2Mbps and didn't see anomalous output. --- cores/esp8266/HardwareSerial.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 979b0c0da4..4bd6d0cd98 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -152,6 +152,9 @@ void HardwareSerial::flush() } uart_wait_tx_empty(_uart); + //Workaround for a bug in serial not actually being finished yet + //Wait for 8 data bits, 1 parity and 2 stop bits, just in case + delayMicroseconds(1100000 / uart_get_baudrate(_uart) + 1)); } size_t HardwareSerial::write(uint8_t c) From 0f25996870708902d266f7b312fdf16af1cb5df5 Mon Sep 17 00:00:00 2001 From: WereCatf Date: Fri, 13 Oct 2017 10:14:46 +0300 Subject: [PATCH 2/3] Remove extraneous character --- cores/esp8266/HardwareSerial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 4bd6d0cd98..7c5e809b3f 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -154,7 +154,7 @@ void HardwareSerial::flush() uart_wait_tx_empty(_uart); //Workaround for a bug in serial not actually being finished yet //Wait for 8 data bits, 1 parity and 2 stop bits, just in case - delayMicroseconds(1100000 / uart_get_baudrate(_uart) + 1)); + delayMicroseconds(1100000 / uart_get_baudrate(_uart) + 1); } size_t HardwareSerial::write(uint8_t c) From 3ef8c2d481115fb8c232a11fede4f96127fd5bef Mon Sep 17 00:00:00 2001 From: WereCatf Date: Fri, 13 Oct 2017 23:43:42 +0300 Subject: [PATCH 3/3] Update HardwareSerial.cpp --- cores/esp8266/HardwareSerial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 7c5e809b3f..d78b239f1e 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -154,7 +154,7 @@ void HardwareSerial::flush() uart_wait_tx_empty(_uart); //Workaround for a bug in serial not actually being finished yet //Wait for 8 data bits, 1 parity and 2 stop bits, just in case - delayMicroseconds(1100000 / uart_get_baudrate(_uart) + 1); + delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1); } size_t HardwareSerial::write(uint8_t c)