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

SPI transfer failure

Hi,

I have a strange issue on my device.

Once in a while, after turning on my device and connect it to the PC via NFC trigger, the device fails during writing to external flash via nrfx_spim_xfer.

The function nrfx_spim_xfer returns NRF_SUCCESS, but after that, the device waits too long (9000 times in a for loop), until SPIM event handler is called.

After that, the device resets itself, maybe due to a fatal error.

The SPI is protected by a mutex in my application.

Is there any option that the NFC is related to that? Maybe it's something with power on process? Any ideas?

Thanks!

Parents Reply Children
  • Yes, the flashlog/crashlog will be stored in Non-Volatile Memory (flash) and is not removed until you explicitly remove it from flash (using the provided API or erasing the flash pages). Note that flashlogs are dropped if the allocated flash area is full, as described in the previously linked documentation.

  • I'm not sure I understood correctly how to use that. Should I set any flag? 

    After that - is that a command line I need to operate in order to see the logs?

    Thanks!

  • If you want to use it with the SPI example, you need to add the flashlog backend yourself. It is not used in that example.

    Add the following to the main.c file:

    #if NRF_LOG_BACKEND_FLASH_ENABLED
    #if NRF_LOG_BACKEND_FLASHLOG_ENABLED
    NRF_LOG_BACKEND_FLASHLOG_DEF(m_flash_log_backend);
    #endif
    #endif
    
    #if NRF_LOG_BACKEND_FLASH_ENABLED
    static void flashlog_init(void)
    {
        ret_code_t ret;
        int32_t backend_id;
    
        NRF_LOG_INFO("Initializing flashlog");
        
        ret = nrf_log_backend_flash_init(&nrf_fstorage_sd);
        APP_ERROR_CHECK(ret);
    #if NRF_LOG_BACKEND_FLASHLOG_ENABLED
        backend_id = nrf_log_backend_add(&m_flash_log_backend, NRF_LOG_SEVERITY_WARNING);
        APP_ERROR_CHECK_BOOL(backend_id >= 0);
    
        nrf_log_backend_enable(&m_flash_log_backend);
    #endif
    }
    #endif

    And call the function from the main-function:

    #if NRF_LOG_BACKEND_FLASH_ENABLED
        flashlog_init();
    #endif

    Enable the backend in your sdk_config.h file:

    //==========================================================
    // <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
    // <q> NRF_LOG_BACKEND_FLASH_CLI_CMDS  - Enable CLI commands for this module.
     
    
    #ifndef NRF_LOG_BACKEND_FLASH_CLI_CMDS
    #define NRF_LOG_BACKEND_FLASH_CLI_CMDS 0
    #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 0
    #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>

    The flashlog only stores the address of the string in code-flash, to avoid duplicating long strings. To read the logs it is easiest to use the nrf_log_backend_flash_next_entry_get function. You can have a look at how this function is used in the CLI example.

Related