Skip to content

Commit 4ef0466

Browse files
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.
1 parent c8772cf commit 4ef0466

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cores/esp8266/HardwareSerial.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ void HardwareSerial::flush() {
636636
if(_tx_buffer->getSize() == 0 &&
637637
UART_GET_TX_FIFO_ROOM(uart_nr) >= UART_TX_FIFO_SIZE) {
638638
break;
639+
} else if(il.savedInterruptLevel() > 0) {
640+
_tx_empty_irq();
641+
continue;
639642
}
640643
}
641644
yield();
@@ -663,6 +666,9 @@ size_t HardwareSerial::write(uint8_t c) {
663666
break;
664667
} else if(_tx_buffer->write(c)) {
665668
break;
669+
} else if(il.savedInterruptLevel() > 0) {
670+
_tx_empty_irq();
671+
continue;
666672
}
667673
}
668674
yield();

cores/esp8266/interrupts.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class InterruptLock {
3131
xt_wsr_ps(_state);
3232
}
3333

34+
uint32_t savedInterruptLevel() const {
35+
return _state & 0x0f;
36+
}
37+
3438
protected:
3539
uint32_t _state;
3640
};

0 commit comments

Comments
 (0)