From 0276148613b2da796e8ee460a6341328232d571d Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Mon, 6 Apr 2015 19:15:10 +0200 Subject: [PATCH] fix printf corrupts Serial.print --- cores/esp8266/HardwareSerial.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 1a0f87d28..a5e733f2c 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -394,17 +394,31 @@ void ICACHE_FLASH_ATTR uart_ignore_char(char c) { } void ICACHE_FLASH_ATTR uart0_write_char(char c) { - if(c == '\n') { - WRITE_PERI_REG(UART_FIFO(0), '\r'); - } - WRITE_PERI_REG(UART_FIFO(0), c); + if(&Serial != NULL && Serial.isTxEnabled()) { + if(c == '\n') { + Serial.write('\r'); + } + Serial.write(c); + } else { + if(c == '\n') { + WRITE_PERI_REG(UART_FIFO(0), '\r'); + } + WRITE_PERI_REG(UART_FIFO(0), c); + } } void ICACHE_FLASH_ATTR uart1_write_char(char c) { - if(c == '\n') { - WRITE_PERI_REG(UART_FIFO(1), '\r'); - } - WRITE_PERI_REG(UART_FIFO(1), c); + if(&Serial1 != NULL && Serial1.isTxEnabled()) { + if(c == '\n') { + Serial1.write('\r'); + } + Serial1.write(c); + } else { + if(c == '\n') { + WRITE_PERI_REG(UART_FIFO(1), '\r'); + } + WRITE_PERI_REG(UART_FIFO(1), c); + } } static UARTnr_t s_uart_debug_nr = UART_NO;