From 370c212a48ebe50658d5e12fd3872ac0506d0d82 Mon Sep 17 00:00:00 2001 From: Peter Dons Tychsen Date: Tue, 28 Oct 2025 17:13:34 +0100 Subject: [PATCH 1/6] simple_uart: fix msvc warning --- simple_uart.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/simple_uart.c b/simple_uart.c index 179c6f7..780ba64 100644 --- a/simple_uart.c +++ b/simple_uart.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif /* _MSC_VER */ + #define _GNU_SOURCE #include #include From 0e05e0b41b1e3ff3fdc714b414696c32cca2b5b4 Mon Sep 17 00:00:00 2001 From: Peter Dons Tychsen Date: Tue, 28 Oct 2025 17:14:01 +0100 Subject: [PATCH 2/6] simple_uart: add XON/XOFF --- simple_uart.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/simple_uart.c b/simple_uart.c index 780ba64..c66b22e 100644 --- a/simple_uart.c +++ b/simple_uart.c @@ -256,6 +256,15 @@ static int simple_uart_set_config(struct simple_uart *sc, int speed, const char } else { options.fRtsControl = RTS_CONTROL_DISABLE; } + // XON/XOFF + if (HAS_OPTION('X')) { + options.fOutX = TRUE; + options.fInX = TRUE; + } else { + options.fOutX = FALSE; + options.fInX = FALSE; + } + /* mandatory options */ options.fBinary = TRUE; /* assign to port */ From 819fff73b661d2ae0b4eafa3a27cdc086130e49d Mon Sep 17 00:00:00 2001 From: Peter Dons Tychsen Date: Tue, 28 Oct 2025 17:14:22 +0100 Subject: [PATCH 3/6] simple_uart: default to DTR off --- simple_uart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/simple_uart.c b/simple_uart.c index c66b22e..5752d3f 100644 --- a/simple_uart.c +++ b/simple_uart.c @@ -267,6 +267,7 @@ static int simple_uart_set_config(struct simple_uart *sc, int speed, const char /* mandatory options */ options.fBinary = TRUE; + options.fDtrControl = FALSE; /* assign to port */ if (!SetCommState(sc->port, &options)) return win32_errno(); From e425b9cc6e0f5a1274679ff1713dbf5671303a05 Mon Sep 17 00:00:00 2001 From: Peter Dons Tychsen Date: Tue, 28 Oct 2025 18:03:25 +0100 Subject: [PATCH 4/6] simple_uart: fix build on msvc that does not have vasprintf --- simple_uart.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/simple_uart.c b/simple_uart.c index 5752d3f..13db0cd 100644 --- a/simple_uart.c +++ b/simple_uart.c @@ -756,14 +756,14 @@ int simple_uart_describe(const char *uart, char *description, size_t max_desc_le int simple_uart_set_logfile(struct simple_uart *uart, const char *logfile, ...) { va_list ap; - char *buffer; + char buffer[PATH_MAX]; int len; if (!uart || !logfile) return -EINVAL; va_start(ap, logfile); - len = vasprintf(&buffer, logfile, ap); + len = vsprintf(buffer, logfile, ap); va_end(ap); if (len < 0) return -errno; @@ -774,10 +774,8 @@ int simple_uart_set_logfile(struct simple_uart *uart, const char *logfile, ...) uart->logfile = fopen(buffer, "a"); if (!uart->logfile) { int e = -errno; - free(buffer); return e; } - free(buffer); return 0; } From a4c0babab9ad81ae0a1e1103fac04124a505837a Mon Sep 17 00:00:00 2001 From: Peter Dons Tychsen Date: Tue, 28 Oct 2025 18:04:09 +0100 Subject: [PATCH 5/6] simple_uart: fix missing PATH_MAX on msvc --- simple_uart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/simple_uart.c b/simple_uart.c index 13db0cd..aae2035 100644 --- a/simple_uart.c +++ b/simple_uart.c @@ -1,5 +1,8 @@ #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS +#ifndef PATH_MAX +#define PATH_MAX MAX_PATH +#endif /* PATH_MAX */ #endif /* _MSC_VER */ #define _GNU_SOURCE From d91b0f820ba796e9c2f16e4db6ebe12a4f394f16 Mon Sep 17 00:00:00 2001 From: Peter Dons Tychsen Date: Tue, 28 Oct 2025 18:04:09 +0100 Subject: [PATCH 6/6] simple_uart: fix missing PATH_MAX on msvc simple_uart: fix using of vsprintf simple_uart: support flow control on linux --- simple_uart.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/simple_uart.c b/simple_uart.c index aae2035..8bf2849 100644 --- a/simple_uart.c +++ b/simple_uart.c @@ -376,6 +376,11 @@ static int simple_uart_set_config(struct simple_uart *sc, int speed, const char else options.c_cflag &= ~CRTSCTS; + /* clear and set software flow control */ + options.c_iflag &= (tcflag_t) ~(IXON | IXOFF | IXANY); + if (HAS_OPTION('X')) + options.c_iflag |= IXON | IXOFF; + // raw input mode options.c_lflag &= (tcflag_t) ~(ICANON | ECHO | ECHOE | ISIG); @@ -766,7 +771,7 @@ int simple_uart_set_logfile(struct simple_uart *uart, const char *logfile, ...) return -EINVAL; va_start(ap, logfile); - len = vsprintf(buffer, logfile, ap); + len = vsnprintf(buffer, sizeof(buffer), logfile, ap); va_end(ap); if (len < 0) return -errno;