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

SDK 14.2: NRF_LOG prefix is garbage

Hello all I am trying to get out some debug messages from my custom Firmware (and board) but the log looks like this:

<info> µ“°8$M­ø@ñ¨ó¹)F¨: NRF_LOG initialized

I am fiddling around in SDK-config.h for a while now, but can't find a solution to this. Any suggestions what could be causing this? The project previously used the RttDebugPrintDebug(), which I deactivated just for now to see if this messes up things but this didn't change anything...

The relevant parts of my main.cpp look like this:

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include <stdint.h>
#include <string.h>

#include <sdk_config.h>
#define NRF_LOG_MODULE_NAME main
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#ifdef __cplusplus
}
#endif

int main(void) {
    (void) NRF_LOG_INIT(NULL);
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    NRF_LOG_INFO("NRF_LOG initialized\r\n");

    while(1) {
        NRF_LOG_PROCESS();
    }
}

There are lot's of other headers included, which I ommited for readability. I guess they won't mess up things, because I don't use any of the functions of my project while debugging this issue as you can see in my main().

And here you can see the relevant content of my app_config.h

#define NRF_LOG_ENABLED 1
#if (NRF_LOG_ENABLED == 1)
    #define NRF_FPRINTF_ENABLED 			1
    #define NRF_BALLOC_ENABLED 				1
    #define NRF_LOG_BACKEND_RTT_ENABLED		1
    #define NRF_LOG_BACKEND_UART_ENABLED	0
    #define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 	64
    #define NRF_LOG_BACKEND_MAX_STRING_LENGTH		32
    #define NRF_LOG_BACKEND_UART_BAUDRATE 			30801920
    #define NRF_LOG_USES_COLORS 			1
    #define NRF_LOG_ERROR_COLOR				2
    #define NRF_LOG_WARNING_COLOR			4
    #define NRF_LOG_COLOR_DEFAULT			3
    #define NRF_LOG_DEFAULT_LEVEL 				4
    #define NRF_LOG_DEFERRED					1
    #define NRF_LOG_BUFSIZE						1024
    #define NRF_LOG_USES_TIMESTAMP				0
    #define NRF_LOG_ALLOW_OVERFLOW				1
#endif	// NRF_LOG_ENABLED

#define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP		2048
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 		16
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 			0

#define NRF_LOG_FILTERS_ENABLED 				0

Any suggestions how to resolve this?

Kind regards Karl

  • I have to thank you @Jørgen Holmefjord because while trying to create this minimum working example I stumbled upon the solution. Turns out, there was an error in my linker script. I am not sure why it makes a difference, but with this setting ind the linker script everything works just fine now. Here is the wrong part

    .log_dynamic_data :
    {
        PROVIDE(__start_log_dynamic_data = .);
        KEEP(*(.log_const_data))  /*THIS LINE IS WRONG*/
        PROVIDE(__stop_log_dynamic_data = .);
    } > RAM
    
    .log_const_data :
    {
        PROVIDE(__start_log_const_data = .);
        KEEP(*(.log_const_data))  /*THIS LINE IS WRONG*/
        PROVIDE(__stop_log_const_data = .);
    } > FLASH
    

    I had to change it to:

    .log_dynamic_data :
    {
        PROVIDE(__start_log_dynamic_data = .);
        KEEP(*(SORT(.log_dynamic_data*)))  /*CORRECT*/
        PROVIDE(__stop_log_dynamic_data = .);
    } > RAM
    
    .log_const_data :
    {
        PROVIDE(__start_log_const_data = .);
        KEEP(*(SORT(.log_const_data*)))  /*CORRECT*/
        PROVIDE(__stop_log_const_data = .);
    } > FLASH
    

    I'll attach my complete linker script as a reference here: gcc_nrf52.ld

    And also my akefile from the minimum working example: Makefile

    And here my main.cpp from the minimum working example: main.cpp

    And here the sdk_config.h: sdk_config.h

    Thank you for your input, I hope this helps some people from loosing their hair :)

  • This is great! Thank you for reporting back the solution.

  • Thank you @CarlosDerseher (and @joh2)!! For my own curiosity and desire to become a better C/C++ developer (new to this), how did you figure this out?

  • As I said, I tried to strip down my project to a minimum working example (MWE). When I could compile it, I didn't get out any debug messages at all. So I took a look at my working bootloader, which is actually the one from the SDK examples, with a few changes for signaling through a buzzer and a main.cpp instead of main.c . There I kicked out everything but log module initialization and it still gave me debug messages. So I thought maybe the sdk_config is wrong. Copy pasting it to my MWE didn't bring logs to live. Next step was to compare the Makefiles, but I couldn't find anything suspicous there. Exchanging the linker scripts though brought up debug messages and they were correct too. So I did compare those two files with notepad++ and there you go, I found the line which did the trick. As I said, I don't know why this makes such a difference, maybe someone else can explain that to us?

Related