Setting up console over SWD interface

Hello,

I am trying to compile a basic Hello World application for a custom PCB with a nRF52832 microcontroller. I am using VS Code and the nRF Connect SDK. I have completed the nRF Connect SDK Fundamentals course and received the certificate, and now I am trying to apply those lessons to my custom hardware.

My goal is to compile a Hello World example and see the message printed on the VS Code console. My custom hardware does not have a UART connection broken out. I am programming my custom hardware over SWD via a nRF52-DK PCA10040 board. I would like to receive logging messages over SWD as well.

When I connect a TagConnect cable to the P19 Debug Out connector and mate it with my custom board, I can see the Connected Devices tab update from NRF52832_xxAA_REV2 to NRF52832_xxAB_REV2, so I am fairly sure that I am programming my custom board and not the DK itself. 

Initially, I tried a simple printk statement, which builds and runs, but no messages are received in the terminal. After some digging in the Nordic forums, I realized that I want to use the SWD interface for console output, instead of a UART. So, I enabled logging as explained in the Fundamentals course Lesson 4 Exercise 2. I also tried changing my prj.conf to disable the UART console and enable the RTT_CONSOLE instead.

This builds and flashes without issue, but I am still not getting any of my debug messages.

How can I properly set up the SWD interface for Hello world, printk, and logging messages on a custom PCB?

main.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(NixieLogs,LOG_LEVEL_DBG);
int main(void)
{
while(true){
printk("Hello World! %s\n", CONFIG_BOARD);
LOG_INF("nRF Connect SDK Fundamentals");
LOG_DBG("A log message in debug level");
LOG_WRN("A log message in warning level!");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

prj.conf

Fullscreen
1
2
3
4
5
6
7
# nothing here
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

CMakeLists.txt

Fullscreen
1
2
3
4
5
6
7
8
9
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)
target_sources(app PRIVATE src/main.c)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Custom PCB board defconfig

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_NRF52X=y
CONFIG_SOC_NRF52832_QFAA=y
CONFIG_BOARD_NIXIE_CLOCK_BOARD=y
# Enable MPU
CONFIG_ARM_MPU=y
# Enable hardware stack protection
CONFIG_HW_STACK_PROTECTION=y
# Enable RTT
CONFIG_USE_SEGGER_RTT=y
# enable GPIO
CONFIG_GPIO=y
# enable uart driver
CONFIG_SERIAL=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Custom board DTS file

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Copyright (c) 2017 Shawn Nock <shawn@monadnock.ca>
* Copyright (c) 2017 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <nordic/nrf52832_qfaa.dtsi>
#include "nixie_clock_board-pinctrl.dtsi"
/ {
model = "Chris Fernandez Nixie Clock Board";
compatible = "chrisfernandez,nixie_clock_board";
chosen {
zephyr,console = &uart0;
zephyr,shell-uart = &uart0;
zephyr,uart-mcumgr = &uart0;
zephyr,bt-mon-uart = &uart0;
zephyr,bt-c2h-uart = &uart0;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Custom PCB board.cmake

Fullscreen
1
2
3
4
5
6
7
8
9
10
# SPDX-License-Identifier: Apache-2.0
board_runner_args(jlink "--device=nRF52832_xxAA" "--speed=4000")
board_runner_args(pyocd "--target=nrf52832" "--frequency=4000000")
set(OPENOCD_NRF5_SUBFAMILY "nrf52")
include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake)
include(${ZEPHYR_BASE}/boards/common/nrfutil.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • Hello,

    If I understand correctly, you want to see the print and log output only on the RTT logger not on serial terminal. 

    You have disabled UART in config file using this CONFIG_UART_CONSOLE=n but you have enabled this again on-board config file.

    Try this:
    In prj.conf file, add this 
    CONFIG_LOG=y
    CONFIG_LOG_PRINTK = y
    In the board config file, you can write this:
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    # SPDX-License-Identifier: Apache-2.0
    CONFIG_SOC_SERIES_NRF52X=y
    CONFIG_SOC_NRF52832_QFAA=y
    (your board file config)
    # Enable MPU
    CONFIG_ARM_MPU=y
    # Enable hardware stack protection
    CONFIG_HW_STACK_PROTECTION=y
    # Enable RTT
    CONFIG_USE_SEGGER_RTT=y
    # enable GPIO
    CONFIG_GPIO=y
    # enable uart driver
    CONFIG_SERIAL=y
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Try this and let me know if it works.
    Thanks.
    BR
    kazi
     
  • Hi Kazi, thanks for the response. 

    I have made your recommended changes. The application builds and installs, but I am still not seeing any of my debug message output on the terminal. I have checked VCOM0 (set to /dev/ttyACM0 at 115200, 8n1, rtscts:off) and the RTT connected device (unsure if RTT is the right device to check?)

    Do you have any suggestions for what else could be wrong? To be clear, I am setting up a custom board in VS Code for the first time, so it's possible that I have other errors elsewhere. I am not sure where to check, but I am happy to share any other files that could be useful in debugging.

  • Hello, 

    RTT is the right device to connect as you set this to see the output message on that terminal and unset the UART terminal. 

    ''The application builds and installs, but I am still not seeing any of my debug message output on the terminal.''

    Can I look at the error log?

  • Hi Kazi,

    I am not seeing any errors during the build or run steps. I'm just not receiving any of my debugging log messages.

     Here is the build output:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    Building hello_world
    /bin/sh -c west build --build-dir /media/chris/Data/Documents/Projects/Nixie_clock/repos/nixie_clock_firmware/hello_world/build /media/chris/Data/Documents/Projects/Nixie_clock/repos/nixie_clock_firmware/hello_world
    ninja: no work to do.
    * Terminal will be reused by tasks, press any key to close it.
    * Executing task: nRF Connect: Build [pristine]: hello_world/build (active)
    Building hello_world
    /bin/sh -c west build --build-dir /media/chris/Data/Documents/Projects/Nixie_clock/repos/nixie_clock_firmware/hello_world/build /media/chris/Data/Documents/Projects/Nixie_clock/repos/nixie_clock_firmware/hello_world --pristine --board nixie_clock_board --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DBOARD_ROOT:STRING="/media/chris/Data/Documents/Projects/Nixie_clock/repos/nixie_clock_firmware/hello_world" -DCONF_FILE:STRING="/media/chris/Data/Documents/Projects/Nixie_clock/repos/nixie_clock_firmware/hello_world/prj.conf"
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: /media/chris/Data/Documents/Projects/Nixie_clock/repos/nixie_clock_firmware/hello_world
    -- CMake version: 3.20.5
    -- Found Python3: /home/chris/ncs/toolchains/1f9b40e71a/usr/local/bin/python3.8 (found suitable exact version "3.8.2") found components: Interpreter
    -- Cache files will be written to: /home/chris/.cache/zephyr
    -- Zephyr version: 3.4.99 (/home/chris/ncs/zephyr)
    -- Found west (found suitable version "1.0.0", minimum required is "0.14.0")
    -- Board: nixie_clock_board
    -- Found host-tools: zephyr 0.16.0 (/home/chris/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Here is what I see when connected to RTT. Just a brief message that it connected, without my application's log messages: 

    Fullscreen
    1
    2
    3
    SEGGER J-Link V7.88j - Real time terminal output
    SEGGER J-Link (unknown) V1.0, SN=682046847
    Process: JLinkExe
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


    I'm also attaching my project as a zip file, in case it is helpful in debugging. It includes the Hello World application code (with some minor edits to add extra log messages) and the custom board files as well.

    nixie_clock_firmware.zip


    Finally, here is the schematic for my custom hardware:

     Nixie_Clock_Schematics.pdf

    I am hoping you can help me find a simple configuration error or some other silly mistake. I'm new to the NCS ecosystem so it is very possible that I am missing something basic with my setup. 

    Is there anything that needs to be enabled at the board device tree level to enable RTT logging?

  • I was able to get printk messages and log messages from my custom board. I am going to write out the changes I made in the hopes that this helps someone in the future.

    In the defconfig file for my custom board:

    Fullscreen
    1
    CONFIG_UART_CONSOLE=n
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In my application's prj.conf file:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    CONFIG_LOG=y
    CONFIG_LOG_PRINTK=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_UART_CONSOLE=n
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    main.c

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/logging/log.h>
    LOG_MODULE_REGISTER(NixieLogs,LOG_LEVEL_DBG);
    #define SLEEP_TIME_MS 1000
    int main(void)
    {
    printk("Hello World! %s\n", CONFIG_BOARD);
    LOG_INF("nixie log info");
    LOG_DBG("nixie log debug");
    LOG_WRN("nixie log warning");
    LOG_ERR("nixie log error");
    while (1) {
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    project.code-workspace: a new 'settings' list showed up, listing nrf-connect.applications.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    {
    "folders": [
    {
    "path": "hello_world"
    }
    ],
    "settings": {
    "nrf-connect.applications": [],
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I also switched my programmer from a nRF52-DK PCA10040 board to a nRF5340-DK PCA10095 board. I made this switch because I was concerned that there may have been confusion between the nRF52832 on my programmer, and the nRF52832 on my custom hardware. I am not sure if this made a difference or not.

    When I plugged in my nRF5340-DK, I was prompted in VS Code to update the firmware on the device. I followed the prompt and a firmware update was installed. Unsure if that is relevant. 

    Note: the RTT/SWD interface is shared by the flashing operation and RTT logging. It seems that reflashing the board causes the RTT logs to freeze up. I need to manually kill the RTT terminal and reopen it every time I flash. But, I am getting my printk's and log messages now.

    Thank you to Kazi for helping me.

Reply
  • I was able to get printk messages and log messages from my custom board. I am going to write out the changes I made in the hopes that this helps someone in the future.

    In the defconfig file for my custom board:

    Fullscreen
    1
    CONFIG_UART_CONSOLE=n
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In my application's prj.conf file:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    CONFIG_LOG=y
    CONFIG_LOG_PRINTK=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_UART_CONSOLE=n
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    main.c

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/logging/log.h>
    LOG_MODULE_REGISTER(NixieLogs,LOG_LEVEL_DBG);
    #define SLEEP_TIME_MS 1000
    int main(void)
    {
    printk("Hello World! %s\n", CONFIG_BOARD);
    LOG_INF("nixie log info");
    LOG_DBG("nixie log debug");
    LOG_WRN("nixie log warning");
    LOG_ERR("nixie log error");
    while (1) {
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    project.code-workspace: a new 'settings' list showed up, listing nrf-connect.applications.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    {
    "folders": [
    {
    "path": "hello_world"
    }
    ],
    "settings": {
    "nrf-connect.applications": [],
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I also switched my programmer from a nRF52-DK PCA10040 board to a nRF5340-DK PCA10095 board. I made this switch because I was concerned that there may have been confusion between the nRF52832 on my programmer, and the nRF52832 on my custom hardware. I am not sure if this made a difference or not.

    When I plugged in my nRF5340-DK, I was prompted in VS Code to update the firmware on the device. I followed the prompt and a firmware update was installed. Unsure if that is relevant. 

    Note: the RTT/SWD interface is shared by the flashing operation and RTT logging. It seems that reflashing the board causes the RTT logs to freeze up. I need to manually kill the RTT terminal and reopen it every time I flash. But, I am getting my printk's and log messages now.

    Thank you to Kazi for helping me.

Children
  • Just as a quick test, I switched back to my original nRF52-DK PCA10040 board and reflashed my application. I am still getting logs. So, it seems that switching the programming board was irrelevant.