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

Fstorage issue without SoftDevice

Hi all,

I have an issue when trying to use the fstorage without the SoftDevice. The documentation explains that it is possible to use the FStorage without SoftDevice if the NVMC api backend is used, that is what I do. I have no issue when reading data from flash but when I try to write something, there is absolutely no data written to flash. I used the example provided in the SDK15.

Here is my initialization code 

/**
 * @brief NRF fstorage definition
 * @details Sets the fstorage event handler, start and end addresses.
 */
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
    /* Set a handler for fstorage events. */
    .evt_handler = vFstorageEventHandler,

    /* These below are the boundaries of the flash space assigned to this instance of fstorage.
     * You must set these manually, even at runtime, before nrf_fstorage_init() is called.
     * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
     * last page of flash available to write data. */
    .start_addr = FLASH_STORAGE_START_ADDRESS,
    .end_addr   = FLASH_STORAGE_END_ADDRESS,
};

With :
FLASH_STORAGE_START_ADDRESS = 0x0007F000
FLASH_STORAGE_END_ADDRESS = 0x00080000

void vFlashConfig_Init( void )
{
    ret_code_t rc;

    /* Pointer the the Flash Storage api */
    nrf_fstorage_api_t * p_fs_api;

    /* Initialize an fstorage instance using the nrf_fstorage_nvmc backend.
     * nrf_fstorage_nvmc uses the NVMC peripheral. This implementation can be used when the
     * SoftDevice is disabled or not present.
     *
     * Using this implementation when the SoftDevice is enabled results in a hardfault. */
    p_fs_api = &nrf_fstorage_nvmc;

    /* Initialize Flash Storage driver */
	APP_ERROR_CHECK( nrf_fstorage_init( &fstorage, p_fs_api, NULL ) );
}

And finally the dummy data write test

void vFlashConfig_WriteTest( void )
{
    /* Table with dummy data */
    uint8_t pu8TestTab[] = {0x01, 0x02, 0x03, 0x04};

    /* Save main application configuration */
    return_code = nrf_fstorage_write( &fstorage, 0x7F040, pu8TestTab, sizeof(pu8TestTab), NULL );

    APP_ERROR_CHECK(return_code);

    /* Wait during flash writing operations */
    vWaitForFlashReady( &fstorage );
}

The event handler function is called as expected and gives the following message :

 app: --> Event received: wrote 4 bytes at address 0x7F040.

I used the debugger to visualize the flash content, unfortunately no data written to the flash :

Thanks a lot for your help !

Regards,
Raphael

Parents
  • Hi,

    Can you show us the implementation of your vWaitForFlashReady() function? (Or even better, upload your whole project so that I can test on my side). Which SDK are you using?

  • Hi Einar,

    Thanks for your answer, here is the implementation of the vWaitForFlashReady( ) function :

    /**
     * @brief Wait for events while flash storage is busy.
     *
     * @param p_fstorage Pointer to the fstorage instance to wait for.
     */
    static void vWaitForFlashReady(nrf_fstorage_t const * p_fstorage)
    {
        /* While fstorage is busy, sleep and wait for an event. */
        while (nrf_fstorage_is_busy(p_fstorage))
        {
            __WFE();
        }
    }

    I prefer not to share the entire project at the moment as it is a strategic project for my company. However, after some more research and tests, I found out that when using the NVMC api backend, the concerned page must be erased before being written again. When doing so, it works pretty well. Can you confirm ? If so, is it also needed when using the SD api backend in combination with the SoftDevice ?

    Thanks again.

  • Hi,

    This should be OK, but we have only seen snippets and not the full flow of your application. Can you make a minimal example that demonstrate this issue? If not, an alternative for sharing your code could be to create a private support case and refer to this thread.

Reply Children
No Data
Related