Skip to content

Commit e147314

Browse files
Re-enable interrupts before directly enqueuing characters in the UART FIFO.
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).
1 parent 4b90db4 commit e147314

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cores/esp8266/HardwareSerial.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,13 @@ size_t HardwareSerial::write(uint8_t c) {
627627
return 0;
628628
_written = true;
629629

630+
bool tx_now = false;
630631
while(true) {
631632
{
632633
InterruptLock il;
633634
if(_tx_buffer->empty()) {
634635
if(uart_get_tx_fifo_room(_uart) > 0) {
635-
uart_transmit_char(_uart, c);
636+
tx_now = true;
636637
} else {
637638
_tx_buffer->write(c);
638639
uart_arm_tx_interrupt(_uart);
@@ -644,6 +645,9 @@ size_t HardwareSerial::write(uint8_t c) {
644645
}
645646
yield();
646647
}
648+
if (tx_now) {
649+
uart_transmit_char(_uart, c);
650+
}
647651
return 1;
648652
}
649653

0 commit comments

Comments
 (0)