Skip to content

Commit c37c682

Browse files
committed
add menu debug out option to select output meessage via Serial, Serial1 or Segger RTT
1 parent 9bc5320 commit c37c682

File tree

5 files changed

+135
-25
lines changed

5 files changed

+135
-25
lines changed

boards.txt

+89
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
menu.softdevice=SoftDevice
22
menu.debug=Debug
3+
menu.debug_output=Debug Output
34

45
# -----------------------------------
56
# Adafruit Feather nRF52832
@@ -46,6 +47,14 @@ feather52832.menu.debug.l3=Level 3 (Segger SystemView)
4647
feather52832.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
4748
feather52832.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
4849

50+
# Debug Output Menu
51+
feather52832.menu.debug_output.serial=Serial
52+
feather52832.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
53+
feather52832.menu.debug_output.serial1=Serial1
54+
feather52832.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
55+
feather52832.menu.debug_output.rtt=Segger RTT
56+
feather52832.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
57+
4958
# -----------------------------------
5059
# Adafruit Feather nRF52840 Express
5160
# -----------------------------------
@@ -100,6 +109,14 @@ feather52840.menu.debug.l3=Level 3 (Segger SystemView)
100109
feather52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
101110
feather52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
102111

112+
# Debug Output Menu
113+
feather52840.menu.debug_output.serial=Serial
114+
feather52840.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
115+
feather52840.menu.debug_output.serial1=Serial1
116+
feather52840.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
117+
feather52840.menu.debug_output.rtt=Segger RTT
118+
feather52840.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
119+
103120
# -----------------------------------
104121
# Adafruit Feather nRF52840 Sense
105122
# -----------------------------------
@@ -154,6 +171,14 @@ feather52840sense.menu.debug.l3=Level 3 (Segger SystemView)
154171
feather52840sense.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
155172
feather52840sense.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
156173

174+
# Debug Output Menu
175+
feather52840sense.menu.debug_output.serial=Serial
176+
feather52840sense.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
177+
feather52840sense.menu.debug_output.serial1=Serial1
178+
feather52840sense.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
179+
feather52840sense.menu.debug_output.rtt=Segger RTT
180+
feather52840sense.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
181+
157182
# -----------------------------------
158183
# Adafruit ItsyBitsy nRF52840 Express
159184
# -----------------------------------
@@ -208,6 +233,14 @@ itsybitsy52840.menu.debug.l3=Level 3 (Segger SystemView)
208233
itsybitsy52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
209234
itsybitsy52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
210235

236+
# Debug Output Menu
237+
itsybitsy52840.menu.debug_output.serial=Serial
238+
itsybitsy52840.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
239+
itsybitsy52840.menu.debug_output.serial1=Serial1
240+
itsybitsy52840.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
241+
itsybitsy52840.menu.debug_output.rtt=Segger RTT
242+
itsybitsy52840.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
243+
211244
# -----------------------------------
212245
# Adafruit Circuit Playground Bluefruit
213246
# -----------------------------------
@@ -260,6 +293,14 @@ cplaynrf52840.menu.debug.l3=Level 3 (Segger SystemView)
260293
cplaynrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
261294
cplaynrf52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
262295

296+
# Debug Output Menu
297+
cplaynrf52840.menu.debug_output.serial=Serial
298+
cplaynrf52840.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
299+
cplaynrf52840.menu.debug_output.serial1=Serial1
300+
cplaynrf52840.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
301+
cplaynrf52840.menu.debug_output.rtt=Segger RTT
302+
cplaynrf52840.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
303+
263304
# -----------------------------------
264305
# Adafruit CLUE
265306
# -----------------------------------
@@ -312,6 +353,14 @@ cluenrf52840.menu.debug.l3=Level 3 (Segger SystemView)
312353
cluenrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
313354
cluenrf52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
314355

356+
# Debug Output Menu
357+
cluenrf52840.menu.debug_output.serial=Serial
358+
cluenrf52840.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
359+
cluenrf52840.menu.debug_output.serial1=Serial1
360+
cluenrf52840.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
361+
cluenrf52840.menu.debug_output.rtt=Segger RTT
362+
cluenrf52840.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
363+
315364
# -----------------------------------
316365
# Adafruit LED Glasses Driver nRF52840
317366
# -----------------------------------
@@ -364,6 +413,14 @@ ledglasses_nrf52840.menu.debug.l3=Level 3 (Segger SystemView)
364413
ledglasses_nrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
365414
ledglasses_nrf52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
366415

416+
# Debug Output Menu
417+
ledglasses_nrf52840.menu.debug_output.serial=Serial
418+
ledglasses_nrf52840.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
419+
ledglasses_nrf52840.menu.debug_output.serial1=Serial1
420+
ledglasses_nrf52840.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
421+
ledglasses_nrf52840.menu.debug_output.rtt=Segger RTT
422+
ledglasses_nrf52840.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
423+
367424
# -----------------------------------
368425
# Raytac nRF52840 Dongle
369426
# -----------------------------------
@@ -416,6 +473,14 @@ mdbt50qrx.menu.debug.l3=Level 3 (Segger SystemView)
416473
mdbt50qrx.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
417474
mdbt50qrx.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
418475

476+
# Debug Output Menu
477+
mdbt50qrx.menu.debug_output.serial=Serial
478+
mdbt50qrx.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
479+
mdbt50qrx.menu.debug_output.serial1=Serial1
480+
mdbt50qrx.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
481+
mdbt50qrx.menu.debug_output.rtt=Segger RTT
482+
mdbt50qrx.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
483+
419484
# -----------------------------------
420485
# Adafruit Metro nRF52840 Express
421486
# -----------------------------------
@@ -470,6 +535,14 @@ metro52840.menu.debug.l3=Level 3 (Segger SystemView)
470535
metro52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
471536
metro52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
472537

538+
# Debug Output Menu
539+
metro52840.menu.debug_output.serial=Serial
540+
metro52840.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
541+
metro52840.menu.debug_output.serial1=Serial1
542+
metro52840.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
543+
metro52840.menu.debug_output.rtt=Segger RTT
544+
metro52840.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
545+
473546

474547
# -------------------------------------------------------
475548
#
@@ -527,6 +600,14 @@ pca10056.menu.debug.l3=Level 3 (Segger SystemView)
527600
pca10056.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
528601
pca10056.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
529602

603+
# Debug Output Menu
604+
pca10056.menu.debug_output.serial=Serial
605+
pca10056.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
606+
pca10056.menu.debug_output.serial1=Serial1
607+
pca10056.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
608+
pca10056.menu.debug_output.rtt=Segger RTT
609+
pca10056.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
610+
530611
# -----------------------------------
531612
# Particle Xenon
532613
# -----------------------------------
@@ -576,3 +657,11 @@ particle_xenon.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
576657
particle_xenon.menu.debug.l3=Level 3 (Segger SystemView)
577658
particle_xenon.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
578659
particle_xenon.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
660+
661+
# Debug Output Menu
662+
particle_xenon.menu.debug_output.serial=Serial
663+
particle_xenon.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0
664+
particle_xenon.menu.debug_output.serial1=Serial1
665+
particle_xenon.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG
666+
particle_xenon.menu.debug_output.rtt=Segger RTT
667+
particle_xenon.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL

cores/nRF5/common_func.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
176176

177177
#if CFG_DEBUG
178178

179-
#define PRINT_LOCATION() PRINTF("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
180-
#define PRINT_MESS(x) PRINTF("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x))
181-
#define PRINT_HEAP() if (CFG_DEBUG >= 3) PRINTF("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
182-
#define PRINT_STR(x) PRINTF("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
183-
#define PRINT_INT(x) PRINTF("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
184-
#define PRINT_FLOAT(x) PRINTF("%s: %d: " #x " = %f\n" , __FUNCTION__, __LINE__, (float) (x) )
179+
#define PRINT_LOCATION() PRINTF("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
180+
#define PRINT_MESS(x) PRINTF("%s: %d: %s \r\n" , __FUNCTION__, __LINE__, (char*)(x))
181+
#define PRINT_HEAP() if (CFG_DEBUG >= 3) PRINTF("\n%s: %d: Heap free: %d\r\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
182+
#define PRINT_STR(x) PRINTF("%s: %d: " #x " = %s\r\n" , __FUNCTION__, __LINE__, (char*)(x) )
183+
#define PRINT_INT(x) PRINTF("%s: %d: " #x " = %ld\r\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
184+
#define PRINT_FLOAT(x) PRINTF("%s: %d: " #x " = %f\r\n" , __FUNCTION__, __LINE__, (float) (x) )
185185

186186
#define PRINT_HEX(x) \
187187
do {\
@@ -196,7 +196,7 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
196196
uint8_t const* p8 = (uint8_t const*) (buf);\
197197
PRINTF(#buf ": ");\
198198
for(uint32_t i=0; i<(n); i++) {\
199-
if (i%16 == 0) PRINTF("\n"); \
199+
if (i%16 == 0) PRINTF("\r\n"); \
200200
PRINTF("%02x ", p8[i]); \
201201
}\
202202
PRINTF("\r\n");\
@@ -212,7 +212,7 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
212212
#define ADALOG_BUFFER(_tag, _buf, _n) \
213213
do {\
214214
const char * _xtag = _tag;\
215-
if ( _xtag ) PRINTF("%-6s: len = %d\n", _xtag, _n);\
215+
if ( _xtag ) PRINTF("%-6s: len = %d\r\n", _xtag, _n);\
216216
dbgDumpMemory(_buf, 1, _n, true);\
217217
}while(0)
218218

cores/nRF5/main.cpp

+24-13
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
#define ARDUINO_MAIN
1717
#include "Arduino.h"
1818

19-
#if (CFG_LOGGER == 2)
20-
#include <SEGGER_RTT.h>
21-
#endif
22-
23-
// From the UI, setting debug level to 3 will enable SysView
2419
#if CFG_SYSVIEW
25-
#include "SEGGER_RTT.h"
26-
#include "SEGGER_SYSVIEW.h"
20+
// Select Menu -> Debug -> Segger SystemView
21+
#include "SEGGER_RTT.h"
22+
#include "SEGGER_SYSVIEW.h"
23+
24+
#elif CFG_LOGGER == 2
25+
// Select Menu -> Debug Output -> Segger RTT
26+
#include "SEGGER_RTT.h"
2727
#endif
2828

2929
// DEBUG Level 1
@@ -119,20 +119,31 @@ extern "C"
119119
{
120120

121121
// nanolib printf() retarget
122+
// Logger 0: Serial (CDC), 1 Serial1 (UART), 2 Segger RTT
122123
int _write (int fd, const void *buf, size_t count)
123124
{
124125
(void) fd;
125-
#if (CFG_LOGGER == 2)
126-
unsigned numBytes = count;
127-
SEGGER_RTT_Write(0, buf, numBytes);
128-
return (int)count;
126+
127+
size_t ret = 0;
128+
129+
#if CFG_LOGGER == 2 || CFG_SYSVIEW
130+
SEGGER_RTT_Write(0, buf, count);
131+
ret = count;
132+
133+
#elif CFG_LOGGER == 1
134+
if ( Serial1 )
135+
{
136+
ret = Serial1.write((const uint8_t *) buf, count);
137+
}
138+
129139
#else
130140
if ( Serial )
131141
{
132-
return Serial.write( (const uint8_t *) buf, count);
142+
ret = Serial.write((const uint8_t *) buf, count);
133143
}
134144
#endif
135-
return 0;
145+
146+
return (int) ret;
136147
}
137148

138149
}

platform.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ compiler.ldflags=-mcpu={build.mcu} -mthumb {build.float_flags} -Wl,--cref -Wl,--
5353
compiler.size.cmd=arm-none-eabi-size
5454

5555
# this can be overriden in boards.txt
56+
# Logger 0: Serial (CDC), 1 Serial1 (UART), 2 Segger RTT
5657
build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16 -u _printf_float
5758
build.debug_flags=-DCFG_DEBUG=0
58-
build.logger_flags=-DCFG_LOGGER=1
59+
build.logger_flags=-DCFG_LOGGER=0
5960
build.sysview_flags=-DCFG_SYSVIEW=0
6061

6162
# USB flags
@@ -78,8 +79,6 @@ compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-5.7.0.path}/CMSIS/DSP/Lib/GCC
7879
rtos.path={build.core.path}/freertos
7980
nordic.path={build.core.path}/nordic
8081

81-
# build.logger_flags and build.sysview_flags are intentionally empty,
82-
# to allow modification via a user's own boards.local.txt or platform.local.txt files.
8382
build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DDX_CC_TEE -DLFS_NAME_MAX=64 {compiler.optimization_flag} {build.debug_flags} {build.logger_flags} {build.sysview_flags} {compiler.arm.cmsis.c.flags} "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include/nrf52" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"
8483

8584
# Compile patterns

tools/makeboards.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
from bokeh.palettes import name
23

34
mcu_dict = {
45
52832: {
@@ -102,17 +103,27 @@ def build_debug(name):
102103
print("%s.menu.debug.l3=Level 3 (Segger SystemView)" % name)
103104
print("%s.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3" % name)
104105
print("%s.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1" % name)
106+
print()
105107

108+
def build_debug_output(name):
109+
print("# Debug Output Menu")
110+
print("%s.menu.debug_output.serial=Serial" % name)
111+
print("%s.menu.debug_output.serial.build.logger_flags=-DCFG_LOGGER=0" % name)
112+
print("%s.menu.debug_output.serial1=Serial1" % name)
113+
print("%s.menu.debug_output.serial1.build.logger_flags=-DCFG_LOGGER=1 -DCFG_TUSB_DEBUG=CFG_DEBUG" % name)
114+
print("%s.menu.debug_output.rtt=Segger RTT" % name)
115+
print("%s.menu.debug_output.rtt.build.logger_flags=-DCFG_LOGGER=2 -DCFG_TUSB_DEBUG=CFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL" % name)
106116

107117
def build_global_menu():
108118
print("menu.softdevice=SoftDevice")
109119
print("menu.debug=Debug")
110-
120+
print("menu.debug_output=Debug Output")
111121

112122
def make_board(name, vendor_name, product_name, vid, pid, boarddefine, variant):
113123
build_header(name, vendor_name, product_name, vid, pid, boarddefine, variant)
114124
build_softdevice(name)
115125
build_debug(name)
126+
build_debug_output(name)
116127

117128

118129
build_global_menu()

0 commit comments

Comments
 (0)