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

NRF LOG crashlog backend

I can't get flashlog/crashlog to work properly. The symptoms are that when NRF_LOG_BACKEND_FLASH_START_PAGE is set to 0 (i.e logs are written to address right after the application code ends), the flashlog status CLI command reveals that logs are being filled but flashlog read says the flashlog is empty.

If I clear the flashlog using flashlog clear command, I can start reading the newly written logs. However, when the NRF_LOG_FINAL_FLUSH is called before a reset, the code enters a hardfault condition. This means that the NRF_LOG_FINAL_FLUSH's writes are somehow corrupting flash.

To check for that, I changed NRF_LOG_BACKEND_FLASH_START_PAGE to a value after my application and before FDS pages (~150) and logging seems to be working fine and so does NRF_LOG_FINAL_FLUSH. Except when the flash is filled with logs-- when flashlog status says 99% of the flash is used, it doesn't increment the counter for dropped logs anymore. A reset after NRF_LOG_FINAL_FLUSH results in a hardfault again. 

Am I somehow misusing the module? I am using SDK 15.2 and FreeRTOS. I followed how the  flashlog module is used in the ble_cli_app example identically. 

 

Parents
  • Just a hunch but can you try to increase (maybe double) the below values in your FreeRTOSConfig.h file to see if that helps?

    #define configMINIMAL_STACK_SIZE
    #define configTOTAL_HEAP_SIZE

  • OK, found the source of the issue. When NRF_LOG_FINAL_FLUSH() is called when there's no room in the flashlog, the crashlog_marker_inject() function inside nrf_log_backend_crashlog_panic_set() makes a call to nrf_fstorage_write(). nrf_fstorage_write() has a PARAM_CHECK call for addr_is_within_bounds() which fails. On failure, it prints to NRF_LOG_ERROR. At this point, crashlog is in panic state so it accepts that entry and tries another flash write which fails and another NRF_LOG_ERROR function is called ad infinitum/until hardfault. 

    How do you suggest I patch this issue? If I disable the PARAM CHECK, then nrf_fstorage_write() succeeds and the adjacent flash page is written to which is undesirable. 

Reply
  • OK, found the source of the issue. When NRF_LOG_FINAL_FLUSH() is called when there's no room in the flashlog, the crashlog_marker_inject() function inside nrf_log_backend_crashlog_panic_set() makes a call to nrf_fstorage_write(). nrf_fstorage_write() has a PARAM_CHECK call for addr_is_within_bounds() which fails. On failure, it prints to NRF_LOG_ERROR. At this point, crashlog is in panic state so it accepts that entry and tries another flash write which fails and another NRF_LOG_ERROR function is called ad infinitum/until hardfault. 

    How do you suggest I patch this issue? If I disable the PARAM CHECK, then nrf_fstorage_write() succeeds and the adjacent flash page is written to which is undesirable. 

Children
Related