nRF52840 SDK16 - nrf_fstorage: addr_is_within_bounds(p_fs, dest, len) check failed in nrf_fstorage_write() with value 0x10.

Hi guys,

I try to integrate the flash logger backend

When I run the code I get the following error:

<error> nrf_fstorage: addr_is_within_bounds(p_fs, dest, len) check failed in nrf_fstorage_write() with value 0x10.

This is the sdk_config section

//==========================================================
// <e> NRF_LOG_BACKEND_FLASH_ENABLED - nrf_log_backend_flash - Log flash backend
//==========================================================
#ifndef NRF_LOG_BACKEND_FLASH_ENABLED
#define NRF_LOG_BACKEND_FLASH_ENABLED 1
#endif
 
// <e> NRF_LOG_BACKEND_FLASHLOG_ENABLED - Enable flashlog backend.
//==========================================================
#ifndef NRF_LOG_BACKEND_FLASHLOG_ENABLED
#define NRF_LOG_BACKEND_FLASHLOG_ENABLED 1
#endif
// <o> NRF_LOG_BACKEND_FLASHLOG_QUEUE_SIZE - Logger messages queue size. 
// <i> Queue holds log messages pending to be written to flash.
// <i> Note that the queue holds logger messages and thus the queue size determines
// <i> increasing the pool of logger messages (see log message pool configuration).
 
#ifndef NRF_LOG_BACKEND_FLASHLOG_QUEUE_SIZE
#define NRF_LOG_BACKEND_FLASHLOG_QUEUE_SIZE 8
#endif
 
// </e>
 
// <e> NRF_LOG_BACKEND_CRASHLOG_ENABLED - Enable crashlog backend.
//==========================================================
#ifndef NRF_LOG_BACKEND_CRASHLOG_ENABLED
#define NRF_LOG_BACKEND_CRASHLOG_ENABLED 1
#endif
// <o> NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE - Number of log messages held to be flushed in panic. 
// <i> Crashlog FIFO always keeps a defined number of the most
// <i> recent logs (severity level is set on runtime).
// <i> Note that the FIFO holds logger messages and thus the FIFO size determines
// <i> increasing the pool of logger messages (see log message pool configuration).
 
#ifndef NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE
#define NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE 8
#endif
 
// </e>
 
// <o> NRF_LOG_BACKEND_FLASH_SER_BUFFER_SIZE - Size of the buffer used for serialize log message. 
// <i> Message is trimmed if it is longer. It may happen in case of 
// <i> hexdump message. Buffer size must be multiple of 4.
 
#ifndef NRF_LOG_BACKEND_FLASH_SER_BUFFER_SIZE
#define NRF_LOG_BACKEND_FLASH_SER_BUFFER_SIZE 64
#endif
 
// <h> Flash log location - Configuration of flash area used for storing the logs.
 
//==========================================================
// <o> NRF_LOG_BACKEND_FLASH_START_PAGE - Starting page.  
// <i> If 0, then pages directly after the application are used.
 
#ifndef NRF_LOG_BACKEND_FLASH_START_PAGE
#define NRF_LOG_BACKEND_FLASH_START_PAGE 0
#endif
 
// <o> NRF_LOG_BACKEND_PAGES - Number of pages. 
#ifndef NRF_LOG_BACKEND_PAGES
#define NRF_LOG_BACKEND_PAGES 1
#endif
 
// </h> 
//==========================================================
// </e>

This is my flashlog init function:

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 error returns from nrf_fstorage_write() when calling the NRF_FSTORAGE_PARAM_CHECK(addr_is_within_bounds(p_fs, dest, len), NRF_ERROR_INVALID_ADDR)

What am I missing?

Parents Reply Children
  • Thanks for confirming. So this is not supposed to happen. The flash backend should stop writing to flash as soon as the flash page is full. Do you get this assertion immediately even if you erase the flash log page first?

    e.g.

    $ nrfjprog --erasepage 0x59000

    Also, have you tried to enable NRF_LOG_FILTERS_ENABLED and increased the NRF_LOG_SEVERITY_* level so the logger does not attempt to write every message to flash as recommended here: Flash logger backend?

  • Hi Vidar,

    Well, I did some tests. To many issues :/ do not know where I should start but I will try to be as illustrative as possible.

    First of all if I change the NRF_LOG_DEFAULT_LEVEL to either Error or Warning then I do not get <error> nrf_fstorage: addr_is_within_bounds(p_fs, dest, len) check failed in nrf_fstorage_write() with value 0x10

    It doesn't look as a solution to me, also I didn't see any difference by setting the NRF_LOG_FILTERS_ENABLED

    Issue 1

    I have included the following logs (ERROR, WARNING and INFO) just for testing

    static void log_init(void) {
      ret_code_t err_code = NRF_LOG_INIT(NULL);
      APP_ERROR_CHECK(err_code);
    
      NRF_LOG_DEFAULT_BACKENDS_INIT();
      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();
    }

    I can read some logs, however, they are outside the memory boundaries of the flash logger backend

    Start address: 368640

    Stop address: 372735

    While the address I read the log is 353472

    Issue 2

    Then I disabled the flash log backend and produced a softdevice crash error to be captured by the crash log backend

    This is the error I read from the debug terminal

    and this is the error I read from the flash memory

    As you can see, the error log is stored again outside the boundaries and another issue is that missing information from the log such as the file path and the line number where the error occurred.

    Moreover, the starting address of the flash logger is empty.

    Issue 3

    If I try to forward for example just the WARNING to the backend and I set the NRF_LOG_FILTERS_ENABLED, the info and error logs are still stored in the flash

    Lastly, in case this is useful, this is the sdk_config for nRF_Log

    // </h> 
    //==========================================================
    
    // </h> 
    //==========================================================
    
    // <h> nRF_Log 
    
    //==========================================================
    // <e> NRF_LOG_BACKEND_FLASH_ENABLED - nrf_log_backend_flash - Log flash backend
    //==========================================================
    #ifndef NRF_LOG_BACKEND_FLASH_ENABLED
    #define NRF_LOG_BACKEND_FLASH_ENABLED 1
    #endif
     
    // <e> NRF_LOG_BACKEND_FLASHLOG_ENABLED - Enable flashlog backend.
    //==========================================================
    #ifndef NRF_LOG_BACKEND_FLASHLOG_ENABLED
    #define NRF_LOG_BACKEND_FLASHLOG_ENABLED 1
    #endif
    // <o> NRF_LOG_BACKEND_FLASHLOG_QUEUE_SIZE - Logger messages queue size. 
    // <i> Queue holds log messages pending to be written to flash.
    // <i> Note that the queue holds logger messages and thus the queue size determines
    // <i> increasing the pool of logger messages (see log message pool configuration).
     
    #ifndef NRF_LOG_BACKEND_FLASHLOG_QUEUE_SIZE
    #define NRF_LOG_BACKEND_FLASHLOG_QUEUE_SIZE 8
    #endif
     
    // </e>
     
    // <e> NRF_LOG_BACKEND_CRASHLOG_ENABLED - Enable crashlog backend.
    //==========================================================
    #ifndef NRF_LOG_BACKEND_CRASHLOG_ENABLED
    #define NRF_LOG_BACKEND_CRASHLOG_ENABLED 1
    #endif
    // <o> NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE - Number of log messages held to be flushed in panic. 
    // <i> Crashlog FIFO always keeps a defined number of the most
    // <i> recent logs (severity level is set on runtime).
    // <i> Note that the FIFO holds logger messages and thus the FIFO size determines
    // <i> increasing the pool of logger messages (see log message pool configuration).
     
    #ifndef NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE
    #define NRF_LOG_BACKEND_CRASHLOG_FIFO_SIZE 8
    #endif
     
    // </e>
     
    // <o> NRF_LOG_BACKEND_FLASH_SER_BUFFER_SIZE - Size of the buffer used for serialize log message. 
    // <i> Message is trimmed if it is longer. It may happen in case of 
    // <i> hexdump message. Buffer size must be multiple of 4.
     
    #ifndef NRF_LOG_BACKEND_FLASH_SER_BUFFER_SIZE
    #define NRF_LOG_BACKEND_FLASH_SER_BUFFER_SIZE 64
    #endif
     
    // <h> Flash log location - Configuration of flash area used for storing the logs.
     
    //==========================================================
    // <o> NRF_LOG_BACKEND_FLASH_START_PAGE - Starting page.  
    // <i> If 0, then pages directly after the application are used.
     
    #ifndef NRF_LOG_BACKEND_FLASH_START_PAGE
    #define NRF_LOG_BACKEND_FLASH_START_PAGE 0
    #endif
     
    // <o> NRF_LOG_BACKEND_PAGES - Number of pages. 
    #ifndef NRF_LOG_BACKEND_PAGES
    #define NRF_LOG_BACKEND_PAGES 1
    #endif
     
    // </h> 
    //==========================================================
    // </e>
    
    
    //==========================================================
    // <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
    //==========================================================
    #ifndef NRF_LOG_BACKEND_RTT_ENABLED
    #define NRF_LOG_BACKEND_RTT_ENABLED 1
    #endif
    // <o> NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. 
    // <i> Size of the buffer is a trade-off between RAM usage and processing.
    // <i> if buffer is smaller then strings will often be fragmented.
    // <i> It is recommended to use size which will fit typical log and only the
    // <i> longer one will be fragmented.
    
    #ifndef NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE
    #define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
    #endif
    
    // <o> NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS - Period before retrying writing to RTT 
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
    #endif
    
    // <o> NRF_LOG_BACKEND_RTT_TX_RETRY_CNT - Writing to RTT retries. 
    // <i> If RTT fails to accept any new data after retries
    // <i> module assumes that host is not active and on next
    // <i> request it will perform only one write attempt.
    // <i> On successful writing, module assumes that host is active
    // <i> and scheme with retry is applied again.
    
    #ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
    #define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
    #endif
    
    // </e>
    
    // <e> NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart - Log UART backend
    //==========================================================
    #ifndef NRF_LOG_BACKEND_UART_ENABLED
    #define NRF_LOG_BACKEND_UART_ENABLED 0
    #endif
    // <o> NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin 
    #ifndef NRF_LOG_BACKEND_UART_TX_PIN
    #define NRF_LOG_BACKEND_UART_TX_PIN 6
    #endif
    
    // <o> NRF_LOG_BACKEND_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=> 1000000 baud 
    
    #ifndef NRF_LOG_BACKEND_UART_BAUDRATE
    #define NRF_LOG_BACKEND_UART_BAUDRATE 30801920
    #endif
    
    // <o> NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. 
    // <i> Size of the buffer is a trade-off between RAM usage and processing.
    // <i> if buffer is smaller then strings will often be fragmented.
    // <i> It is recommended to use size which will fit typical log and only the
    // <i> longer one will be fragmented.
    
    #ifndef NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE
    #define NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE 64
    #endif
    
    // </e>
    
    // <e> NRF_LOG_ENABLED - nrf_log - Logger
    //==========================================================
    #ifndef NRF_LOG_ENABLED
    #define NRF_LOG_ENABLED 1
    #endif
    // <h> Log message pool - Configuration of log message pool
    
    //==========================================================
    // <o> NRF_LOG_MSGPOOL_ELEMENT_SIZE - Size of a single element in the pool of memory objects. 
    // <i> If a small value is set, then performance of logs processing
    // <i> is degraded because data is fragmented. Bigger value impacts
    // <i> RAM memory utilization. The size is set to fit a message with
    // <i> a timestamp and up to 2 arguments in a single memory object.
    
    #ifndef NRF_LOG_MSGPOOL_ELEMENT_SIZE
    #define NRF_LOG_MSGPOOL_ELEMENT_SIZE 20
    #endif
    
    // <o> NRF_LOG_MSGPOOL_ELEMENT_COUNT - Number of elements in the pool of memory objects 
    // <i> If a small value is set, then it may lead to a deadlock
    // <i> in certain cases if backend has high latency and holds
    // <i> multiple messages for long time. Bigger value impacts
    // <i> RAM memory usage.
    
    #ifndef NRF_LOG_MSGPOOL_ELEMENT_COUNT
    #define NRF_LOG_MSGPOOL_ELEMENT_COUNT 8
    #endif
    
    // </h> 
    //==========================================================
    
    // <q> NRF_LOG_ALLOW_OVERFLOW  - Configures behavior when circular buffer is full.
     
    
    // <i> If set then oldest logs are overwritten. Otherwise a 
    // <i> marker is injected informing about overflow.
    
    #ifndef NRF_LOG_ALLOW_OVERFLOW
    #define NRF_LOG_ALLOW_OVERFLOW 1
    #endif
    
    // <o> NRF_LOG_BUFSIZE  - Size of the buffer for storing logs (in bytes).
     
    
    // <i> Must be power of 2 and multiple of 4.
    // <i> If NRF_LOG_DEFERRED = 0 then buffer size can be reduced to minimum.
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    // <2048=> 2048 
    // <4096=> 4096 
    // <8192=> 8192 
    // <16384=> 16384 
    
    #ifndef NRF_LOG_BUFSIZE
    #define NRF_LOG_BUFSIZE 1024
    #endif
    
    // <q> NRF_LOG_CLI_CMDS  - Enable CLI commands for the module.
     
    
    #ifndef NRF_LOG_CLI_CMDS
    #define NRF_LOG_CLI_CMDS 0
    #endif
    
    // <o> NRF_LOG_DEFAULT_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRF_LOG_DEFAULT_LEVEL
    #define NRF_LOG_DEFAULT_LEVEL 3
    #endif
    
    // <q> NRF_LOG_DEFERRED  - Enable deffered logger.
     
    
    // <i> Log data is buffered and can be processed in idle.
    
    #ifndef NRF_LOG_DEFERRED
    #define NRF_LOG_DEFERRED 1
    #endif
    
    // <q> NRF_LOG_FILTERS_ENABLED  - Enable dynamic filtering of logs.
     
    
    #ifndef NRF_LOG_FILTERS_ENABLED
    #define NRF_LOG_FILTERS_ENABLED 1
    #endif
    
    // <q> NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED  - Enable use of critical region for non deffered mode when flushing logs.
     
    
    // <i> When enabled NRF_LOG_FLUSH is called from critical section when non deffered mode is used.
    // <i> Log output will never be corrupted as access to the log backend is exclusive
    // <i> but system will spend significant amount of time in critical section
    
    #ifndef NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED
    #define NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED 0
    #endif
    
    // <o> NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
     
    // <16=> 16 
    // <32=> 32 
    // <64=> 64 
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
    #define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
    #endif
    
    // <o> NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
     
    // <16=> 16 
    // <32=> 32 
    // <64=> 64 
    // <128=> 128 
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
    #define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
    #endif
    
    // <e> NRF_LOG_USES_COLORS - If enabled then ANSI escape code for colors is prefixed to every string
    //==========================================================
    #ifndef NRF_LOG_USES_COLORS
    #define NRF_LOG_USES_COLORS 0
    #endif
    // <o> NRF_LOG_COLOR_DEFAULT  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_COLOR_DEFAULT
    #define NRF_LOG_COLOR_DEFAULT 0
    #endif
    
    // <o> NRF_LOG_ERROR_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_ERROR_COLOR
    #define NRF_LOG_ERROR_COLOR 2
    #endif
    
    // <o> NRF_LOG_WARNING_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRF_LOG_WARNING_COLOR
    #define NRF_LOG_WARNING_COLOR 4
    #endif
    
    // </e>

    I could share my project if you want to debug it.

  • Hi,

    I'm sorry for the delay response. I already looked through detailed information your provided, but I think I will have to actually debug this on my side to understand why it happens. So yes, it would be helpful if you could provide your project as well.

  • Thank you ,

    I attach the app. I have commented out some functions from the main so that you can run it on a nrf52 dev board. Please exact it in nRF5_SDK_16.0.0\examples\ble_peripheral

    BLE_IMU_v6.3_modified for debugging by Nordic.zip

Related