From 5b52671c508d88064c2593f9a5aad8ecf53ac120 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sat, 16 Dec 2023 22:15:35 +0100 Subject: [PATCH] ports/sh: improve USB debugging behavior - Set MP_DEBUG_PRINTER to go through DEBUG_printf instead of the console, which is important when the former is USB. - Disable malloc/gc_alloc messages to avoid spamming USB debug log. --- ports/sh/debug.c | 8 ++++++++ ports/sh/mpconfigport.h | 7 +++++++ py/gc.c | 2 +- py/malloc.c | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ports/sh/debug.c b/ports/sh/debug.c index d74c360b6..6f6b16c66 100644 --- a/ports/sh/debug.c +++ b/ports/sh/debug.c @@ -74,6 +74,14 @@ int pe_debug_printf(char const *fmt, ...) int DEBUG_printf(char const *fmt, ...) __attribute__((alias("pe_debug_printf"))); +static void print_strn(void *env, const char *str, size_t len) { + (void)env; + usb_open_wait(); + usb_fxlink_text(str, len); +} + +mp_print_t const mp_debug_print = { NULL, print_strn }; + void pe_debug_kmalloc(void) { kmalloc_gint_stats_t *s; diff --git a/ports/sh/mpconfigport.h b/ports/sh/mpconfigport.h index ec6b62129..bbbf55deb 100644 --- a/ports/sh/mpconfigport.h +++ b/ports/sh/mpconfigport.h @@ -14,6 +14,13 @@ /* PythonExtra's main debug flag */ #define PE_DEBUG (0) #define MICROPY_DEBUG_VERBOSE (0) +/* Custom flag to remove DEBUG_printf in alloc/GC (very verbose) */ +#define MICROPY_DEBUG_VERBOSE_ALLOC (0) + +#if PE_DEBUG +extern const struct _mp_print_t mp_debug_print; +#define MICROPY_DEBUG_PRINTER (&mp_debug_print) +#endif /* General feature set selection Other options: BASIC_FEATURES, EXTRA_FEATURES, FULL_FEATURES, EVERYTHING */ diff --git a/py/gc.c b/py/gc.c index 30e2e5922..f7a054bcc 100644 --- a/py/gc.c +++ b/py/gc.c @@ -34,7 +34,7 @@ #if MICROPY_ENABLE_GC -#if MICROPY_DEBUG_VERBOSE // print debugging info +#if MICROPY_DEBUG_VERBOSE && MICROPY_DEBUG_VERBOSE_ALLOC #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf #else // don't print debugging info diff --git a/py/malloc.c b/py/malloc.c index ddf139e38..960d865e9 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -32,7 +32,7 @@ #include "py/misc.h" #include "py/mpstate.h" -#if MICROPY_DEBUG_VERBOSE // print debugging info +#if MICROPY_DEBUG_VERBOSE && MICROPY_DEBUG_VERBOSE_ALLOC #define DEBUG_printf DEBUG_printf #else // don't print debugging info #define DEBUG_printf(...) (void)0