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

debugging over RTT in linux

Hello, I want to test using RTT for logging since I am using UART for send/receive packets. I made following changes in sdk_config.h:

#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 1 // previously 0
#endif

after I call make default, i have following errors while compiling:

Linking target: _build/nrf51422_xxac.out
_build/nrf51422_xxac_app_error_weak.c.o: In function `app_error_fault_handler':
/home/ac4/programs/NRF_SDK_12.1/examples/ble_peripheral/ble_app_uart/pca10028/s130/armgcc/../../../../../../components/libraries/
util/app_error_weak.c:26: undefined reference to `nrf_log_frontend_std_0'
/home/ac4/programs/NRF_SDK_12.1/examples/ble_peripheral/ble_app_uart/pca10028/s130/armgcc/../../../../../../components/libraries/
util/app_error_weak.c:27: undefined reference to `nrf_log_blocking_backend_set'
/home/ac4/programs/NRF_SDK_12.1/examples/ble_peripheral/ble_app_uart/pca10028/s130/armgcc/../../../../../../components/libraries/

util/app_error_weak.c:27: undefined reference to `nrf_log_frontend_dequeue'
_build/nrf51422_xxac_softdevice_handler.c.o: In function `softdevice_enable':
/home/ac4/programs/NRF_SDK_12.1/examples/ble_peripheral/ble_app_uart/pca10028/s130/armgcc/../../../../../../components/softdevice
/common/softdevice_handler/softdevice_handler.c:530: undefined reference to `nrf_log_frontend_std_1'
/home/ac4/programs/NRF_SDK_12.1/examples/ble_peripheral/ble_app_uart/pca10028/s130/armgcc/../../../../../../components/softdevice
/common/softdevice_handler/softdevice_handler.c:543: undefined reference to `nrf_log_frontend_std_1'
/home/ac4/programs/NRF_SDK_12.1/examples/ble_peripheral/ble_app_uart/pca10028/s130/armgcc/../../../../../../components/softdevice
/common/softdevice_handler/softdevice_handler.c:536: undefined reference to `nrf_log_frontend_std_1'
/home/ac4/programs/NRF_SDK_12.1/examples/ble_peripheral/ble_app_uart/pca10028/s130/armgcc/../../../../../../components/softdevice
/common/softdevice_handler/softdevice_handler.c:538: undefined reference to `nrf_log_frontend_std_1'
collect2: error: ld returned 1 exit status
make: *** [_build/nrf51422_xxac.out] Error 1

Please suggest where I am going wrong?

  • You also need to add the Segger RTT files to your makefile.

    In the SRC_FILES make sure these are included:

      $(SDK_ROOT)/external/segger_rtt/RTT_Syscalls_GCC.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
    

    In the INC_FOLDERS, make sure this is inclued:

      $(SDK_ROOT)/external/segger_rtt \
    
  • Since Sigurd's answer provide some good guides to dig further, there is some more work to do in order to be "compliant" with Nordic proprietary logging system.

    Just continue with Sigurd's suggestions and include libraries for NRF_LOG backend (under the SRC_FILES):

    $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \  
    $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
    

    in INC_FOLDERS make just you have:

    $(SDK_ROOT)/components/libraries/log/src \
    

    Then add header files to main.c, e.g.:

    #define NRF_LOG_MODULE_NAME "MY_APP"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    

    To work out-of-the-box you will also need declaration for your constants (which can be copy-pasted from other examples), best to place them at the end of config file (default: sdk_config.h):

    // ....other constants ...
    //
    // <h> nrf_log_backend - Logging sink
    
    //==========================================================
    // <o> NRF_LOG_BACKEND_MAX_STRING_LENGTH - Buffer for storing single output string
    // <i> Logger backend RAM usage is determined by this value.
    
    #ifndef NRF_LOG_BACKEND_MAX_STRING_LENGTH
    #define NRF_LOG_BACKEND_MAX_STRING_LENGTH 256
    #endif
    
    // <o> NRF_LOG_TIMESTAMP_DIGITS - Number of digits for timestamp
    // <i> If higher resolution timestamp source is used it might be needed to increase that
    
    #ifndef NRF_LOG_TIMESTAMP_DIGITS
    #define NRF_LOG_TIMESTAMP_DIGITS 8
    #endif
    
    // <e> NRF_LOG_BACKEND_SERIAL_USES_UART - If enabled data is printed over UART
    //==========================================================
    #ifndef NRF_LOG_BACKEND_SERIAL_USES_UART
    #define NRF_LOG_BACKEND_SERIAL_USES_UART 0
    #endif
    #if  NRF_LOG_BACKEND_SERIAL_USES_UART
    // <o> NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE  - Default Baudrate
    
    // <323584=> 1200 baud
    // <643072=> 2400 baud
    // <1290240=> 4800 baud
    // <2576384=> 9600 baud
    // <3862528=> 14400 baud
    // <5152768=> 19200 baud
    // <7716864=> 28800 baud
    // <10289152=> 38400 baud
    // <15400960=> 57600 baud
    // <20615168=> 76800 baud
    // <30801920=> 115200 baud
    // <61865984=> 230400 baud
    // <67108864=> 250000 baud
    // <121634816=> 460800 baud
    // <251658240=> 921600 baud
    // <268435456=> 57600 baud
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE
    #define NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE 30801920
    #endif
    
    // <o> NRF_LOG_BACKEND_SERIAL_UART_TX_PIN - UART TX pin
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_TX_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_TX_PIN 6
    #endif
    
    // <o> NRF_LOG_BACKEND_SERIAL_UART_RX_PIN - UART RX pin
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_RX_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_RX_PIN 8
    #endif
    
    // <o> NRF_LOG_BACKEND_SERIAL_UART_RTS_PIN - UART RTS pin
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_RTS_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_RTS_PIN 5
    #endif
    
    // <o> NRF_LOG_BACKEND_SERIAL_UART_CTS_PIN - UART CTS pin
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_CTS_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_CTS_PIN 7
    #endif
    
    // <o> NRF_LOG_BACKEND_SERIAL_UART_FLOW_CONTROL  - Hardware Flow Control
    
    // <0=> Disabled
    // <1=> Enabled
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_FLOW_CONTROL
    #define NRF_LOG_BACKEND_SERIAL_UART_FLOW_CONTROL 0
    #endif
    
    // <o> NRF_LOG_BACKEND_UART_INSTANCE  - UART instance used
    
    // <0=> 0
    
    #ifndef NRF_LOG_BACKEND_UART_INSTANCE
    #define NRF_LOG_BACKEND_UART_INSTANCE 0
    #endif
    
    #endif //NRF_LOG_BACKEND_SERIAL_USES_UART
    // </e>
    
    // <q> NRF_LOG_BACKEND_SERIAL_USES_RTT  - If enabled data is printed using RTT
    
    
    #ifndef NRF_LOG_BACKEND_SERIAL_USES_RTT
    #define NRF_LOG_BACKEND_SERIAL_USES_RTT 1
    #endif
    
    // </h>
    //==========================================================
    

    The important parts here are "NRF_LOG_BACKEND_SERIAL_USES_RTT 1" and "NRF_LOG_BACKEND_SERIAL_USES_UART 0", so debug data will go ONLY to your Segger RTT.

    BTW, don't forget to initialize the NRF_LOG module before use it (in main.c), i.e.:

    // Initialize NRF_LOG module
    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);
    
  • You are correct. Since I was at the time of posting, using an example application from nrf SDK, I didn't have to bother about the steps you have mentioned. However, just recently when I was writing my customized application I was stuck because NRF_LOG_BACKEND_SERIAL_USES_RTT 1 and NRF_LOG_USES_RTT were not enabled. This is what I was looking for.

Related