diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 8ab7b49ae..c3bbf28e7 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -358,6 +358,7 @@ if SYSTEM_VIEW: 'embed/segger/SEGGER/SEGGER_SYSVIEW.c', 'embed/segger/SEGGER/SEGGER_RTT.c', 'embed/segger/SEGGER/SEGGER_RTT_ASM_ARMv7M.S', + 'embed/segger/SEGGER/Syscalls/SEGGER_RTT_Syscalls_GCC.c', 'embed/firmware/systemview.c', ] CPPPATH_MOD += [ @@ -365,6 +366,7 @@ if SYSTEM_VIEW: 'embed/segger/Config/', ] CPPDEFINES_MOD += ['SYSTEM_VIEW'] + CCFLAGS_MOD += '-DSYSTEM_VIEW ' SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED diff --git a/core/embed/firmware/mpconfigport.h b/core/embed/firmware/mpconfigport.h index 82846b035..0666b8bbb 100644 --- a/core/embed/firmware/mpconfigport.h +++ b/core/embed/firmware/mpconfigport.h @@ -156,6 +156,13 @@ #define MICROPY_PY_TREZORUI (1) #define MICROPY_PY_TREZORUTILS (1) +#ifdef SYSTEM_VIEW +#define MP_PLAT_PRINT_STRN(str, len) segger_print(str, len) +// set following to 0 if you want to print to RTT instead of SystemView +// openocd supports only the RTT output method +#define SYSTEMVIEW_DEST_SYSTEMVIEW (1) +#endif + #define MP_STATE_PORT MP_STATE_VM // ============= this ends common config section =================== diff --git a/core/embed/firmware/mphalport.c b/core/embed/firmware/mphalport.c index 493f475e7..339a907fe 100644 --- a/core/embed/firmware/mphalport.c +++ b/core/embed/firmware/mphalport.c @@ -19,9 +19,8 @@ #include "common.h" #include "py/mphal.h" -#include "usb.h" -#include "systemview.h" #include "string.h" +#include "usb.h" static int vcp_iface_num = -1; @@ -43,15 +42,3 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) { } void mp_hal_set_vcp_iface(int iface_num) { vcp_iface_num = iface_num; } - -#ifdef SYSTEM_VIEW -int segger_print(const char* str, size_t len) { - static char str_copy[1024]; - size_t copylen = len > 1023 ? 1023 : len; - memcpy(str_copy, str, copylen); - str_copy[copylen] = 0; - SEGGER_SYSVIEW_Print(str_copy); - return len; -} -#endif - diff --git a/core/embed/firmware/systemview.c b/core/embed/firmware/systemview.c index 0c48e6a5c..10f3ecf52 100644 --- a/core/embed/firmware/systemview.c +++ b/core/embed/firmware/systemview.c @@ -2,6 +2,9 @@ #include "systemview.h" #include +#include +#include +#include "mpconfigport.h" #include "SEGGER_SYSVIEW.h" #include "SEGGER_SYSVIEW_Conf.h" @@ -94,4 +97,19 @@ void enable_systemview() { SYSTICK->CSR = 0x07; // enable systick } +size_t _write(int file, const void *ptr, size_t len); + +size_t segger_print(const char *str, size_t len) { +#if SYSTEMVIEW_DEST_SYSTEMVIEW + static char str_copy[1024]; + size_t copylen = len > 1023 ? 1023 : len; + memcpy(str_copy, str, copylen); + str_copy[copylen] = 0; + SEGGER_SYSVIEW_Print(str_copy); + return len; +#else + _write(0, str, len); + return len; +#endif +} #endif