Skip to content

Commit 78dc2db

Browse files
committed
py/mpconfig: Provide config option for internal printf printer.
The C-level printf is usually used for internal debugging prints, and a port/board may want to redirect this somewhere other than stdout. Signed-off-by: Damien George <[email protected]>
1 parent b3c8ab3 commit 78dc2db

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,11 @@ typedef double mp_float_t;
904904
#define MICROPY_USE_INTERNAL_PRINTF (1)
905905
#endif
906906

907+
// The mp_print_t printer used for printf output when MICROPY_USE_INTERNAL_PRINTF is enabled
908+
#ifndef MICROPY_INTERNAL_PRINTF_PRINTER
909+
#define MICROPY_INTERNAL_PRINTF_PRINTER (&mp_plat_print)
910+
#endif
911+
907912
// Support for internal scheduler
908913
#ifndef MICROPY_ENABLE_SCHEDULER
909914
#define MICROPY_ENABLE_SCHEDULER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)

shared/libc/printf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ int snprintf(char *str, size_t size, const char *fmt, ...);
6060
int printf(const char *fmt, ...) {
6161
va_list ap;
6262
va_start(ap, fmt);
63-
int ret = mp_vprintf(&mp_plat_print, fmt, ap);
63+
int ret = mp_vprintf(MICROPY_INTERNAL_PRINTF_PRINTER, fmt, ap);
6464
va_end(ap);
6565
return ret;
6666
}
6767

6868
int vprintf(const char *fmt, va_list ap) {
69-
return mp_vprintf(&mp_plat_print, fmt, ap);
69+
return mp_vprintf(MICROPY_INTERNAL_PRINTF_PRINTER, fmt, ap);
7070
}
7171

7272
// need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a')

0 commit comments

Comments
 (0)