Skip to content

Commit 2cf1772

Browse files
committed
fix bug when TX buffer is full and os will write.
in this case we hang endless or until wtd triggers. new: now we overdrive the data in FIFO --> no hang / crash but we loss chars. only happens by extensive use of os_printf!
1 parent 202d38b commit 2cf1772

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp

+20-16
Original file line numberDiff line numberDiff line change
@@ -392,30 +392,34 @@ void uart_ignore_char(char c) {
392392

393393
void uart0_write_char(char c) {
394394
if(&Serial != NULL && Serial.isTxEnabled()) {
395-
if(c == '\n') {
396-
Serial.write('\r');
397-
}
398-
Serial.write(c);
399-
} else {
400-
if(c == '\n') {
401-
USF(0) = '\r';
395+
if(Serial.availableForWrite() > 0) {
396+
if(c == '\n') {
397+
Serial.write('\r');
398+
}
399+
Serial.write(c);
400+
return;
402401
}
403-
USF(0) = c;
404402
}
403+
if(c == '\n') {
404+
USF(0) = '\r';
405+
}
406+
USF(0) = c;
405407
}
406408

407409
void uart1_write_char(char c) {
408410
if(&Serial1 != NULL && Serial1.isTxEnabled()) {
409-
if(c == '\n') {
410-
Serial1.write('\r');
411-
}
412-
Serial1.write(c);
413-
} else {
414-
if(c == '\n') {
415-
USF(1) = '\r';
411+
if(Serial1.availableForWrite() > 0) {
412+
if(c == '\n') {
413+
Serial1.write('\r');
414+
}
415+
Serial1.write(c);
416+
return;
416417
}
417-
USF(1) = c;
418418
}
419+
if(c == '\n') {
420+
USF(1) = '\r';
421+
}
422+
USF(1) = c;
419423
}
420424

421425
static int s_uart_debug_nr = UART0;

0 commit comments

Comments
 (0)