From b97d1154d5a4cdd5c38548e6bd85a3409736b07d Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 5 Mar 2022 09:42:44 +0100 Subject: [PATCH] STDIO redirection to USB virtual COM port disabled by default, can be enabled by defining the ENABLE_STDIO macro --- meson.build | 2 +- .../MK22FN512xxx12/boot/libc_integration.cpp | 17 ++++++++++++++++- .../mcu/STM32F4xx/boot/libc_integration.cpp | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 145e4f18..3e0b8e04 100644 --- a/meson.build +++ b/meson.build @@ -9,7 +9,7 @@ project('OpenRTX', ['c', 'cpp'], ## Optional defines, common to all souces (e.g. to enable debugging) ## -def = {'VCOM_ENABLED' : ''} +def = {} ## ## ----------------- Platform-independent source files ------------------------- diff --git a/platform/mcu/MK22FN512xxx12/boot/libc_integration.cpp b/platform/mcu/MK22FN512xxx12/boot/libc_integration.cpp index e02109bc..317f8d93 100644 --- a/platform/mcu/MK22FN512xxx12/boot/libc_integration.cpp +++ b/platform/mcu/MK22FN512xxx12/boot/libc_integration.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2020, 2021 by Silvano Seva IU2KWO * + * Copyright (C) 2020 - 2022 by Silvano Seva IU2KWO * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -32,10 +32,17 @@ extern "C" { */ int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt) { + #ifdef ENABLE_STDIO if(fd == STDOUT_FILENO || fd == STDERR_FILENO) { return vcom_writeBlock(buf, cnt); } + #else + (void) ptr; + (void) fd; + (void) buf; + (void) cnt; + #endif /* If fd is not stdout or stderr */ ptr->_errno = EBADF; @@ -50,6 +57,7 @@ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt) { int ret = -1; + #ifdef ENABLE_STDIO if(fd == STDIN_FILENO) { for(;;) @@ -68,6 +76,13 @@ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt) ptr->_errno = EBADF; ret = -1; } + #else + (void) ptr; + (void) fd; + (void) buf; + (void) cnt; + ptr->_errno = EBADF; + #endif return ret; } diff --git a/platform/mcu/STM32F4xx/boot/libc_integration.cpp b/platform/mcu/STM32F4xx/boot/libc_integration.cpp index 137ba0ce..6435e9e1 100644 --- a/platform/mcu/STM32F4xx/boot/libc_integration.cpp +++ b/platform/mcu/STM32F4xx/boot/libc_integration.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2020, 2021 by Silvano Seva IU2KWO * + * Copyright (C) 2020 - 2022 by Silvano Seva IU2KWO * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -32,11 +32,18 @@ extern "C" { */ int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt) { + #ifdef ENABLE_STDIO if(fd == STDOUT_FILENO || fd == STDERR_FILENO) { vcom_writeBlock(buf, cnt); return cnt; } + #else + (void) ptr; + (void) fd; + (void) buf; + (void) cnt; + #endif /* If fd is not stdout or stderr */ ptr->_errno = EBADF; @@ -49,6 +56,7 @@ int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt) */ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt) { + #ifdef ENABLE_STDIO if(fd == STDIN_FILENO) { for(;;) @@ -57,6 +65,12 @@ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt) if((r < 0) || (r == (ssize_t)(cnt))) return r; } } + #else + (void) ptr; + (void) fd; + (void) buf; + (void) cnt; + #endif /* If fd is not stdin */ ptr->_errno = EBADF;