Allow using Segger RTT as debug output (#3052)

Firmware needs to be built with -DDEBUG=YES and -DDEBUG_SEGGER_RTT=YES to use this feature.
This commit is contained in:
Cliff
2023-01-23 09:08:31 +01:00
committed by GitHub
parent 15dca01f42
commit 0b8e4c6003
7 changed files with 69 additions and 12 deletions
+3
View File
@@ -11,3 +11,6 @@
path = radio/src/thirdparty/FreeRTOS path = radio/src/thirdparty/FreeRTOS
url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git
shallow = true shallow = true
[submodule "radio/src/thirdparty/Segger_RTT"]
path = radio/src/thirdparty/Segger_RTT
url = https://github.com/adfernandes/segger-rtt.git
+7 -1
View File
@@ -44,6 +44,7 @@ option(RAS "RAS (SWR) enabled" ON)
option(TEMPLATES "Model templates menu" OFF) option(TEMPLATES "Model templates menu" OFF)
option(TRACE_SIMPGMSPACE "Turn on traces in simpgmspace.cpp" ON) option(TRACE_SIMPGMSPACE "Turn on traces in simpgmspace.cpp" ON)
option(TRACE_LUA_INTERNALS "Turn on traces for Lua internals" OFF) option(TRACE_LUA_INTERNALS "Turn on traces for Lua internals" OFF)
option(DEBUG_SEGGER_RTT "Debug output to Segger RTT" OFF)
option(DEBUG_WINDOWS "Turn on windows traces" OFF) option(DEBUG_WINDOWS "Turn on windows traces" OFF)
option(DEBUG_YAML "Turn on YAML traces" OFF) option(DEBUG_YAML "Turn on YAML traces" OFF)
option(DEBUG_LABELS "Turn on Labels traces" OFF) option(DEBUG_LABELS "Turn on Labels traces" OFF)
@@ -365,6 +366,11 @@ if(TRACE_LUA_INTERNALS)
add_definitions(-DTRACE_LUA_INTERNALS_ENABLED) add_definitions(-DTRACE_LUA_INTERNALS_ENABLED)
endif() endif()
if(DEBUG_SEGGER_RTT)
add_definitions(-DDEBUG_SEGGER_RTT)
set(SRC ${SRC} ${THIRDPARTY_DIR}/Segger_RTT/RTT/SEGGER_RTT.c)
endif()
if(DEBUG_WINDOWS) if(DEBUG_WINDOWS)
add_definitions(-DDEBUG_WINDOWS) add_definitions(-DDEBUG_WINDOWS)
endif() endif()
@@ -520,7 +526,7 @@ if(NATIVE_BUILD)
target_compile_options(radiolib_native PUBLIC -DSIMU) target_compile_options(radiolib_native PUBLIC -DSIMU)
add_dependencies(radiolib_native ${RADIO_DEPENDENCIES}) add_dependencies(radiolib_native ${RADIO_DEPENDENCIES})
set_property(TARGET radiolib_native PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET radiolib_native PROPERTY POSITION_INDEPENDENT_CODE ON)
add_subdirectory(targets/simu) add_subdirectory(targets/simu)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
+2 -2
View File
@@ -139,7 +139,7 @@ void dumpTraceBuffer()
" notd", // INT_OTG_FS_RX_NOT_DEVICE, " notd", // INT_OTG_FS_RX_NOT_DEVICE,
#endif // #if defined(DEBUG_USB_INTERRUPTS) #endif // #if defined(DEBUG_USB_INTERRUPTS)
}; };
#elif defined(PCBTARANIS) #elif defined(PCBTARANIS)
const char * const interruptNames[INT_LAST] = { const char * const interruptNames[INT_LAST] = {
"Tick ", // INT_TICK, "Tick ", // INT_TICK,
"5ms ", // INT_5MS, "5ms ", // INT_5MS,
@@ -201,7 +201,7 @@ void DebugTimer::stop()
else { else {
last *= 10000ul; //adjust unit to 1us last *= 10000ul; //adjust unit to 1us
} }
evalStats(); evalStats();
} }
DebugTimer debugTimers[DEBUG_TIMERS_COUNT]; DebugTimer debugTimers[DEBUG_TIMERS_COUNT];
+36 -4
View File
@@ -45,6 +45,10 @@
#include "extmodule_serial_driver.h" #include "extmodule_serial_driver.h"
#endif #endif
#if defined(DEBUG_SEGGER_RTT)
#include "thirdparty/Segger_RTT/RTT/SEGGER_RTT.h"
#endif
#define PRINTF_BUFFER_SIZE 128 #define PRINTF_BUFFER_SIZE 128
static void (*dbg_serial_putc)(void*, uint8_t) = nullptr; static void (*dbg_serial_putc)(void*, uint8_t) = nullptr;
@@ -67,6 +71,33 @@ void dbgSerialSetSendCb(void* ctx, void (*cb)(void*, uint8_t))
dbg_serial_putc = cb; dbg_serial_putc = cb;
} }
#if defined(DEBUG_SEGGER_RTT)
extern "C" void dbgSerialPutc(char c)
{
SEGGER_RTT_Write(0, (const void *)&c, 1);
}
extern "C" void dbgSerialPrintf(const char * format, ...)
{
va_list arglist;
char tmp[PRINTF_BUFFER_SIZE+1];
// no need to do anything if we don't have an output
if (!dbg_serial_putc) return;
va_start(arglist, format);
vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist);
tmp[PRINTF_BUFFER_SIZE] = '\0';
va_end(arglist);
const char *t = tmp;
while (*t && dbg_serial_putc) {
SEGGER_RTT_Write(0, (const void *)t++, 1);
}
}
#else
extern "C" void dbgSerialPutc(char c) extern "C" void dbgSerialPutc(char c)
{ {
auto _putc = dbg_serial_putc; auto _putc = dbg_serial_putc;
@@ -81,7 +112,7 @@ extern "C" void dbgSerialPrintf(const char * format, ...)
// no need to do anything if we don't have an output // no need to do anything if we don't have an output
if (!dbg_serial_putc) return; if (!dbg_serial_putc) return;
va_start(arglist, format); va_start(arglist, format);
vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist); vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist);
tmp[PRINTF_BUFFER_SIZE] = '\0'; tmp[PRINTF_BUFFER_SIZE] = '\0';
@@ -92,6 +123,7 @@ extern "C" void dbgSerialPrintf(const char * format, ...)
dbg_serial_putc(dbg_serial_ctx, *t++); dbg_serial_putc(dbg_serial_ctx, *t++);
} }
} }
#endif
extern "C" void dbgSerialCrlf() extern "C" void dbgSerialCrlf()
{ {
@@ -157,7 +189,7 @@ static void serialSetCallBacks(int mode, void* ctx, const etx_serial_port_t* por
getByte = drv->getByte; getByte = drv->getByte;
setRxCb = drv->setReceiveCb; setRxCb = drv->setReceiveCb;
} }
} }
// prevent compiler warnings // prevent compiler warnings
(void)sendByte; (void)sendByte;
@@ -228,7 +260,7 @@ static void serialSetCallBacks(int mode, void* ctx, const etx_serial_port_t* por
extmoduleSetSerialPort(drv); extmoduleSetSerialPort(drv);
break; break;
#endif #endif
#endif #endif
} }
} }
@@ -392,7 +424,7 @@ void serialInit(uint8_t port_nr, int mode)
void initSerialPorts() void initSerialPorts()
{ {
memset(serialPortStates, 0, sizeof(serialPortStates)); memset(serialPortStates, 0, sizeof(serialPortStates));
for (uint8_t port_nr = 0; port_nr < MAX_AUX_SERIAL; port_nr++) { for (uint8_t port_nr = 0; port_nr < MAX_AUX_SERIAL; port_nr++) {
auto mode = getSerialPortMode(port_nr); auto mode = getSerialPortMode(port_nr);
serialInit(port_nr, mode); serialInit(port_nr, mode);
@@ -54,6 +54,13 @@ if(BLUETOOTH)
) )
endif() endif()
if(DEBUG_SEGGER_RTT)
set(BOOTLOADER_SRC
${BOOTLOADER_SRC}
../../../../../thirdparty/Segger_RTT/RTT/SEGGER_RTT.c
)
endif()
if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14) if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
set(BOOTLOADER_SRC set(BOOTLOADER_SRC
@@ -73,7 +80,7 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
foreach(LVGL_FILE ${LVGL_SRC_FILES_MINIMAL}) foreach(LVGL_FILE ${LVGL_SRC_FILES_MINIMAL})
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} ../../../../../${LVGL_FILE}) set(BOOTLOADER_SRC ${BOOTLOADER_SRC} ../../../../../${LVGL_FILE})
endforeach() endforeach()
if(USB_CHARGER) if(USB_CHARGER)
set(BOOTLOADER_SRC set(BOOTLOADER_SRC
${BOOTLOADER_SRC} ${BOOTLOADER_SRC}
@@ -88,11 +95,11 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
../../../../../targets/${TARGET_DIR}/extmodule_helper.cpp ../../../../../targets/${TARGET_DIR}/extmodule_helper.cpp
) )
endif() endif()
if(DEBUG) if(DEBUG)
set(BOOTLOADER_SRC set(BOOTLOADER_SRC
${BOOTLOADER_SRC} ${BOOTLOADER_SRC}
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c # ../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
../../../../../serial.cpp ../../../../../serial.cpp
../../../../../targets/common/arm/stm32/aux_serial_driver.cpp ../../../../../targets/common/arm/stm32/aux_serial_driver.cpp
../../../../../targets/common/arm/stm32/stm32_usart_driver.cpp ../../../../../targets/common/arm/stm32/stm32_usart_driver.cpp
@@ -27,6 +27,10 @@
#include "keys.h" #include "keys.h"
#include "debug.h" #include "debug.h"
#if defined(DEBUG_SEGGER_RTT)
#include "thirdparty/Segger_RTT/RTT/SEGGER_RTT.h"
#endif
#if defined(PCBXLITE) #if defined(PCBXLITE)
#define BOOTLOADER_KEYS 0x0F #define BOOTLOADER_KEYS 0x0F
#else #else
@@ -83,7 +87,7 @@ void interrupt10ms()
#if defined(DEBUG) #if defined(DEBUG)
g_tmr10ms++; g_tmr10ms++;
#endif #endif
uint8_t index = 0; uint8_t index = 0;
uint32_t in = readKeys(); uint32_t in = readKeys();
@@ -228,6 +232,10 @@ void bootloaderInitApp()
boardBootloaderInit(); boardBootloaderInit();
#endif #endif
#if defined(DEBUG_SEGGER_RTT)
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
#endif
pwrInit(); pwrInit();
keysInit(); keysInit();
@@ -267,7 +275,7 @@ void bootloaderInitApp()
#endif #endif
delaysInit(); // needed for lcdInit() delaysInit(); // needed for lcdInit()
#if defined(DEBUG) #if defined(DEBUG)
initSerialPorts(); initSerialPorts();
#endif #endif