diff --git a/src/platform/PICO/mk/PICO.mk b/src/platform/PICO/mk/PICO.mk index 7809bd06ad..1ad08c7625 100644 --- a/src/platform/PICO/mk/PICO.mk +++ b/src/platform/PICO/mk/PICO.mk @@ -4,10 +4,9 @@ # The top level Makefile adds $(MCU_COMMON_SRC) and $(DEVICE_STDPERIPH_SRC) to SRC collection. # +# PICO_TRACE = 1 DEFAULT_OUTPUT := uf2 -PICO_TRACE = 1 - PICO_LIB_OPTIMISATION := -O2 -fuse-linker-plugin -ffast-math -fmerge-all-constants # This file PICO.mk is $(TARGET_PLATFORM_DIR)/mk/$(TARGET_MCU_FAMILY).mk diff --git a/src/platform/PICO/mk/PICO_trace.mk b/src/platform/PICO/mk/PICO_trace.mk index 41d0cb64a0..4689428376 100644 --- a/src/platform/PICO/mk/PICO_trace.mk +++ b/src/platform/PICO/mk/PICO_trace.mk @@ -1,4 +1,12 @@ +# PICO_trace +# +# Allow tracing into and out of functions without modifying the source code +# +# Enable by setting PICO_TRACE variable in make, e.g. by export PICO_TRACE=1; make ... +# PICO_WRAPPED_FUNCTIONS = main -PICO_WRAPPED_FUNCTIONS += init initEEPROM isEEPROMVersionValid +PICO_WRAPPED_FUNCTIONS += init initEEPROM isEEPROMVersionValid resetEEPROM writeUnmodifiedConfigToEEPROM resetConfig pgResetAll PICO_TRACE_LD_FLAGS += $(foreach fn, $(PICO_WRAPPED_FUNCTIONS), -Wl,--wrap=$(fn)) PICO_TRACE_SRC += PICO/pico_trace.c + +DEVICE_FLAGS += -DPICO_TRACE diff --git a/src/platform/PICO/pico_trace.c b/src/platform/PICO/pico_trace.c index 49c5d6aa5f..a76cca7d11 100644 --- a/src/platform/PICO/pico_trace.c +++ b/src/platform/PICO/pico_trace.c @@ -1,25 +1,102 @@ +/* + * This file is part of Betaflight. + * + * Betaflight is free software. You can redistribute this software + * and/or modify this software under the terms of the GNU General + * Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later + * version. + * + * Betaflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software. + * + * If not, see . + */ + #include "pico_trace.h" +#include "pico/stdio.h" +#include "pico/stdio_uart.h" +#include "pico/platform/compiler.h" + +static int depth; + +static const char* prefix[]= { + "-- ", + "--- ", + "---- ", + "----- ", + "------ ", + "------- " +}; + +static const int plen = sizeof(prefix)/sizeof(prefix[0]); + +void picotrace_prefix(void) +{ + stdio_printf(prefix[depth%plen]); +} // Wrap main to insert the initialisation code. extern int main(int argc, char * argv[]); extern int REAL_FUNC(main)(int argc, char * argv[]); int WRAPPER_FUNC(main)(int argc, char * argv[]) { - stdio_init_all(); - return REAL_FUNC(main)(argc, argv); + //stdio_init_all(); + stdio_uart_init(); + tprintf("\n=== Betaflight main ==="); + depth++; + int mr = REAL_FUNC(main)(argc, argv); + depth--; + tprintf("\n=== Betaflight main end ==="); + return mr; } #define TRACEvoidvoid(x) \ - extern void x(void);\ - extern void REAL_FUNC(x)(void); \ - void WRAPPER_FUNC(x)(void)\ - {\ - tprintf("*** enter " #x " ***");\ - REAL_FUNC(x)();\ - tprintf("*** exit " #x " ***");\ + extern void x(void); \ + extern void REAL_FUNC(x)(void); \ + void WRAPPER_FUNC(x)(void) \ + { \ + tprintf("Enter " #x ""); \ + depth++;REAL_FUNC(x)();depth--; \ + tprintf("Exit " #x ""); \ } +#define TRACEboolvoid(x) \ + extern bool x(void); \ + extern bool REAL_FUNC(x)(void); \ + bool WRAPPER_FUNC(x)(void) \ + { \ + tprintf("Enter " #x ""); \ + depth++; \ + bool ret__ = REAL_FUNC(x)(); \ + depth--; \ + tprintf("Exit " #x ""); \ + return ret__; \ + } + +#define TRACEvoidbool(x) \ + extern void x(bool _); \ + extern void REAL_FUNC(x)(bool _); \ + void WRAPPER_FUNC(x)(bool xyz__) \ + { \ + tprintf("Enter " #x " [%d]", xyz__); \ + depth++; REAL_FUNC(x)(xyz__); depth--; \ + tprintf("Exit " #x ""); \ + } + + // remember to add to PICO_WRAPPED_FUNCTIONS in PICO_trace.mk TRACEvoidvoid(init) -TRACEvoidvoid(initEEPROM) -TRACEvoidvoid(isEEPROMVersionValid) + TRACEvoidvoid(initEEPROM) + TRACEvoidvoid(isEEPROMVersionValid) + TRACEvoidvoid(writeUnmodifiedConfigToEEPROM) + TRACEboolvoid(resetEEPROM) + TRACEvoidvoid(resetConfig) + TRACEvoidvoid(pgResetAll) + TRACEvoidbool(serialInit) diff --git a/src/platform/PICO/pico_trace.h b/src/platform/PICO/pico_trace.h index 78ac3799b8..0f0ef87e97 100644 --- a/src/platform/PICO/pico_trace.h +++ b/src/platform/PICO/pico_trace.h @@ -1,5 +1,10 @@ -#include "pico/stdio.h" -#include "pico/platform/compiler.h" +#pragma once -#define tprintf(fmt,...) do {stdio_printf(fmt, ## __VA_ARGS__); stdio_printf("\n"); } while (0) +extern void picotrace_prefix(void); + +#define tprintf(fmt,...) do { \ + picotrace_prefix(); \ + stdio_printf(fmt, ## __VA_ARGS__); \ + stdio_printf("\n"); \ + } while (0)