From d10a4b8cdc14330ad8b2679aa0138df58a53ec9e Mon Sep 17 00:00:00 2001 From: crc-32 Date: Sat, 20 Feb 2021 04:23:08 +0000 Subject: [PATCH 1/3] asterix-vla-dvb2 RTT debug support --- Utilities/openocd_rtt.sh | 2 ++ hw/chip/nrf52840/debug.c | 30 ++++++++++++++++++++++-------- hw/platform/asterix/config.mk | 5 ++++- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100755 Utilities/openocd_rtt.sh diff --git a/Utilities/openocd_rtt.sh b/Utilities/openocd_rtt.sh new file mode 100755 index 00000000..b76e45f9 --- /dev/null +++ b/Utilities/openocd_rtt.sh @@ -0,0 +1,2 @@ +RTT_ADDR=$(arm-none-eabi-nm build/${1}/tintin_fw.elf | grep '_SEGGER_RTT' | cut -d " " -f1) +openocd -f interface/jlink.cfg -c "transport select swd" -f target/nrf52.cfg -c "init" -c "rtt setup 0x${RTT_ADDR} 2048 \"SEGGER RTT\"" -c "rtt start" -c "rtt server start 9090 0" diff --git a/hw/chip/nrf52840/debug.c b/hw/chip/nrf52840/debug.c index 3591396f..9a8fa9e9 100644 --- a/hw/chip/nrf52840/debug.c +++ b/hw/chip/nrf52840/debug.c @@ -8,20 +8,12 @@ #include #include "rebbleos.h" #include "nrf_delay.h" -#include "nrfx_uart.h" #include "board_config.h" void delay_us(int us) { nrf_delay_us(us); } -/* We use UART, instead of UARTE, because we could be writing from flash, - * which would cause the EasyDMA engine to lock up, and that would be bad. - * So we just take the performance hit and run a UART engine in PIO mode. - * So it goes. */ - -static nrfx_uart_t debug_uart = NRFX_UART_INSTANCE(0); - __attribute__((naked)) uint32_t get_msp() { asm volatile( @@ -30,8 +22,28 @@ __attribute__((naked)) uint32_t get_msp() ); } +#ifdef NRF_DEBUG_SEGGER_RTT +#include "SEGGER_RTT.h" +void debug_init() { + SEGGER_RTT_Init(); +} + +void debug_write(const unsigned char *p, size_t len) { + SEGGER_RTT_Write(0, p, len); +} + +#else + +#include "nrfx_uart.h" + static int _did_init = 0; +/* We use UART, instead of UARTE, because we could be writing from flash, + * which would cause the EasyDMA engine to lock up, and that would be bad. + * So we just take the performance hit and run a UART engine in PIO mode. + * So it goes. */ + +static nrfx_uart_t debug_uart = NRFX_UART_INSTANCE(0); void debug_init() { nrfx_err_t err; @@ -66,6 +78,8 @@ void debug_write(const unsigned char *p, size_t len) { } } +#endif + void ss_debug_write(const unsigned char *p, size_t len) { // unsupported on this platform diff --git a/hw/platform/asterix/config.mk b/hw/platform/asterix/config.mk index 73436aa0..bb62cff8 100644 --- a/hw/platform/asterix/config.mk +++ b/hw/platform/asterix/config.mk @@ -47,11 +47,14 @@ PLATFORMS += asterix_vla_dvb1 CFLAGS_asterix_vla_dvb2 = $(CFLAGS_asterix_common) CFLAGS_asterix_vla_dvb2 += $(CFLAGS_driver_nrf52_ls013b7dh05) SRCS_asterix_vla_dvb2 = $(SRCS_asterix_common) +SRCS_asterix_vla_dvb2 += external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c +SRCS_asterix_vla_dvb2 += external/segger_rtt/SEGGER_RTT.c +SRCS_asterix_vla_dvb2 += external/segger_rtt/SEGGER_RTT_printf.c SRCS_asterix_vla_dvb2 += $(SRCS_driver_nrf52_ls013b7dh05) LDFLAGS_asterix_vla_dvb2 = $(LDFLAGS_asterix_common) LIBS_asterix_vla_dvb2 = $(LIBS_asterix_common) HWREV_asterix_vla_dvb2 = asterix_vla_dvb2 -CFLAGS_asterix_vla_dvb2 += -DASTERIX_BOARD_VLA_DVB2 +CFLAGS_asterix_vla_dvb2 += -DASTERIX_BOARD_VLA_DVB2 -DNRF_DEBUG_SEGGER_RTT PLATFORMS += asterix_vla_dvb2 From 6016bff0c8400f5cd2b7a930cdc5bc05354829fd Mon Sep 17 00:00:00 2001 From: crc-32 Date: Sat, 20 Feb 2021 14:03:53 +0000 Subject: [PATCH 2/3] Move RTT enable define to board_config.h --- hw/platform/asterix/board_config.h | 2 ++ hw/platform/asterix/config.mk | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/platform/asterix/board_config.h b/hw/platform/asterix/board_config.h index f473b0c9..2d769340 100644 --- a/hw/platform/asterix/board_config.h +++ b/hw/platform/asterix/board_config.h @@ -83,6 +83,8 @@ #define BOARD_DISPLAY_ROT180 +#define NRF_DEBUG_SEGGER_RTT + #else #error unknown Asterix board diff --git a/hw/platform/asterix/config.mk b/hw/platform/asterix/config.mk index bb62cff8..6e662d62 100644 --- a/hw/platform/asterix/config.mk +++ b/hw/platform/asterix/config.mk @@ -55,6 +55,6 @@ LDFLAGS_asterix_vla_dvb2 = $(LDFLAGS_asterix_common) LIBS_asterix_vla_dvb2 = $(LIBS_asterix_common) HWREV_asterix_vla_dvb2 = asterix_vla_dvb2 -CFLAGS_asterix_vla_dvb2 += -DASTERIX_BOARD_VLA_DVB2 -DNRF_DEBUG_SEGGER_RTT +CFLAGS_asterix_vla_dvb2 += -DASTERIX_BOARD_VLA_DVB2 PLATFORMS += asterix_vla_dvb2 From e171739dc9faf868b137cd71f5f6ffb8e0deb283 Mon Sep 17 00:00:00 2001 From: crc-32 Date: Sat, 20 Feb 2021 16:08:31 +0000 Subject: [PATCH 3/3] RTT commands for convenience --- Utilities/openocd_rtt.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Utilities/openocd_rtt.sh b/Utilities/openocd_rtt.sh index b76e45f9..982df3b8 100755 --- a/Utilities/openocd_rtt.sh +++ b/Utilities/openocd_rtt.sh @@ -1,2 +1,8 @@ RTT_ADDR=$(arm-none-eabi-nm build/${1}/tintin_fw.elf | grep '_SEGGER_RTT' | cut -d " " -f1) -openocd -f interface/jlink.cfg -c "transport select swd" -f target/nrf52.cfg -c "init" -c "rtt setup 0x${RTT_ADDR} 2048 \"SEGGER RTT\"" -c "rtt start" -c "rtt server start 9090 0" +openocd -f interface/jlink.cfg -c "transport select swd" -f target/nrf52.cfg \ +-c "proc rtt_init {} {rtt setup 0x${RTT_ADDR} 2048 \"SEGGER RTT\";\ + rtt start;\ + rtt server start 9090 0;}" \ +-c "proc rtt_reset {} {rtt server stop 9090;\ + rtt stop;\ + rtt_init;}" \ No newline at end of file