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

How do I add RTT debugging to blinky example in Embedded Studio

Hi all, I apologise for this very basic question, but I don't understand how to add/enable RTT debugging to my code. I want to practice writing basic code for the NRF5 SDK, and I think adding debugging to the blinky example is a good step.

What I have done is:

-Copy the "blinky" folder from ...nRF5_SDK\examples\peripheral\blinky  to a new folder   ...nRF5_SDK\my_code\peripheral\blinky

(Did this to keep my test code separate from the examples)

-Replace the config file ...\nRF5_SDK\my_code\peripheral\blinky\pca10056\mbr\config with the config file from ...\nRF5_SDK\examples\ble_peripheral\ble_app_blinky\pca10056\s140\config

(Did this becuase ble_app_blinky example uses RTT debugging, and I know it works)

-Add nrf_log_backend_rtt.c and nrf_log_default_backends.c to the nRF_Log folder in Embedded studio from ...nRF5_SDK\components\libraries\log\src

(Did this to match the ble_app_blinky example)

-Create folder nRF_Segger_RTT in Embedded studio, and added SEGGER_RTT.c , SEGGER_RTT_printf.c , SEGGER_RTT_Syscalls_SES.c   from ...\nRF5_SDK\external\segger_rtt folder

(Did this to match the ble_app_blinky example)

-Use CMSIS configurator to make sure NRF_LOG_BACKEND_RTT and NRF_LOG_ENABLED are enabled in sdk_config.h

(Need to be enabled to work)

-Modify main.c to use logging.

When I do those steps, the code builds, but when debugging, nothing shows on the debug terminal

Here is the main code:

#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "boards.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"


int main(void)
{
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    bsp_board_init(BSP_INIT_LEDS);


    while (true)
    {
        for (int i = 0; i < LEDS_NUMBER; i++)
        {
            NRF_LOG_INFO("Invert");
            bsp_board_led_invert(i);
            nrf_delay_ms(500);
        }
    }
}

Project items in SES:

Thanks in advance

  • Hello,

    Thank you for including your code.
    Have you seen the Debugging with RTT tutorial?
    If you have not, I highly recommend taking a look at it first. Be advised that since SDK v12.0.0 RTT is built into the NRF_LOG module.

    If you have seen the tutorial, and made sure you've followed the steps, please let me know where it does not perform as expected. You say nothing shows in your debug terminal - have you checked with a serial monitor as well?

    Best regards,
    Karl

  • Thank you for your response, I have seen that tutorial, however I am using Segger embedded studio. The tutorial only mentions Keil, also the RTT files it says to download don't include syscalls for Segger embedded studio, so I thought it wouldn't work. As for what I have done myself, I have tried using the SES built in debug window, Segger RTT viewer, and a Serial monitor, but nothing shows. The code builds fine in SES. Thanks

  • Hello,

    Sorry, I did not see this in when initially reading your ticket. I misunderstood your question.

    I apologise for this very basic question

    No problem at all, you do not need to apologize. I am happy to help!

    Which SDK version are you working with?

    From you code, I immediately notice that you do not call NRF_LOG_INIT(NULL), could you add this to the beginning of your main function, and see if this resolves your issue?
    Your includes and added project source files looks correct.

    If this does not solve your problem, I will build your code tomorrow and take a look!

    If you would like to read more about the Logger module you could do so here, and its API reference can be found here. Here can see how to use different logger debug levels to see different output during your development - such as using NRF_LOG_DEBUG printouts, which are not even compiled on the lower NRF_LOG_LEVELs.
    You could also use the non-RTT options, such as UART(then you can see it using a serial monitor), by enabling them instead of RTT :)

    Best regards,
    Karl

     

  • Thanks for your help again.

    I am using Nrf5 SDK 16.0.0. and Segger embedded studio V4.52

    I tried adding NRF_LOG_INIT(NULL) to the start of main() but still nothing shows in debug window or RTT viewer. I have tried using UART instead of RTT, so I have:

    -Added nrf_drv_uart.c, nrfx_uart.c, nrfx_uarte.c to the project in embedded studio.

    -Enabled NRF_LOG_BACKEND_UART_ENABLED in sdk_config.h

    -Disabled NRF_LOG_BACKEND_RTT_ENABLED in sdk_config.h

     

    Unfortunately after those steps, the project doesn't build. The error is:

    Building ‘blinky_pca10056_mbr’ from solution ‘blinky_pca10056_mbr’ in configuration ‘Release’
    1> Compiling ‘nrf_log_str_formatter.c’
    2> Compiling ‘nrf_log_frontend.c’
    3> Compiling ‘nrf_log_backend_rtt.c’
    4> Compiling ‘nrf_log_backend_serial.c’
    5> Compiling ‘nrf_log_backend_uart.c’
    6> Compiling ‘nrf_log_default_backends.c’
    7> Compiling ‘boards.c’
    8> Compiling ‘app_error_weak.c’
    9> Compiling ‘app_error_handler_gcc.c’
    10> Compiling ‘nrf_atomic.c’
    11> Compiling ‘nrf_fprintf.c’
    12> Compiling ‘nrf_balloc.c’
    13> Compiling ‘nrf_fprintf_format.c’
    14> Compiling ‘nrf_memobj.c’
    15> Compiling ‘nrf_ringbuf.c’
    5> C:\Nordic\nRF5_SDK_16.0.0_98a08e2\components\libraries\log\src\nrf_log_backend_uart.c:45:10: fatal error: nrf_drv_uart.h: No such file or directory
    5> compilation terminated.
    16> Compiling ‘nrf_strerror.c’
    17> Compiling ‘nrfx_atomic.c’
    Build failed

    I checked C:\Nordic\nRF5_SDK_16.0.0_98a08e2\components\libraries\log\src and indeed there is no nrf_drv_uart.h file there. That file is actually located at C:\Nordic\nRF5_SDK_16.0.0_98a08e2\integration\nrfx\legacy

    So I'm not quite sure how to fix that error

    Thanks

    -Eric

Related