diff --git a/makefiles/stdio.inc.mk b/makefiles/stdio.inc.mk index e641523145..9749c34177 100644 --- a/makefiles/stdio.inc.mk +++ b/makefiles/stdio.inc.mk @@ -82,7 +82,7 @@ endif # enable stdout buffering for modules that benefit from sending out buffers in larger chunks ifneq (,$(filter picolibc,$(USEMODULE))) - ifneq (,$(filter stdio_cdc_acm stdio_ethos slipdev_stdio stdio_semihosting,$(USEMODULE))) + ifneq (,$(filter stdio_cdc_acm stdio_ethos slipdev_stdio stdio_semihosting stdio_tinyusb_cdc_acm,$(USEMODULE))) USEMODULE += picolibc_stdout_buffered endif endif diff --git a/sys/fmt/fmt.c b/sys/fmt/fmt.c index 11eddf3cfa..c1d6386550 100644 --- a/sys/fmt/fmt.c +++ b/sys/fmt/fmt.c @@ -27,6 +27,7 @@ #include "kernel_defines.h" #include "fmt.h" +#include "stdio_base.h" static const char _hex_chars[16] = "0123456789ABCDEF"; @@ -506,25 +507,24 @@ uint32_t scn_u32_hex(const char *str, size_t n) return res; } +/* native gets special treatment as native's stdio code is ... special. + * And when not building for RIOT, there's no `stdio_write()`. + * In those cases, just defer to `printf()`. + */ +#if IS_USED(MODULE_STDIO_NATIVE) || !defined(RIOT_VERSION) void print(const char *s, size_t n) { - if (IS_USED(MODULE_STDIO_NATIVE)) { - /* native gets special treatment as native's stdio code is ... - * special */ - printf("%.*s", (int)n, s); - return; - } - - while (n > 0) { - ssize_t written; - written = fwrite(s, 1, n, stdout); - if (written < 0) { - break; - } - n -= written; - s += written; - } + printf("%.*s", (int)n, s); } +#else +void print(const char *s, size_t n) +{ + /* flush the libc's output buffer so output is not intermingled. */ + fflush(stdout); + + stdio_write(s, n); +} +#endif void print_u32_dec(uint32_t val) { diff --git a/sys/test_utils/print_stack_usage/print_stack_usage.c b/sys/test_utils/print_stack_usage/print_stack_usage.c index 6b67d6d1ac..b4e8f7c776 100644 --- a/sys/test_utils/print_stack_usage/print_stack_usage.c +++ b/sys/test_utils/print_stack_usage/print_stack_usage.c @@ -26,7 +26,11 @@ #include #endif +#if MODULE_FMT +# define MIN_SIZE (THREAD_STACKSIZE_TINY) +#else # define MIN_SIZE (THREAD_STACKSIZE_TINY + THREAD_EXTRA_STACKSIZE_PRINTF) +#endif void print_stack_usage_metric(const char *name, void *stack, unsigned max_size) { @@ -37,7 +41,7 @@ void print_stack_usage_metric(const char *name, void *stack, unsigned max_size) #if MODULE_FMT print_str("{ \"threads\": [{ \"name\": \""); print_str(name); - print_str(", \"stack_size\": "); + print_str("\", \"stack_size\": "); print_u32_dec(max_size); print_str(", \"stack_used\": "); print_u32_dec(max_size - free);