Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

what are the required steps/files/definitions/commands to get RTT output from a custom app into RTT Viewer ?

I am using an nRF chip and the nRF SDK for 1st time and I think I am still at the steep part of the learning curve.

My problem is that I cannot get the log from my custom app in RTT Viewer. I use:

  • custom PCB with Taiyo Yuden EYSKBNZWB/nRF52840 Wireless Module
  • SDK 17.0.2
  • arm gcc 10.3.1
  • J-Link RTT Viewer V7.52b (JLinkRTTViewerExe)
  • nRF5_SDK/examples/peripheral/template_project

In my main.c source file I have included the following headers: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.2.0%2Flib_nrf_log.html

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

Again in the main.c source file, I have the define - https://devzone.nordicsemi.com/f/nordic-q-a/29977/undefined-reference-to-nrf_log_default_backend_init

  • #define NRF_LOG_BACKEND_RTT_ENABLED 1

In the Makefile @ nRF5_SDK/examples/peripheral/template_project/pca10056/blank/armgcc I added the following line:

  • $(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \

in order to solve the linker issue: main.c: undefined reference to `nrf_log_default_backends_init'

In the sdk_config.h file @ nRF5_SDK/examples/peripheral/template_project/pca10056/blank/config I have the follwoing settings:

The contents of my main.s source file are:

int main ( void ) {
    ret_code_t err_code = NRF_LOG_INIT ( NULL );
    APP_ERROR_CHECK ( err_code );
    NRF_LOG_DEFAULT_BACKENDS_INIT ();
    
    while ( true ) {
        uint32_t i ;

        for ( i = 0; i < 10; i++ ) {
            NRF_LOG_INFO ( "i = %u\r\n", i );
        }
    }
}

I thought that I could see some numbers printed in RTT VIewer but unfortunately I still can't manage to get the RTT output into the RTT Viewer after reading several posts so I would ask for help at this point. Any would be highly appreciated :-)

P.S. I think the connection PC <-> J-Link <-> PCB works fine as I managed to get an LED blink ca. every second.

Parents
  • Thank you for the thorough answer again. I don't really see any reason that you shouldn't be able to get these messages in the RTT viewer here.

    Since yesterday however, I've noticed that the template project doesn't actually implement the RTT backend, so I might be missing a step. What you could do is to try building and running an example that does, like the peripheral/temperature example for instance. Just make sure to set 

    NRF_LOG_BACKEND_UART_ENABLED to 0 and NRF_LOG_BACKEND_RTT_ENABLED to 1 in the sdk_config.h file. If you still don't see anything in the RTT viewer, try to switch the CR_ON_LF_ENABLED define to 0 in sdk_config.h as well.
    Best regards,
    Simon
Reply
  • Thank you for the thorough answer again. I don't really see any reason that you shouldn't be able to get these messages in the RTT viewer here.

    Since yesterday however, I've noticed that the template project doesn't actually implement the RTT backend, so I might be missing a step. What you could do is to try building and running an example that does, like the peripheral/temperature example for instance. Just make sure to set 

    NRF_LOG_BACKEND_UART_ENABLED to 0 and NRF_LOG_BACKEND_RTT_ENABLED to 1 in the sdk_config.h file. If you still don't see anything in the RTT viewer, try to switch the CR_ON_LF_ENABLED define to 0 in sdk_config.h as well.
    Best regards,
    Simon
Children
  • Hi, Simon,

    thanks for your reply and suggestion !

    Just built and flashed the temperature project, with a semi-successful result :-)

    The code I used is (I commented out the temperature part and left only the first log output statement with an LED switch-on after it):

    // #includes ...
    // #defines ...
    
    int main ( void ) {
        nrf_gpio_cfg_output ( LED_PIN ) ;
        
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
        NRF_LOG_INFO("Temperature example started.");
        
        nrf_gpio_pin_set ( LED_PIN );
    }

    The results are as follows:

    Setting 1 (sdk_config.h):

    NRF_LOG_BACKEND_UART_ENABLED 0

    NRF_LOG_BACKEND_RTT_ENABLED 1

    NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 1 or 0

    NRF_LOG_ENABLED 1

    NRF_LOG_DEFERRED 1

    No output in RTT Viewer ! --> from what I could read, this can be explained by the fact that I don't have a call to

    NRF_LOG_PROCESS() in my code, hence I don't see the output. This is understandable.

    Setting 2 (sdk_config.h):

    NRF_LOG_BACKEND_UART_ENABLED 0

    NRF_LOG_BACKEND_RTT_ENABLED 1

    NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 1 or 0

    NRF_LOG_ENABLED 1

    NRF_LOG_DEFERRED 0

    Output in RTT Viewer is shown, but only the 1st time after a connection is established !

    However, no output is shown if the program is for example reset via “nrfjprog -f nrf52 –reset” with a running RTT Viewer connection !

    For the output to be shown again, the connection in RTT Viewer must be first disconnected, and then re-established AFTER the chip has been previously reset, e.g.

    1. chip reset

    2. (Connection lost) via File → Disconnect 

    3. File → Connect

      Output:

      00> <info> app: Temperature example started.

      00>

    i.e. output is shown when:

    1. chip is reset

    2. RTT Viewer is disconnected

    3. RTT Viewer is re-connected anew

     

    Modifying NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED as described in:

    Link: https://devzone.nordicsemi.com/f/nordic-q-a/46685/no-log-output-to-debug-terminal-in-ses-or-rtt-viewer

    does not change the situation !

    The only difference is the number of output lines being output in RTT Viewer, i.e.

    NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0

    Output:

    00> <info> app: Temperature example started.

    NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 1

    Output:

    00> <info> app: Temperature example started.

    00>

    => in the 2nd case two lines are printed as output, whereas in the 1st case only 1 line is printed as output !

     

    Do you know what is the reason for this behavior and what needs to be done to solve it ?
    This apart, could you elaborate on:
    actually implement the RTT backend

    What does it exactly mean to implement the RTT backend ? Could you point me to a resource where all the required steps are described in terms of required headers / sources / Makefile settings / sdk_config.h settings, or alternatively just type them here in as the logging functionality is so fundamental ?

    Greets and thanks again

    Mario

Related