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:
@@ -11,3 +11,6 @@
|
||||
path = radio/src/thirdparty/FreeRTOS
|
||||
url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git
|
||||
shallow = true
|
||||
[submodule "radio/src/thirdparty/Segger_RTT"]
|
||||
path = radio/src/thirdparty/Segger_RTT
|
||||
url = https://github.com/adfernandes/segger-rtt.git
|
||||
|
||||
@@ -44,6 +44,7 @@ option(RAS "RAS (SWR) enabled" ON)
|
||||
option(TEMPLATES "Model templates menu" OFF)
|
||||
option(TRACE_SIMPGMSPACE "Turn on traces in simpgmspace.cpp" ON)
|
||||
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_YAML "Turn on YAML traces" OFF)
|
||||
option(DEBUG_LABELS "Turn on Labels traces" OFF)
|
||||
@@ -365,6 +366,11 @@ if(TRACE_LUA_INTERNALS)
|
||||
add_definitions(-DTRACE_LUA_INTERNALS_ENABLED)
|
||||
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)
|
||||
add_definitions(-DDEBUG_WINDOWS)
|
||||
endif()
|
||||
@@ -520,7 +526,7 @@ if(NATIVE_BUILD)
|
||||
target_compile_options(radiolib_native PUBLIC -DSIMU)
|
||||
add_dependencies(radiolib_native ${RADIO_DEPENDENCIES})
|
||||
set_property(TARGET radiolib_native PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
|
||||
add_subdirectory(targets/simu)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
+2
-2
@@ -139,7 +139,7 @@ void dumpTraceBuffer()
|
||||
" notd", // INT_OTG_FS_RX_NOT_DEVICE,
|
||||
#endif // #if defined(DEBUG_USB_INTERRUPTS)
|
||||
};
|
||||
#elif defined(PCBTARANIS)
|
||||
#elif defined(PCBTARANIS)
|
||||
const char * const interruptNames[INT_LAST] = {
|
||||
"Tick ", // INT_TICK,
|
||||
"5ms ", // INT_5MS,
|
||||
@@ -201,7 +201,7 @@ void DebugTimer::stop()
|
||||
else {
|
||||
last *= 10000ul; //adjust unit to 1us
|
||||
}
|
||||
evalStats();
|
||||
evalStats();
|
||||
}
|
||||
|
||||
DebugTimer debugTimers[DEBUG_TIMERS_COUNT];
|
||||
|
||||
+36
-4
@@ -45,6 +45,10 @@
|
||||
#include "extmodule_serial_driver.h"
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_SEGGER_RTT)
|
||||
#include "thirdparty/Segger_RTT/RTT/SEGGER_RTT.h"
|
||||
#endif
|
||||
|
||||
#define PRINTF_BUFFER_SIZE 128
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
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
|
||||
if (!dbg_serial_putc) return;
|
||||
|
||||
|
||||
va_start(arglist, format);
|
||||
vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist);
|
||||
tmp[PRINTF_BUFFER_SIZE] = '\0';
|
||||
@@ -92,6 +123,7 @@ extern "C" void dbgSerialPrintf(const char * format, ...)
|
||||
dbg_serial_putc(dbg_serial_ctx, *t++);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" void dbgSerialCrlf()
|
||||
{
|
||||
@@ -157,7 +189,7 @@ static void serialSetCallBacks(int mode, void* ctx, const etx_serial_port_t* por
|
||||
getByte = drv->getByte;
|
||||
setRxCb = drv->setReceiveCb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// prevent compiler warnings
|
||||
(void)sendByte;
|
||||
@@ -228,7 +260,7 @@ static void serialSetCallBacks(int mode, void* ctx, const etx_serial_port_t* por
|
||||
extmoduleSetSerialPort(drv);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -392,7 +424,7 @@ void serialInit(uint8_t port_nr, int mode)
|
||||
void initSerialPorts()
|
||||
{
|
||||
memset(serialPortStates, 0, sizeof(serialPortStates));
|
||||
|
||||
|
||||
for (uint8_t port_nr = 0; port_nr < MAX_AUX_SERIAL; port_nr++) {
|
||||
auto mode = getSerialPortMode(port_nr);
|
||||
serialInit(port_nr, mode);
|
||||
|
||||
@@ -54,6 +54,13 @@ if(BLUETOOTH)
|
||||
)
|
||||
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)
|
||||
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})
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} ../../../../../${LVGL_FILE})
|
||||
endforeach()
|
||||
|
||||
|
||||
if(USB_CHARGER)
|
||||
set(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
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
if(DEBUG)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
|
||||
# ../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
|
||||
../../../../../serial.cpp
|
||||
../../../../../targets/common/arm/stm32/aux_serial_driver.cpp
|
||||
../../../../../targets/common/arm/stm32/stm32_usart_driver.cpp
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
#include "keys.h"
|
||||
#include "debug.h"
|
||||
|
||||
#if defined(DEBUG_SEGGER_RTT)
|
||||
#include "thirdparty/Segger_RTT/RTT/SEGGER_RTT.h"
|
||||
#endif
|
||||
|
||||
#if defined(PCBXLITE)
|
||||
#define BOOTLOADER_KEYS 0x0F
|
||||
#else
|
||||
@@ -83,7 +87,7 @@ void interrupt10ms()
|
||||
#if defined(DEBUG)
|
||||
g_tmr10ms++;
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t index = 0;
|
||||
uint32_t in = readKeys();
|
||||
|
||||
@@ -228,6 +232,10 @@ void bootloaderInitApp()
|
||||
boardBootloaderInit();
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_SEGGER_RTT)
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
|
||||
#endif
|
||||
|
||||
pwrInit();
|
||||
keysInit();
|
||||
|
||||
@@ -267,7 +275,7 @@ void bootloaderInitApp()
|
||||
#endif
|
||||
|
||||
delaysInit(); // needed for lcdInit()
|
||||
|
||||
|
||||
#if defined(DEBUG)
|
||||
initSerialPorts();
|
||||
#endif
|
||||
|
||||
+1
Submodule radio/src/thirdparty/Segger_RTT added at fdac9caa26
Reference in New Issue
Block a user