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

Implement flashlog backend

Hello,

I am working on an nRF52840 with S140SD chip.

I am currently using the RTT as a backend for logs. I tried adding the Flashlog backend in order to save the logs in non-volatile memory however it doesn't appear to be saving them in the flash.

Here is my current initialization:

// Define log backend for using non-volatile memory
NRF_LOG_BACKEND_FLASHLOG_DEF(m_flash_log_backend);
NRF_LOG_BACKEND_CRASHLOG_DEF(m_crash_log_backend);

void log_init() {
  // Initialize logging module
  ret_code_t err_code = NRF_LOG_INIT(app_timer_cnt_get, TIMESTAMP_FREQ);
  APP_ERROR_CHECK(err_code);
  NRF_LOG_DEFAULT_BACKENDS_INIT(); // Enable RTT

  // Add flashlog backend
  flashlog_init();

  NRF_LOG_ERROR("Test flash log");
  NRF_LOG_WARNING("Test warning flash log");
  NRF_LOG_INFO("Test info flash log");
  NRF_LOG_FLUSH();
}

void flashlog_init(void)
{
    ret_code_t ret;
    int32_t backend_id;

    ret = nrf_log_backend_flash_init(&nrf_fstorage_sd);
    APP_ERROR_CHECK(ret);

    backend_id = nrf_log_backend_add(&m_flash_log_backend, NRF_LOG_SEVERITY_WARNING);
    APP_ERROR_CHECK_BOOL(backend_id >= 0);

    backend_id = nrf_log_backend_add(&m_crash_log_backend, NRF_LOG_SEVERITY_INFO);
    APP_ERROR_CHECK_BOOL(backend_id >= 0);

    nrf_log_backend_enable(&m_flash_log_backend);
    nrf_log_backend_enable(&m_crash_log_backend);
}

The sdk_config was modified to use:

NRF_QUEUE_ENABLED 0

RF_LOG_BACKEND_FLASH_ENABLED 1

NRF_LOG_BACKEND_FLASHLOG_ENABLED 1

NRF_LOG_BACKEND_FLASHLOG_QUEUE_SIZE 8

NRF_LOG_BACKEND_CRASHLOG_ENABLED 1

NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE 8

NRF_LOG_BACKEND_FLASH_SER_BUFFER_SIZE 64

NRF_LOG_BACKEND_FLASH_START_PAGE 0

NRF_LOG_BACKEND_PAGES 10

NRF_LOG_MSGPOOL_ELEMENT_COUNT 16

NRF_LOG_BUFSIZE 8192

NRF_LOG_FILTERS_ENABLED 1



I am reading the flash and getting the text using 

nrfjprog --readcode flashhex && python3 hex2dump.py flashhex > flash.txt

I also modified the linker to add a section for the flash storage.

I am not seeing the logs that were supposed to be stored in the flash.

What could I be doing wrong?

Thank you.

Parents
  • Hi,

    Do you see anything stored in this flash page? The format of the log data might be different from what you expect - instead of storing log messages in cleartext we store it as serialized logger objects with pointers referencing hardcoded messages inside the application image itself. This is to avoid duplication of log messages in flash.

  • Vidar, I don't understand... from the picture, the address to where log is stored is 0x0004e41c, how come 0x52000 is the log entry? Could you please explain more? Thank you.

  • The log entry stored at address 0x52000 is referencing a text string stored at 0x0004e41c in this case. Remember that you can have multiple log entries referencing the same text string. This makes it so that you don't have to write the same text string over and over again in flash.

    As an example, lets say you have periodic logging of some sensor value and the data is logged with this line of code:

         NRF_LOG_INFO( "sensor value :%d", sensor_value) 

    Here the string "sensor value :" will be stored at some other location in flash and only referenced with a pointer from the log entry. the  sensor value argument will be stored each time with the log data, because it isn't a constant value.

Reply
  • The log entry stored at address 0x52000 is referencing a text string stored at 0x0004e41c in this case. Remember that you can have multiple log entries referencing the same text string. This makes it so that you don't have to write the same text string over and over again in flash.

    As an example, lets say you have periodic logging of some sensor value and the data is logged with this line of code:

         NRF_LOG_INFO( "sensor value :%d", sensor_value) 

    Here the string "sensor value :" will be stored at some other location in flash and only referenced with a pointer from the log entry. the  sensor value argument will be stored each time with the log data, because it isn't a constant value.

Children
Related