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

Adding RTT to basic nRF Connect SDK Blinky example not working with nRF5340DK

I've read similar issues but none with this configuration:-

  • nRF Connect SDK 1.4.2
  • Blinky example
  • Trying to enable RTT logging
  • nRF5340DK board
  • Windows 64 bit host
  • jLink RTT viewer

No matter which sample I use I cannot get RTT working. This is preventing me from developing open source wearable code for COVID-19. I'm attempting to get the most basic sample working in an attempt to debug my settings and find working ones.

All I need is a simple, working, configuration for the above combination. No matter how simple an example I create and add a logging line to, or which settings I choose, I do not see any logging output in segger studio at all. I've also tried the JLink viewer (not at the same time as segger studio) to no avail.

It seems no-one on this forum has provided a working simple example of RTT logging for the nRF5340DK with nRF Connect SDK combination which worries me - something this simple should 'just work' but that doesn't appear to be the case.

I've read all the usual tutorials, trawled this forum, and scoured YouTube to no avail. Either the examples are nRF5 SDK, not nRF Connect, or the settings do not work.

I can connect my JLink viewer to the live blinky example to which I've added logging lines, but see nothing.

Can someone please provide a simple working config change to the Blinky example that is confirmed to work on their machine?

Thanks in advance.

  • Hi,

    Here is one simple example of adding RTT support to zephyr\samples\basic\blinky example:

    prj.conf

    CONFIG_GPIO=y
    
    # choose RTT console
    CONFIG_UART_CONSOLE=n
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    
    # General config
    CONFIG_LOG=y
    CONFIG_LOG_DEFAULT_LEVEL=4

    main.c

    /*
     * Copyright (c) 2016 Intel Corporation
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/gpio.h>
    #include <logging/log.h>
    
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS   1000
    
    /* The devicetree node identifier for the "led0" alias. */
    #define LED0_NODE DT_ALIAS(led0)
    
    #if DT_NODE_HAS_STATUS(LED0_NODE, okay)
    #define LED0	DT_GPIO_LABEL(LED0_NODE, gpios)
    #define PIN	DT_GPIO_PIN(LED0_NODE, gpios)
    #define FLAGS	DT_GPIO_FLAGS(LED0_NODE, gpios)
    #else
    /* A build error here means your board isn't set up to blink an LED. */
    #error "Unsupported board: led0 devicetree alias is not defined"
    #define LED0	""
    #define PIN	0
    #define FLAGS	0
    #endif
    
    LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL);
    
    void main(void)
    {
    	const struct device *dev;
    	bool led_is_on = true;
    	int ret;
       
       LOG_ERR("This is a error message!");
       LOG_WRN("This is a warning message!");
       LOG_INF("This is a information message!");
       LOG_DBG("This is a debugging message!");
    
    	dev = device_get_binding(LED0);
    	if (dev == NULL) {
    		return;
    	}
    
    	ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
    	if (ret < 0) {
    		return;
    	}
    
    	while (1) {
    		gpio_pin_set(dev, PIN, (int)led_is_on);
    		led_is_on = !led_is_on;
    		LOG_INF("LED is toggled!");
    		k_msleep(SLEEP_TIME_MS);
    	}
    }
    

    This setting can satisfy your basic needs of debugging. Please read the Logging — Zephyr Project Documentation (nordicsemi.com) for other advanced options.

    Best regards,

    Charlie

  • Thanks. Sorry for the late reply. Using your example I managed to annotate my code with RTT support and get this all working. We now have a working COVID-19 wearable opensource sample on the nRF5340DK. Having RTT log information was key. Much closer to being complete. Thanks!

Related