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 <keithpac@amazon.com>
This commit is contained in:
Keith Packard 2023-03-02 12:55:57 -08:00 committed by Paul Bartell
parent 0ecd0f5188
commit f807222c85

View file

@ -50,8 +50,6 @@ extern unsigned long _heap_bottom;
extern unsigned long _heap_top; extern unsigned long _heap_top;
extern unsigned long g_ulBase; extern unsigned long g_ulBase;
static void * heap_end = 0;
/** /**
* @brief initializes the UART emulated hardware * @brief initializes the UART emulated hardware
*/ */
@ -61,6 +59,34 @@ void uart_init()
UART0_ADDR->CTRL = UART_CTRL_TX_EN; UART0_ADDR->CTRL = UART_CTRL_TX_EN;
} }
#ifdef __PICOLIBC__
#include <stdio.h>
/**
* @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 * @brief not used anywhere in the code
* @todo implement if necessary * @todo implement if necessary
@ -132,6 +158,8 @@ void * _sbrk( int incr )
return prev_heap_end; return prev_heap_end;
} }
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif