From 995b9a0da03789056ca19cfa9a6401121b36de8e Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 11:56:38 -0600 Subject: [PATCH 01/13] add option to Flush() to only clear txQueue Add the option to cause Flush() to just wait for tx data to clear the tx fifo and uart, leave the rx queue and rx fifo as is. --- cores/esp32/HardwareSerial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 5f886650816..56c377b2d7b 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -62,7 +62,7 @@ class HardwareSerial: public Stream int availableForWrite(void); int peek(void); int read(void); - void flush(void); + void flush( bool txOnly = false); size_t write(uint8_t); size_t write(const uint8_t *buffer, size_t size); From 48d28fbb4fc913cb6c7f09ef3893d7176fb705c3 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:00:29 -0600 Subject: [PATCH 02/13] support tx only flush() --- cores/esp32/HardwareSerial.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 545c9b05562..22ecb1e175b 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -131,9 +131,9 @@ int HardwareSerial::read(void) return -1; } -void HardwareSerial::flush() +void HardwareSerial::flush(bool txOnly) { - uartFlush(_uart); + uartFlush(_uart, txOnly); } size_t HardwareSerial::write(uint8_t c) From 92403a22902954d1cf7f67f17163330e52bd7a6b Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:01:52 -0600 Subject: [PATCH 03/13] support tx only Flush() --- cores/esp32/esp32-hal-uart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index 821ca9c6ce0..99a8e6f5ef3 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -62,7 +62,7 @@ uint8_t uartPeek(uart_t* uart); void uartWrite(uart_t* uart, uint8_t c); void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len); -void uartFlush(uart_t* uart); +void uartFlush(uart_t* uart, bool txOnly = false); void uartSetBaudRate(uart_t* uart, uint32_t baud_rate); uint32_t uartGetBaudRate(uart_t* uart); From 4046a5853cfc10e36943aa5ae8f1431f63fd35e9 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:06:02 -0600 Subject: [PATCH 04/13] support txOnly for Flush() --- cores/esp32/esp32-hal-uart.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 2dee63dc325..265df72e1a1 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -326,7 +326,7 @@ void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len) UART_MUTEX_UNLOCK(); } -void uartFlush(uart_t* uart) +void uartFlush(uart_t* uart, bool txOnly) { if(uart == NULL) { return; @@ -334,17 +334,19 @@ void uartFlush(uart_t* uart) UART_MUTEX_LOCK(); while(uart->dev->status.txfifo_cnt || uart->dev->status.st_utx_out); + + if( !txOnly ){ + //Due to hardware issue, we can not use fifo_rst to reset uart fifo. + //See description about UART_TXFIFO_RST and UART_RXFIFO_RST in <> v2.6 or later. - //Due to hardware issue, we can not use fifo_rst to reset uart fifo. - //See description about UART_TXFIFO_RST and UART_RXFIFO_RST in <> v2.6 or later. + // we read the data out and make `fifo_len == 0 && rd_addr == wr_addr`. + while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) { + READ_PERI_REG(UART_FIFO_REG(uart->num)); + } - // we read the data out and make `fifo_len == 0 && rd_addr == wr_addr`. - while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) { - READ_PERI_REG(UART_FIFO_REG(uart->num)); + xQueueReset(uart->queue); } - - xQueueReset(uart->queue); - + UART_MUTEX_UNLOCK(); } From be1a52e992605f0f308e6c8c0528c0571a438862 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:20:04 -0600 Subject: [PATCH 05/13] compatibility to Stream() --- cores/esp32/HardwareSerial.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 56c377b2d7b..7d9f26d2fae 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -62,7 +62,8 @@ class HardwareSerial: public Stream int availableForWrite(void); int peek(void); int read(void); - void flush( bool txOnly = false); + void flush(void); + void flush( bool txOnly); size_t write(uint8_t); size_t write(const uint8_t *buffer, size_t size); From 8956c51ebc600adb80d23dc4f137717e98c13de5 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:22:18 -0600 Subject: [PATCH 06/13] compatibility for Stream() --- cores/esp32/HardwareSerial.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 22ecb1e175b..749c89dc262 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -131,6 +131,11 @@ int HardwareSerial::read(void) return -1; } +void HardwareSerial::flush(void) +{ + uartFlush(_uart, false); +} + void HardwareSerial::flush(bool txOnly) { uartFlush(_uart, txOnly); From d7ccd54720b8c527f822e8f38e77450554fe5316 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:26:46 -0600 Subject: [PATCH 07/13] default value error --- cores/esp32/esp32-hal-uart.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index 99a8e6f5ef3..e1f4c3152c5 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -62,7 +62,8 @@ uint8_t uartPeek(uart_t* uart); void uartWrite(uart_t* uart, uint8_t c); void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len); -void uartFlush(uart_t* uart, bool txOnly = false); +void uartFlush(uart_t* uart); +void uartFlush(uart_t* uart, bool txOnly ); void uartSetBaudRate(uart_t* uart, uint32_t baud_rate); uint32_t uartGetBaudRate(uart_t* uart); From fb82400b2c86a66949b54abf8a0ec145dd0e7741 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:28:51 -0600 Subject: [PATCH 08/13] default value error --- cores/esp32/esp32-hal-uart.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 265df72e1a1..29fafd4481d 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -326,6 +326,11 @@ void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len) UART_MUTEX_UNLOCK(); } +vois uartFlush(uart_t* uart) +{ + uartFlush(uart,false); +} + void uartFlush(uart_t* uart, bool txOnly) { if(uart == NULL) { From 16b75899fcb66b45929c88b91ec9f93576a1f684 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:40:12 -0600 Subject: [PATCH 09/13] Update esp32-hal-uart.h --- cores/esp32/esp32-hal-uart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index e1f4c3152c5..2630f9ba469 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -63,7 +63,7 @@ void uartWrite(uart_t* uart, uint8_t c); void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len); void uartFlush(uart_t* uart); -void uartFlush(uart_t* uart, bool txOnly ); +void uartFlushTxOnly(uart_t* uart ); void uartSetBaudRate(uart_t* uart, uint32_t baud_rate); uint32_t uartGetBaudRate(uart_t* uart); From 070836a513eba323cfc9f15b65f4b4d5fa9757bb Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:43:10 -0600 Subject: [PATCH 10/13] Update esp32-hal-uart.c --- cores/esp32/esp32-hal-uart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 29fafd4481d..4f60a0a58ad 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -328,10 +328,10 @@ void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len) vois uartFlush(uart_t* uart) { - uartFlush(uart,false); + uartFlushTxOnly(uart,false); } -void uartFlush(uart_t* uart, bool txOnly) +void uartFlushTxOnly(uart_t* uart, bool txOnly) { if(uart == NULL) { return; From 715fcbe33605c58ee7e4d5ffdd227011277ce2fa Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:44:51 -0600 Subject: [PATCH 11/13] Update HardwareSerial.cpp --- cores/esp32/HardwareSerial.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 749c89dc262..860c2c0f604 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -133,12 +133,12 @@ int HardwareSerial::read(void) void HardwareSerial::flush(void) { - uartFlush(_uart, false); + uartFlush(_uart); } void HardwareSerial::flush(bool txOnly) { - uartFlush(_uart, txOnly); + uartFlushTxOnly(_uart, txOnly); } size_t HardwareSerial::write(uint8_t c) From 62b11df569cb69c24706d5042bf0b161cbf48ea3 Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 12:57:38 -0600 Subject: [PATCH 12/13] sp --- cores/esp32/esp32-hal-uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 4f60a0a58ad..8bb4b185566 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -326,7 +326,7 @@ void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len) UART_MUTEX_UNLOCK(); } -vois uartFlush(uart_t* uart) +void uartFlush(uart_t* uart) { uartFlushTxOnly(uart,false); } From f1628cc6047768debcbffa4e96f5fa33fab5d62f Mon Sep 17 00:00:00 2001 From: chuck todd Date: Wed, 30 Oct 2019 13:03:23 -0600 Subject: [PATCH 13/13] correctly implement flushTxOnly() --- cores/esp32/esp32-hal-uart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index 2630f9ba469..e44d25bbc5e 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -63,7 +63,7 @@ void uartWrite(uart_t* uart, uint8_t c); void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len); void uartFlush(uart_t* uart); -void uartFlushTxOnly(uart_t* uart ); +void uartFlushTxOnly(uart_t* uart, bool txOnly ); void uartSetBaudRate(uart_t* uart, uint32_t baud_rate); uint32_t uartGetBaudRate(uart_t* uart);