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

NRF_LOG_INFO: Only the last log statement is printed out

I inherited a Nordic project that is running on the 52832 board with the 15.3 version of the SDK.  The project uses CLI, TWI, and logging.  The developer has to jump through hoops to get all 3 functioning at the same time.  I am now expanding the project.  The issue.  NRF_LOG_INFO works fine if I provide a constant string (e.q. NRF_LOG_INFO("Hello world");)

However, the minute I create a generic logging utility which uses non-stack memory (using data segment memory - statically declared array), only the last logged data is printed several times. 

so something like

XXX_LOG_PRINTF(LOG_INFO, "sensor initialization start.");
.... some more code here.....
XXX_LOG_PRINTF(LOG_INFO, "sensor initialization complete.");
My logging utility can take variable length arguments, etc.  So the "constant strings" you see in the calls above gets copied to a statically declared string which gets passed to the Nordic logging utility.
I only see the last line printed twice.  I have turned off deferred, so I am at a loss.

I have read the chapter on logging and think I understand the buffering concept on the front and back end.   I have tried messing with the sdk_config.h to no avail.   Here are what I think are relevant:

All my CLI commands and output work great.

#define NRF_LOG_DEFERRED 0
#define NRF_LOG_CLI_CMDS 1
#define NRF_LOG_FILTERS_ENABLED 0
The ways I have tried to log the info:
NRF_LOG_INFO("%s\n", NRF_LOG_PUSH((char *)pLogMsg));
or
NRF_LOG_RAW_INFO
I am running on Ubuntu linux, using minicom (which works great for constant strings and cli).  Segger, RTT or any other IDE is not an option.  This must be done via UART<
Please let me know if you need additional info to assist in this.
Thanks,
Jim
Parents
  • So I took the CLI example and added the following code and the same problem occurs.  I turned off deferred (=0), and the result is I never see the first log message, I just see the second message printed twice.

    static char message[256];
    
    void logMsg(const char *pMessage)
    {
        int cnt = 0;
    
        memset(message, 0, 256);
        cnt = snprintf(message, 255, pMessage); 
        message[cnt-1] = '\0';
        NRF_LOG_RAW_INFO("%s\n", message);
    
        return;
    }
    
    ....
    
    int main(void)
    {
    ...
        /* logMsg replaces the NRF_LOG_RAW_INFO */
        logMsg("Command Line Interface example started.\n");
        logMsg("Please press the Tab key to see all available commands.\n");
    
        while (true)
        {
            UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
    #if CLI_OVER_USB_CDC_ACM && APP_USBD_CONFIG_EVENT_QUEUE_ENABLE
            while (app_usbd_event_queue_process())
            {
                /* Nothing to do */
            }
    #endif
            cli_process();
        }
    }......
    
    [00:00:00.000,000] <warning> app: Logger configuration file not found.
    [00:00:00.000,122] <info> stack_guard: Stack Guard (128 bytes): 0x2000E000-0x2000E07F (total stack size: 8192 bytes, usable stack area: 8064 bytes)
    Please press the Tab key to see all available commands.
    Please press the Tab key to see all available commands.
    

Reply
  • So I took the CLI example and added the following code and the same problem occurs.  I turned off deferred (=0), and the result is I never see the first log message, I just see the second message printed twice.

    static char message[256];
    
    void logMsg(const char *pMessage)
    {
        int cnt = 0;
    
        memset(message, 0, 256);
        cnt = snprintf(message, 255, pMessage); 
        message[cnt-1] = '\0';
        NRF_LOG_RAW_INFO("%s\n", message);
    
        return;
    }
    
    ....
    
    int main(void)
    {
    ...
        /* logMsg replaces the NRF_LOG_RAW_INFO */
        logMsg("Command Line Interface example started.\n");
        logMsg("Please press the Tab key to see all available commands.\n");
    
        while (true)
        {
            UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
    #if CLI_OVER_USB_CDC_ACM && APP_USBD_CONFIG_EVENT_QUEUE_ENABLE
            while (app_usbd_event_queue_process())
            {
                /* Nothing to do */
            }
    #endif
            cli_process();
        }
    }......
    
    [00:00:00.000,000] <warning> app: Logger configuration file not found.
    [00:00:00.000,122] <info> stack_guard: Stack Guard (128 bytes): 0x2000E000-0x2000E07F (total stack size: 8192 bytes, usable stack area: 8064 bytes)
    Please press the Tab key to see all available commands.
    Please press the Tab key to see all available commands.
    

Children
No Data
Related