From e147314f97ce929cade4c678b23484ba082587bc Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 28 Dec 2015 12:17:18 -0500 Subject: [PATCH 01/13] Re-enable interrupts before directly enqueuing characters in the UART FIFO. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure why, but this reduces the occurrence rate of an occasional ~3.25 or ~7μs intercharacter delay, which was interfering with use of the UART to generate precise timing pulses (such as driving WS2812 LEDs). --- cores/esp8266/HardwareSerial.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 3527b4a86..0cddc2ad2 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -627,12 +627,13 @@ size_t HardwareSerial::write(uint8_t c) { return 0; _written = true; + bool tx_now = false; while(true) { { InterruptLock il; if(_tx_buffer->empty()) { if(uart_get_tx_fifo_room(_uart) > 0) { - uart_transmit_char(_uart, c); + tx_now = true; } else { _tx_buffer->write(c); uart_arm_tx_interrupt(_uart); @@ -644,6 +645,9 @@ size_t HardwareSerial::write(uint8_t c) { } yield(); } + if (tx_now) { + uart_transmit_char(_uart, c); + } return 1; } From e83dd4d2415f153dc9b06ed8ec0bf4555bcd2aa5 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 28 Dec 2015 17:53:10 -0500 Subject: [PATCH 02/13] Use lightweight tests when we only care if the buffer is empty or full. --- cores/esp8266/cbuf.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/cbuf.h b/cores/esp8266/cbuf.h index 02b612c5c..4b5157e1a 100644 --- a/cores/esp8266/cbuf.h +++ b/cores/esp8266/cbuf.h @@ -45,18 +45,22 @@ class cbuf { return _begin - _end - 1; } - bool empty() const { + inline bool empty() const { return _begin == _end; } + inline bool full() const { + return wrap_if_bufend(_end + 1) == _begin; + } + int peek() { - if(_end == _begin) return -1; + if(empty()) return -1; return static_cast(*_begin); } int read() { - if(getSize() == 0) return -1; + if(empty()) return -1; char result = *_begin; _begin = wrap_if_bufend(_begin + 1); @@ -80,7 +84,7 @@ class cbuf { } size_t write(char c) { - if(room() == 0) return 0; + if(full()) return 0; *_end = c; _end = wrap_if_bufend(_end + 1); @@ -109,7 +113,7 @@ class cbuf { } private: - inline char* wrap_if_bufend(char* ptr) { + inline char* wrap_if_bufend(char* ptr) const { return (ptr == _bufend) ? _buf : ptr; } From 83398f60119bec102ecc7823b2a367106cddd501 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 28 Dec 2015 16:21:22 -0500 Subject: [PATCH 03/13] Don't bother testing isRxEnabled() on UART1 - it is always false. --- cores/esp8266/HardwareSerial.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 0cddc2ad2..800d021fe 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -133,13 +133,7 @@ void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) { } // -------------- UART 1 -------------- - - if(Serial1.isRxEnabled()) { - while(U1IS & (1 << UIFF)) { - Serial1._rx_complete_irq((char) (U1F & 0xff)); - U1IC = (1 << UIFF); - } - } + // Note: only TX is supported on UART 1. if(Serial1.isTxEnabled()) { if(U1IS & (1 << UIFE)) { U1IC = (1 << UIFE); @@ -294,6 +288,7 @@ uart_t* uart_init(int uart_nr, int baudrate, byte config, byte mode) { IOSWAP &= ~(1 << IOSWAPU0); break; case UART1: + // Note: uart_interrupt_handler does not support RX on UART 1. uart->rxEnabled = false; uart->txEnabled = (mode != SERIAL_RX_ONLY); uart->rxPin = 255; From cfe7ae1118f817f42c020464e2444e51e37da559 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 28 Dec 2015 18:35:27 -0500 Subject: [PATCH 04/13] Put HardwareSerial and cbuf methods called from interrupt context in RAM. This is required per the non-OS SDK doc, which states: "Using non-OS SDK, please do not call any function defined with ICACHE_FLASH_ATTR in the interrupt handler." This avoids an "Illegal instruction" exception with epc1 pointing at a valid instruction (in flash) for one of the moved methods. --- cores/esp8266/HardwareSerial.cpp | 40 ++++++++++++++++----------- cores/esp8266/cbuf.cpp | 46 ++++++++++++++++++++++++++++++++ cores/esp8266/cbuf.h | 25 +++++------------ 3 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 cores/esp8266/cbuf.cpp diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 800d021fe..16094aa66 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -116,6 +116,13 @@ int uart_get_debug(); // #################################################################################################### // #################################################################################################### +// These function internals can be used from interrupt handlers to ensure they +// are in instruction RAM, or anywhere that the uart_nr has been validated. +#define UART_GET_TX_FIFO_ROOM(uart_nr) (UART_TX_FIFO_SIZE - ((USS(uart_nr) >> USTXC) & 0xff)) +#define UART_TRANSMIT_CHAR(uart_nr, c) do { USF(uart_nr) = (c); } while(0) +#define UART_ARM_TX_INTERRUPT(uart_nr) do { USIE(uart_nr) |= (1 << UIFE); } while(0) +#define UART_DISARM_TX_INTERRUPT(uart_nr) do { USIE(uart_nr) &= ~(1 << UIFE); } while(0) + void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) { // -------------- UART 0 -------------- @@ -160,7 +167,7 @@ size_t uart_get_tx_fifo_room(uart_t* uart) { if(uart == 0) return 0; if(uart->txEnabled) { - return UART_TX_FIFO_SIZE - ((USS(uart->uart_nr) >> USTXC) & 0xff); + return UART_GET_TX_FIFO_ROOM(uart->uart_nr); } return 0; } @@ -177,7 +184,7 @@ void uart_transmit_char(uart_t* uart, char c) { if(uart == 0) return; if(uart->txEnabled) { - USF(uart->uart_nr) = c; + UART_TRANSMIT_CHAR(uart->uart_nr, c); } } @@ -241,7 +248,7 @@ void uart_arm_tx_interrupt(uart_t* uart) { if(uart == 0) return; if(uart->txEnabled) { - USIE(uart->uart_nr) |= (1 << UIFE); + UART_ARM_TX_INTERRUPT(uart->uart_nr); } } @@ -249,7 +256,7 @@ void uart_disarm_tx_interrupt(uart_t* uart) { if(uart == 0) return; if(uart->txEnabled) { - USIE(uart->uart_nr) &= ~(1 << UIFE); + UART_DISARM_TX_INTERRUPT(uart->uart_nr); } } @@ -536,13 +543,13 @@ void HardwareSerial::setDebugOutput(bool en) { } } -bool HardwareSerial::isTxEnabled(void) { +bool ICACHE_RAM_ATTR HardwareSerial::isTxEnabled(void) { if(_uart == 0) return false; return _uart->txEnabled; } -bool HardwareSerial::isRxEnabled(void) { +bool ICACHE_RAM_ATTR HardwareSerial::isRxEnabled(void) { if(_uart == 0) return false; return _uart->rxEnabled; @@ -604,11 +611,12 @@ void HardwareSerial::flush() { if(!_written) return; + const int uart_nr = _uart->uart_nr; while(true) { { InterruptLock il; if(_tx_buffer->getSize() == 0 && - uart_get_tx_fifo_room(_uart) >= UART_TX_FIFO_SIZE) { + UART_GET_TX_FIFO_ROOM(uart_nr) >= UART_TX_FIFO_SIZE) { break; } } @@ -623,15 +631,16 @@ size_t HardwareSerial::write(uint8_t c) { _written = true; bool tx_now = false; + const int uart_nr = _uart->uart_nr; while(true) { { InterruptLock il; if(_tx_buffer->empty()) { - if(uart_get_tx_fifo_room(_uart) > 0) { + if(UART_GET_TX_FIFO_ROOM(uart_nr) > 0) { tx_now = true; } else { _tx_buffer->write(c); - uart_arm_tx_interrupt(_uart); + UART_ARM_TX_INTERRUPT(uart_nr); } break; } else if(_tx_buffer->write(c)) { @@ -641,7 +650,7 @@ size_t HardwareSerial::write(uint8_t c) { yield(); } if (tx_now) { - uart_transmit_char(_uart, c); + UART_TRANSMIT_CHAR(uart_nr, c); } return 1; } @@ -650,26 +659,27 @@ HardwareSerial::operator bool() const { return _uart != 0; } -void HardwareSerial::_rx_complete_irq(char c) { +void ICACHE_RAM_ATTR HardwareSerial::_rx_complete_irq(char c) { if(_rx_buffer) { _rx_buffer->write(c); } } -void HardwareSerial::_tx_empty_irq(void) { +void ICACHE_RAM_ATTR HardwareSerial::_tx_empty_irq(void) { if(_uart == 0) return; if(_tx_buffer == 0) return; + const int uart_nr = _uart->uart_nr; size_t queued = _tx_buffer->getSize(); if(!queued) { - uart_disarm_tx_interrupt(_uart); + UART_DISARM_TX_INTERRUPT(uart_nr); return; } - size_t room = uart_get_tx_fifo_room(_uart); + size_t room = UART_GET_TX_FIFO_ROOM(uart_nr); int n = static_cast((queued < room) ? queued : room); while(n--) { - uart_transmit_char(_uart, _tx_buffer->read()); + UART_TRANSMIT_CHAR(uart_nr, _tx_buffer->read()); } } diff --git a/cores/esp8266/cbuf.cpp b/cores/esp8266/cbuf.cpp new file mode 100644 index 000000000..963ac638f --- /dev/null +++ b/cores/esp8266/cbuf.cpp @@ -0,0 +1,46 @@ +/* + cbuf.cpp - Circular buffer implementation + Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "cbuf.h" +#include "c_types.h" + +size_t ICACHE_RAM_ATTR cbuf::getSize() const { + if(_end >= _begin) { + return _end - _begin; + } + return _size - (_begin - _end); +} + +int ICACHE_RAM_ATTR cbuf::read() { + if(empty()) return -1; + + char result = *_begin; + _begin = wrap_if_bufend(_begin + 1); + return result; + return static_cast(result); +} + +size_t ICACHE_RAM_ATTR cbuf::write(char c) { + if(full()) return 0; + + *_end = c; + _end = wrap_if_bufend(_end + 1); + return 1; +} diff --git a/cores/esp8266/cbuf.h b/cores/esp8266/cbuf.h index 4b5157e1a..46f886c31 100644 --- a/cores/esp8266/cbuf.h +++ b/cores/esp8266/cbuf.h @@ -21,7 +21,10 @@ #ifndef __cbuf_h #define __cbuf_h +#include #include +#include + class cbuf { public: cbuf(size_t size) : @@ -32,11 +35,7 @@ class cbuf { delete[] _buf; } - size_t getSize() const { - if(_end >= _begin) return _end - _begin; - - return _size - (_begin - _end); - } + size_t getSize() const; size_t room() const { if(_end >= _begin) { @@ -59,13 +58,7 @@ class cbuf { return static_cast(*_begin); } - int read() { - if(empty()) return -1; - - char result = *_begin; - _begin = wrap_if_bufend(_begin + 1); - return static_cast(result); - } + int read(); size_t read(char* dst, size_t size) { size_t bytes_available = getSize(); @@ -83,13 +76,7 @@ class cbuf { return size_read; } - size_t write(char c) { - if(full()) return 0; - - *_end = c; - _end = wrap_if_bufend(_end + 1); - return 1; - } + size_t write(char c); size_t write(const char* src, size_t size) { size_t bytes_available = room(); From c8772cfcd04630d8c2457096ab6d1f137db7a141 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 28 Dec 2015 19:11:12 -0500 Subject: [PATCH 05/13] Make HardwareSerial::begin() and end() interrupt safe and disable TX/RX if we can't allocate a buffer for them. Prior to this change, the interrupt could fire during initialisation, necessitating a deep check that the HardwareSerial structure had valid _tx_buffer or _rx_buffer each time an interrupt occurred. By keeping uart_t's and HardwareSerial's (txEnabled, _tx_buffer) and (rxEnabled, _rx_buffer) in sync, we can remove this extra check, as well as fixing a null pointer dereference if e.g. _tx_buffer allocation failed and write() was subsequently called. --- cores/esp8266/HardwareSerial.cpp | 50 ++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 16094aa66..3fd5af48b 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -101,7 +101,8 @@ void uart_disarm_tx_interrupt(uart_t* uart); void uart_set_baudrate(uart_t* uart, int baud_rate); int uart_get_baudrate(uart_t* uart); -uart_t* uart_init(int uart_nr, int baudrate, byte config); +uart_t* uart_start_init(int uart_nr, int baudrate, byte config); +void uart_finish_init(uart_t* uart); void uart_uninit(uart_t* uart); void uart_swap(uart_t* uart); @@ -273,9 +274,8 @@ int uart_get_baudrate(uart_t* uart) { return uart->baud_rate; } -uart_t* uart_init(int uart_nr, int baudrate, byte config, byte mode) { +uart_t* uart_start_init(int uart_nr, int baudrate, byte config, byte mode) { - uint32_t conf1 = 0x00000000; uart_t* uart = (uart_t*) os_malloc(sizeof(uart_t)); if(uart == 0) { @@ -311,6 +311,12 @@ uart_t* uart_init(int uart_nr, int baudrate, byte config, byte mode) { uart_set_baudrate(uart, baudrate); USC0(uart->uart_nr) = config; + return uart; +} + +void uart_finish_init(uart_t* uart) { + uint32_t conf1 = 0x00000000; + uart_flush(uart); uart_interrupt_enable(uart); @@ -323,8 +329,6 @@ uart_t* uart_init(int uart_nr, int baudrate, byte config, byte mode) { } USC1(uart->uart_nr) = conf1; - - return uart; } void uart_uninit(uart_t* uart) { @@ -485,31 +489,45 @@ HardwareSerial::HardwareSerial(int uart_nr) : } void HardwareSerial::begin(unsigned long baud, byte config, byte mode) { + InterruptLock il; // disable debug for this interface if(uart_get_debug() == _uart_nr) { uart_set_debug(UART_NO); } - _uart = uart_init(_uart_nr, baud, config, mode); + if (_uart) { + os_free(_uart); + } + _uart = uart_start_init(_uart_nr, baud, config, mode); if(_uart == 0) { return; } - if(_uart->rxEnabled) { - if(!_rx_buffer) - _rx_buffer = new cbuf(SERIAL_RX_BUFFER_SIZE); + // Disable the RX and/or TX functions if we fail to allocate circular buffers. + // The user can confirm they are enabled with isRxEnabled() and isTxEnabled(). + if(_uart->rxEnabled && !_rx_buffer) { + _rx_buffer = new cbuf(SERIAL_RX_BUFFER_SIZE); + if(!_rx_buffer) { + _uart->rxEnabled = false; + } } - if(_uart->txEnabled) { - if(!_tx_buffer) - _tx_buffer = new cbuf(SERIAL_TX_BUFFER_SIZE); + if(_uart->txEnabled && !_tx_buffer) { + _tx_buffer = new cbuf(SERIAL_TX_BUFFER_SIZE); + if(!_tx_buffer) { + _uart->txEnabled = false; + } } _written = false; delay(1); + + uart_finish_init(_uart); } void HardwareSerial::end() { + InterruptLock il; + if(uart_get_debug() == _uart_nr) { uart_set_debug(UART_NO); } @@ -660,16 +678,10 @@ HardwareSerial::operator bool() const { } void ICACHE_RAM_ATTR HardwareSerial::_rx_complete_irq(char c) { - if(_rx_buffer) { - _rx_buffer->write(c); - } + _rx_buffer->write(c); } void ICACHE_RAM_ATTR HardwareSerial::_tx_empty_irq(void) { - if(_uart == 0) - return; - if(_tx_buffer == 0) - return; const int uart_nr = _uart->uart_nr; size_t queued = _tx_buffer->getSize(); if(!queued) { From 4ef0466578f84f6ba3e67204e450606d65ef88d0 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Tue, 29 Dec 2015 12:05:15 -0500 Subject: [PATCH 06/13] Don't trip the WDT if interrupts are disabled during write() or flush(). Prior to this change, if interrupts were disabled during a call to HardwareSerial::write() when the circular buffer was full, or HardwareSerial::flush() when the circular buffer was non-empty, we would loop forever and trip a watchdog timeout. --- cores/esp8266/HardwareSerial.cpp | 6 ++++++ cores/esp8266/interrupts.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 3fd5af48b..b0f6861d2 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -636,6 +636,9 @@ void HardwareSerial::flush() { if(_tx_buffer->getSize() == 0 && UART_GET_TX_FIFO_ROOM(uart_nr) >= UART_TX_FIFO_SIZE) { break; + } else if(il.savedInterruptLevel() > 0) { + _tx_empty_irq(); + continue; } } yield(); @@ -663,6 +666,9 @@ size_t HardwareSerial::write(uint8_t c) { break; } else if(_tx_buffer->write(c)) { break; + } else if(il.savedInterruptLevel() > 0) { + _tx_empty_irq(); + continue; } } yield(); diff --git a/cores/esp8266/interrupts.h b/cores/esp8266/interrupts.h index 813997447..b4a2ed44b 100644 --- a/cores/esp8266/interrupts.h +++ b/cores/esp8266/interrupts.h @@ -31,6 +31,10 @@ public: xt_wsr_ps(_state); } + uint32_t savedInterruptLevel() const { + return _state & 0x0f; + } + protected: uint32_t _state; }; From 2375fb0f865dd16895a02cfcaa574f8fb0d79771 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Mon, 14 Dec 2015 21:37:29 -0800 Subject: [PATCH 07/13] Cleanup: remove unused includes of cbuf.h. --- libraries/ESP8266WiFi/src/WiFiClient.cpp | 1 - libraries/ESP8266WiFi/src/WiFiClientSecure.cpp | 1 - libraries/ESP8266WiFi/src/WiFiServer.cpp | 1 - 3 files changed, 3 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClient.cpp b/libraries/ESP8266WiFi/src/WiFiClient.cpp index 672fff4b2..c2c6966f2 100644 --- a/libraries/ESP8266WiFi/src/WiFiClient.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClient.cpp @@ -38,7 +38,6 @@ extern "C" #include "lwip/tcp.h" #include "lwip/inet.h" #include "lwip/netif.h" -#include "cbuf.h" #include "include/ClientContext.h" #include "c_types.h" diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp index 484a23fc0..bf4252275 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp @@ -37,7 +37,6 @@ extern "C" #include "lwip/tcp.h" #include "lwip/inet.h" #include "lwip/netif.h" -#include "cbuf.h" #include "include/ClientContext.h" #include "c_types.h" diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index 462e7d7de..c58a91476 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -35,7 +35,6 @@ extern "C" { #include "lwip/opt.h" #include "lwip/tcp.h" #include "lwip/inet.h" -#include "cbuf.h" #include "include/ClientContext.h" WiFiServer::WiFiServer(IPAddress addr, uint16_t port) From bc9493e690c5483b268e38ff291bc5a5db0279fb Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Tue, 29 Dec 2015 12:46:25 -0500 Subject: [PATCH 08/13] Remove tracking of whether write() was called. Tracking _written was required on AVR devices to work around a hardware limitation when implementing flush(). The ESP8266 doesn't have the same issue, so we can remove the tracking and make write() more lightweight. The cost is a minor increase in work done in flush() when write() was not previously called, but this should be much rarer than individual character writes. --- cores/esp8266/HardwareSerial.cpp | 7 +------ cores/esp8266/HardwareSerial.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index b0f6861d2..1939bbcbb 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -485,7 +485,7 @@ int uart_get_debug() { // #################################################################################################### HardwareSerial::HardwareSerial(int uart_nr) : - _uart_nr(uart_nr), _uart(0), _tx_buffer(0), _rx_buffer(0), _written(false) { + _uart_nr(uart_nr), _uart(0), _tx_buffer(0), _rx_buffer(0) { } void HardwareSerial::begin(unsigned long baud, byte config, byte mode) { @@ -519,7 +519,6 @@ void HardwareSerial::begin(unsigned long baud, byte config, byte mode) { _uart->txEnabled = false; } } - _written = false; delay(1); uart_finish_init(_uart); @@ -626,8 +625,6 @@ void HardwareSerial::flush() { return; if(!_uart->txEnabled) return; - if(!_written) - return; const int uart_nr = _uart->uart_nr; while(true) { @@ -643,13 +640,11 @@ void HardwareSerial::flush() { } yield(); } - _written = false; } size_t HardwareSerial::write(uint8_t c) { if(_uart == 0 || !_uart->txEnabled) return 0; - _written = true; bool tx_now = false; const int uart_nr = _uart->uart_nr; diff --git a/cores/esp8266/HardwareSerial.h b/cores/esp8266/HardwareSerial.h index 123aa7adc..f2a108a5e 100644 --- a/cores/esp8266/HardwareSerial.h +++ b/cores/esp8266/HardwareSerial.h @@ -117,7 +117,6 @@ class HardwareSerial: public Stream { uart_t* _uart; cbuf* _tx_buffer; cbuf* _rx_buffer; - bool _written; }; extern HardwareSerial Serial; From 9d7c2fd5be4c734d8915f91b821fdcd7602de055 Mon Sep 17 00:00:00 2001 From: Christopher Pascoe Date: Tue, 29 Dec 2015 17:04:15 -0500 Subject: [PATCH 09/13] Remove duplicate 'return' (copy-and-paste error). --- cores/esp8266/cbuf.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/cores/esp8266/cbuf.cpp b/cores/esp8266/cbuf.cpp index 963ac638f..8f36cf8a2 100644 --- a/cores/esp8266/cbuf.cpp +++ b/cores/esp8266/cbuf.cpp @@ -33,7 +33,6 @@ int ICACHE_RAM_ATTR cbuf::read() { char result = *_begin; _begin = wrap_if_bufend(_begin + 1); - return result; return static_cast(result); } From d2a357e6933a31e9d4f6a397c3d9163f117be1c1 Mon Sep 17 00:00:00 2001 From: Matthew O'Gorman Date: Sun, 3 Jan 2016 23:33:48 -0500 Subject: [PATCH 10/13] add support for manually selecting ip and port for host side --- tools/espota.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/espota.py b/tools/espota.py index 9913f0045..d3b125492 100755 --- a/tools/espota.py +++ b/tools/espota.py @@ -5,11 +5,12 @@ # # Modified since 2015-09-18 from Pascal Gollor (https://github.com/pgollor) # Modified since 2015-11-09 from Hristo Gochkov (https://github.com/me-no-dev) +# Modified since 2016-01-03 from Matthew O'Gorman (https://githumb.com/mogorman) # # This script will push an OTA update to the ESP -# use it like: python espota.py -i -p [-a password] -f +# use it like: python espota.py -i -I -p -P [-a password] -f # Or to upload SPIFFS image: -# python espota.py -i -p [-a password] -s -f +# python espota.py -i -I -p -P [-a password] -s -f # # Changes # 2015-09-18: @@ -22,6 +23,10 @@ # - Added digest authentication # - Enchanced error tracking and reporting # +# Changes +# 2016-01-03: +# - Added more options to parser. +# from __future__ import print_function import socket @@ -64,11 +69,10 @@ def update_progress(progress): sys.stderr.write('.') sys.stderr.flush() -def serve(remoteAddr, remotePort, password, filename, command = FLASH): +def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, command = FLASH): # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - serverPort = random.randint(10000,60000) - server_address = ('0.0.0.0', serverPort) + server_address = (localAddr, localPort) logging.info('Starting on %s:%s', str(server_address[0]), str(server_address[1])) try: sock.bind(server_address) @@ -82,7 +86,7 @@ def serve(remoteAddr, remotePort, password, filename, command = FLASH): file_md5 = hashlib.md5(f.read()).hexdigest() f.close() logging.info('Upload size: %d', content_size) - message = '%d %d %d %s\n' % (command, serverPort, content_size, file_md5) + message = '%d %d %d %s\n' % (command, localPort, content_size, file_md5) # Wait for a connection logging.info('Sending invitation to: %s', remoteAddr) @@ -209,12 +213,24 @@ def parser(): help = "ESP8266 IP Address.", default = False ) + group.add_option("-I", "--host_ip", + dest = "host_ip", + action = "store", + help = "Host IP Address.", + default = "0.0.0.0" + ) group.add_option("-p", "--port", dest = "esp_port", type = "int", help = "ESP8266 ota Port. Default 8266", default = 8266 ) + group.add_option("-P", "--host_port", + dest = "host_port", + type = "int", + help = "Host server ota Port. Default random 10000-60000", + default = random.randint(10000,60000) + ) parser.add_option_group(group) # auth @@ -294,7 +310,7 @@ def main(args): command = SPIFFS # end if - return serve(options.esp_ip, options.esp_port, options.auth, options.image, command) + return serve(options.esp_ip, options.host_ip, options.esp_port, options.host_port, options.auth, options.image, command) # end main From 43a55bd404b369691fdc50a837cd586eac3198ab Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 4 Jan 2016 17:25:23 +0300 Subject: [PATCH 11/13] Update changelog --- doc/changes.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/changes.md b/doc/changes.md index 7d19d6166..763371c3c 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -6,10 +6,44 @@ title: Change Log ### Core +- Allow control of enabling debug and debug level from IDE +- Make HardwareSerial::begin() and end() interrupt safe +- Put HardwareSerial and cbuf methods called from interrupt context in RAM +- Re-enable interrupts before directly enqueuing characters in the UART FIFO +- Add espduino board +- Rework StreamString::write to use String internal buffer directly (#1289) +- Add function to measure stack high water mark +- Update SDK to esp_iot_sdk_v1.5.0_15_12_15_p1 +- Fix RAM corruption caused by our hook of register_chipv6_phy(init_data*). +- Optimize PWM interrupt handler for better precision +- Add warning levels configurable through Preferences +- Protect HardwareSerial's cbuf usage with InterruptLock +- SPIFFS: check if path length is valid (#1089) +- Set CPU frequency before running setup +- Add core_esp8266_features.h to be able to detect the features and libraries included in the ESP core +- Added ESPino to supported boards + ### Libraries +- ESP8266HTTPClient: add CHUNKED encoding support (#1324) +- Fixed crash bug with mDNS where a string buffer could be used uninitialized +- Add WiFi TX power control +- Add WiFi sleep management +- Allow to hook into WiFi events from sketch +- Allow setting TCP timeout +- Add setSleepMode + getSleepMode and setPhyMode + getPhyMode to WiFi +- Update GDBStub library with the source of esp-gdbstub +- Servo: fix detach and attach +- ESP8266mDNS: refactoring, add TXT support +- Add HTTP Basic Auth to WebServer and libb64 (base64) to core +- Fix link-time dependency of ESP8266WebServer on SPIFFS (#862) +- Allow setting client side TLS key and certificate +- Replace chain of UDP pbufs with a single pbuf before sending (#1009) + ### Tools +- espota.py: add support for manually selecting ip and port for host side + --- ## 2.0.0 November 30, 2015 From a995643e7d5a78c751caec93a0061d80e3eedfa5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 4 Jan 2016 18:36:03 +0300 Subject: [PATCH 12/13] Update Readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fdb199842..c12cde778 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ ESP8266 Arduino core comes with libraries to communicate over WiFi using TCP and - [Using git version](#using-git-version-) - [Using stable version with PlatformIO](#using-stable-version-with-platformio) - [Documentation](#documentation) -- [Issues and support](#issues-and-support) +- [Issues and support](#issues-and-support) - [Contributing](#contributing) - [License and credits](#license-and-credits) @@ -25,7 +25,7 @@ Starting with 1.6.4, Arduino allows installation of third-party platform package - Open Boards Manager from Tools > Board menu and install *esp8266* platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation). The best place to ask questions related to this core is ESP8266 community forum: http://www.esp8266.com/arduino. -If you find this ESP8266 board manager useful, please consider supporting it with a donation. The ESP8266 Community Forum and IGRR have made this wonderful port available. +If you find this forum or the ESP8266 Boards Manager package useful, please consider supporting it with a donation. [![Donate](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/webscr?cmd=_s-xclick&hosted_button_id=4M56YCWV6PX66) #### Available versions @@ -38,11 +38,11 @@ Documentation: [http://esp8266.github.io/Arduino/versions/2.0.0/](http://esp8266 ##### Staging version ![](http://arduino.esp8266.com/staging/badge.svg) Boards manager link: `http://arduino.esp8266.com/staging/package_esp8266com_index.json` -Documentation: [http://esp8266.github.io/Arduino/versions/2.0.0-rc2/](http://esp8266.github.io/Arduino/versions/2.0.0-rc2/) +Documentation: [http://esp8266.github.io/Arduino/versions/2.1.0-rc1/](http://esp8266.github.io/Arduino/versions/2.1.0-rc1/) ### Using git version [![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino) -- Install Arduino 1.6.5 +- Install Arduino 1.6.7 - Go to Arduino directory - Clone this repository into hardware/esp8266com/esp8266 directory (or clone it elsewhere and create a symlink) ```bash From 971bba13dd9ae2a2ec9b26f016174511ecdcaac5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 4 Jan 2016 18:36:28 +0300 Subject: [PATCH 13/13] Update release tools --- package/build_boards_manager_package.sh | 2 +- package/esp8266-arudino-doc.bash | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package/build_boards_manager_package.sh b/package/build_boards_manager_package.sh index 261dd2afd..9adf03f00 100755 --- a/package/build_boards_manager_package.sh +++ b/package/build_boards_manager_package.sh @@ -39,7 +39,7 @@ cat << EOF > exclude.txt package EOF # Also include all files which are ignored by git -git ls-files --other --ignored --exclude-standard --directory >> exclude.txt +git ls-files --other --directory >> exclude.txt # Now copy files to $outdir rsync -a --exclude-from 'exclude.txt' $srcdir/ $outdir/ rm exclude.txt diff --git a/package/esp8266-arudino-doc.bash b/package/esp8266-arudino-doc.bash index 25e3dc036..90914b000 100755 --- a/package/esp8266-arudino-doc.bash +++ b/package/esp8266-arudino-doc.bash @@ -24,8 +24,9 @@ set -e # some variable definitions tmp_path=$1 -arduinoESP_src="$tmp_path/arduino" -version="$(git --work-tree=$arduinoESP_src describe --tags --always)" +doc_src_path=$2 +arduinoESP_src=$(cd $PWD/..; pwd) +version="$(git --work-tree=$arduinoESP_src --git-dir=$arduinoESP_src/.git describe --tags --always)" release_date=$(date "+%b_%d,_%Y") # format for badge link build_date=$(date "+%b %d, %Y") destination_path="$tmp_path/doc" @@ -62,7 +63,8 @@ mkdir -p $destination_path/$version cp -R $arduinoESP_src/doc/* $destination_path/src # download doc template -git clone $doc_template_url $destination_path/build +rsync -av $doc_src_path/ $destination_path/build/ +# git clone $doc_template_url $destination_path/build # create versions.html file @@ -113,4 +115,3 @@ popd # grab badge wget -q -O $destination_path/$version/badge.svg "https://img.shields.io/badge/updated-$release_date-blue.svg" -