From 8877dba7e96115ffbc406461919fca0d5aee8b0b Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Tue, 9 Oct 2018 11:16:05 +0900 Subject: [PATCH] sim: serial: Send '\r\n' instead of just '\n' This fixes an issue when running with the HDMI2USB firmware which expects \r\n to come from the UART. Since the verilator adapter is just sending \n commands cannot be executed. Also, one minor whitespace cleanup. (could remove if needed) --- .../build/sim/core/modules/serial2console/serial2console.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/litex/build/sim/core/modules/serial2console/serial2console.c b/litex/build/sim/core/modules/serial2console/serial2console.c index 20cb12d2e..12704c423 100644 --- a/litex/build/sim/core/modules/serial2console/serial2console.c +++ b/litex/build/sim/core/modules/serial2console/serial2console.c @@ -76,6 +76,11 @@ void read_handler(int fd, short event, void *arg) int i; read_len = read(fd, buffer, 1024); for(i = 0; i < read_len; i++) { + /* If we are reading a newline make sure its \r\n. */ + if (buffer[i] == '\n') { + s->databuf[(s->data_start + s->datalen ) % 2048] = '\r'; + s->datalen++; + } s->databuf[(s->data_start + s->datalen ) % 2048] = buffer[i]; s->datalen++; } @@ -157,7 +162,7 @@ static int serial2console_tick(void *sess) { *s->rx_valid = 0; if(s->datalen) { - *s->rx=s->databuf[s->data_start]; + *s->rx = s->databuf[s->data_start]; s->data_start = (s->data_start + 1) % 2048; s->datalen--; *s->rx_valid = 1;