Skip to content

Commit

Permalink
Update uart.cpp
Browse files Browse the repository at this point in the history
fix for Slow serial baudrates cause exceptions / WDT
credit goes to @d-a-v 
Reference issue: esp8266#7746

Signed-off-by: Hakam Saffour <[email protected]>
  • Loading branch information
HakamSaffour authored Dec 10, 2020
1 parent 2843a5a commit 2e225f7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cores/esp8266/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "esp8266_peri.h"
#include "user_interface.h"
#include "uart_register.h"
#include "coredecls.h"

#define MODE2WIDTH(mode) (((mode%16)>>2)+5)
#define MODE2STOP(mode) (((mode)>>5)+1)
Expand Down Expand Up @@ -505,8 +506,19 @@ uart_write(uart_t* uart, const char* buf, size_t size)

size_t ret = size;
const int uart_nr = uart->uart_nr;
while (size--)
uart_do_write_char(uart_nr, pgm_read_byte(buf++));

if (can_yield() && 100*size/(uart->baud_rate/10) > 0) {
// it takes more than 0.01s to print this string => yielding between chars
// ( <=> (1000*size)/baud>0 <~> (size<<10)/baud > 0 )
while (size--) {
uart_do_write_char(uart_nr, pgm_read_byte(buf++));
yield();
}
} else {
while (size--) {
uart_do_write_char(uart_nr, pgm_read_byte(buf++));
}
}

return ret;
}
Expand Down

0 comments on commit 2e225f7

Please sign in to comment.