This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use RTT for debugging in nRF9160?

I made my own board in which nRF9160 is populated. It's connected to JLink through SWD. SWO is not connected.

I tried rtt debugging and seems to work correctly, but I'm not sure it's good. Any advice?

I've debugged nRF9160 DK with UART0 and printf. This is the first time to use RTT.

- Copy ../nRF9160/ncs/modules/debug/segger/rtt/SEGGER_RTT_printf.c into src folder.

<CMakeLists.txt>
cmake_minimum_required(VERSION 3.8.2)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE src/SEGGER_RTT_printf.c)

<prf.conf>
CONFIG_TRUSTED_EXECUTION_NONSECURE=y

# CONFIG_NO_OPTIMIZATIONS=y
CONFIG_PRINTK=y
CONFIG_CONSOLE=y

# UART logging devzone.nordicsemi.com/.../nrf91-zephyr-enable-lte-logging
# CONFIG_LOG=y
# CONFIG_SERIAL=y
# CONFIG_STDOUT_CONSOLE=y
# CONFIG_UART_INTERRUPT_DRIVEN=y
# or disable it
CONFIG_SERIAL=y
CONFIG_STDOUT_CONSOLE=y

# docs.zephyrproject.org/.../nordic_segger.html
CONFIG_UART_CONSOLE=n
CONFIG_RTT_CONSOLE=y
CONFIG_HAS_SEGGER_RTT=y
CONFIG_USE_SEGGER_RTT=y

# CONFIG_LOG_BACKEND_RTT=y
# CONFIG_SHELL_BACKEND_RTT=y
# CONFIG_LOG_BACKEND_RTT_FORCE_PRINTK=y

CONFIG_GPIO=y
CONFIG_UART_3_NRF_UARTE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NEWLIB_LIBC=y

#include <zephyr.h>
#include <misc/printk.h>
#include <uart.h>
#include <string.h>
#include <stdlib.h>
#include <gpio.h>

#include "SEGGER_RTT.h" // ADD

.
.
.

void main (void)
{
    SEGGER_RTT_Init();
    
    while(1){
        SEGGER_RTT_printf(0, "START\r\n");
        k_sleep(1000);
    }
}

- Build the project
- Target > Connect JLink
- Target > Download File > Download Intel Hex File > Select merge.hex file
- Debug > Go
- Read Terminal Emulator window in SES

Is this correct procedure?

Related