diff --git a/lib/miosix-kernel b/lib/miosix-kernel index 49b29656..fa5632de 160000 --- a/lib/miosix-kernel +++ b/lib/miosix-kernel @@ -1 +1 @@ -Subproject commit 49b2965680afc759cdaafb9f232f62e7d7a7e1e1 +Subproject commit fa5632de76db04fdf812bbea242cad0e1c1cf691 diff --git a/meson.build b/meson.build index bd3d49f5..ab56ca80 100644 --- a/meson.build +++ b/meson.build @@ -10,6 +10,7 @@ project('OpenRTX', ['c', 'cpp'], ## openrtx_def = {} +#openrtx_def += {'ENABLE_STDIO' : ''} # Enable vcom input/output ## ## UI font configuration, only one uncommented at a time @@ -194,6 +195,7 @@ gdx_src = ['openrtx/src/core/xmodem.c', ## stm32f405_src = ['platform/mcu/STM32F4xx/init.c', + 'platform/mcu/STM32F4xx/libc_integration.cpp', 'platform/mcu/STM32F4xx/drivers/usb/usb_bsp.c', 'platform/mcu/STM32F4xx/drivers/usb/usb_core.c', 'platform/mcu/STM32F4xx/drivers/usb/usb_dcd.c', diff --git a/platform/mcu/MK22FN512xxx12/init_12_288M.c b/platform/mcu/MK22FN512xxx12/init_12_288M.c index 20db546a..67635ea9 100644 --- a/platform/mcu/MK22FN512xxx12/init_12_288M.c +++ b/platform/mcu/MK22FN512xxx12/init_12_288M.c @@ -27,11 +27,14 @@ * in NXP's CMSIS pack files. In this case, it will initialize the clock tree to * full speed, that is, a system clock of 119.808 MHz. * - * The SystemInitHook also sets the vector table offset. + * The SystemInitHook function sets the vector table offset. + * + * The bspInit2_callback function initializes VCOM if STDIO is enabled. */ #include "arch/cortexM4_nxpmk22/nxpmk22f51212_generic/interfaces-impl/arch_registers_impl.h" #include "CMSIS/Device/NXP/MK22FN512xxx12/Include/system_MK22F51212.h" +#include "drivers/usb_vcom.h" extern void (* const __Vectors[])(); @@ -68,3 +71,10 @@ void SystemInitHook(void) SCB->VTOR = (unsigned int)(&__Vectors); // Relocates ISR vector } + +void bspInit2_callback() +{ +#ifdef ENABLE_STDIO + vcom_init(); +#endif +} \ No newline at end of file diff --git a/platform/mcu/STM32F4xx/init.c b/platform/mcu/STM32F4xx/init.c index 6860b4a3..84c3871b 100644 --- a/platform/mcu/STM32F4xx/init.c +++ b/platform/mcu/STM32F4xx/init.c @@ -19,11 +19,14 @@ * This file is mainly used to define the SystemInitHook function. * This function is called at the end of the SystemInit function. * - * The SystemInitHook sets the vector table offset. + * The SystemInitHook function sets the vector table offset + * + * The bspInit2_callback function initializes VCOM if STDIO is enabled. */ #include "arch/cortexM4_stm32f4/stm32f405_generic/interfaces-impl/arch_registers_impl.h" #include "CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h" +#include extern void (* const __Vectors[])(); @@ -31,3 +34,10 @@ void SystemInitHook(void) { SCB->VTOR = (unsigned int)(&__Vectors); // Relocates ISR vector } + +void bspInit2_callback() +{ +#ifdef ENABLE_STDIO + vcom_init(); +#endif +} \ No newline at end of file diff --git a/platform/mcu/STM32F4xx/libc_integration.cpp b/platform/mcu/STM32F4xx/libc_integration.cpp new file mode 100644 index 00000000..4e72dc5f --- /dev/null +++ b/platform/mcu/STM32F4xx/libc_integration.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2020 - 2023 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 * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include +#include "drivers/usb_vcom.h" +#include + +using namespace std; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \internal + * _write_r, write to a file + */ +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; + return -1; +} + +/** + * \internal + * _read_r, read from a file. + */ +int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt) +{ + #ifdef ENABLE_STDIO + if(fd == STDIN_FILENO) + { + for(;;) + { + ssize_t r = vcom_readBlock(buf, 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; + return -1; +} + +#ifdef __cplusplus +} +#endif