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

Parents Reply Children
  • 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

  • Hi Eric,

    I took your code, reverted to the original blinky sdk_config.h(so you could see exactly what needs to be added), and added the following:

    #ifndef NRF_LOG_ENABLED
    #define NRF_LOG_ENABLED 1
    #endif
    
    #ifndef NRF_LOG_DEFERRED
    #define NRF_LOG_DEFERRED 0
    #endif
    
    #ifndef NRF_LOG_BACKEND_RTT_ENABLED
    #define NRF_LOG_BACKEND_RTT_ENABLED 1
    #endif
    
    #ifndef NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE
    #define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
    #endif
    
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
    #endif
    
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
    #endif
    
    #ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_UP
    #define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 512
    #endif
    
    #ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS
    #define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 2
    #endif
    
    #ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN
    #define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 16
    #endif
    
    #ifndef SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS
    #define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 2
    #endif
    
    #ifndef SEGGER_RTT_CONFIG_DEFAULT_MODE
    #define SEGGER_RTT_CONFIG_DEFAULT_MODE 0
    #endif

    I also included the source files nrf_log_backend_rtt, nrf_log_default_backend and nrf_log_backend_serial from components/libraries/log/src, as well as the segger_rtt files from external/segger_rtt(along with adding its include path ../../../../../../external/segger_rtt to the end of the project included directories - options->preprocessor->User Included Directories). You can find this setting by right clicking on the project name, at the top of your project directory and selecting options.

    These files seem to be included in your project in your screenshots, but not when I opened the project files you sent earlier.

    The result from this is "Invert!" being printed in the RTT terminal along with the leds toggling like in the blinky example, the RTT output is seen in the included image.


    I recommend that you use the program "J-link RTT Viewer" for viewing RTT messages, instead of the built in SES debug window. I find the debug window often behaves unexpectedly. Mind you that you may not have J-link RTT Viewer open at the same time as the debug terminal in SES, that will not work.

    If you would like to use the UART backend instead, take a look at an example using this, and see if you can change the code to use UART instead - I recommend this exercise!

    I'll include the modified code in its entirety also, so that you may take a look.
    my_code.zip

    Sorry for my late reply by the way, I had some issues with my network this morning.

    Hope you have a great weekend Eric, and please let me know if you should have any more questions and issues in the future! :)

    Best regards,
    Karl

  • Thank you very much Karl, that has helped me get it working!

    I will need to keep reading through all the infocenter pages on the logger module to really understand it, but this is a good first step.

    I will modify the code to use UART now for some practice.

    Thanks again

    -Eric

Related