From f807222c85118002f1f980dfe4ec00befb083ded Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 2 Mar 2023 12:55:57 -0800 Subject: [PATCH] Demo/CORTEX_M3_MPS2_QEMU_GCC: Provide picolibc syscall implementation Instead of a set of POSIX-compatible APIs as needed by newlib, picolibc needs a FILE struct allocated that references a function to output a single character. Picolibc also doesn't need sbrk as it has its own version Signed-off-by: Keith Packard --- .../Demo/CORTEX_M3_MPS2_QEMU_GCC/syscall.c | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/syscall.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/syscall.c index 6ca04f8da8..2a2e95581a 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/syscall.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/syscall.c @@ -50,8 +50,6 @@ extern unsigned long _heap_bottom; extern unsigned long _heap_top; extern unsigned long g_ulBase; -static void * heap_end = 0; - /** * @brief initializes the UART emulated hardware */ @@ -61,6 +59,34 @@ void uart_init() UART0_ADDR->CTRL = UART_CTRL_TX_EN; } +#ifdef __PICOLIBC__ + +#include + +/** + * @brief Write byte to the UART channel to be displayed on the command line + * with qemu + * @param [in] c byte to send + * @param [in] file ignored + * @returns the character written (cast to unsigned so it is not an error value) + */ + +int +_uart_putc(char c, FILE *file) +{ + (void) file; + UART_DR( UART0_ADDR ) = c; + return (unsigned char) c; +} + +static FILE __stdio = FDEV_SETUP_STREAM(_uart_putc, NULL, NULL, _FDEV_SETUP_WRITE); + +FILE *const stdout = &__stdio; + +#else + +static void * heap_end = 0; + /** * @brief not used anywhere in the code * @todo implement if necessary @@ -132,6 +158,8 @@ void * _sbrk( int incr ) return prev_heap_end; } +#endif + #ifdef __cplusplus } #endif