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

NRF_Fstorage Address Issue

Hi i am working on project where i need to store logs on flash, i included nrf_storage and set start address 0x42000 and end address 0x50000 according to my application, my product contains softdevice, application and bootloader.... but when i try to read write or erase specific address it get stuck ... my application is based on FreeRTOS 

  • <info> app: fstorage example started.

    <info> app: SoftDevice is present.

    <info> app: Initializing nrf_fstorage_sd implementation...

    <info> app: ========| flash info |========

    <info> app: erase unit: 4096 bytes

    <info> app: program unit: 4 bytes

    <info> app: ==============================

    <info> app: Last Address 100000 1048576

    <info> app: 2nd Last Address FFFFF,1048575

    <info> app: Writing "hello_world!" to flash.

    f_fstorage_write() with value 0x10.

  • Hi,

    What exactly do you mean by "it get stuck"? Do you get a hardfault, an error, code stuck in a loop waiting for an event, etc.?

    Can you post the code you used for configuring fstorage, and how you perform the read/write/erase operations?

    Have you made sure that the start and end addresses used for fstorage does not overlap with the application code area?

    Best regards,
    Jørgen

  • Yes I did made sure it is not overlapping 

    as you can see from above pic last address is 0x0004114F

    So i choosed start address 

    NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
    {
    /* Set a handler for fstorage events. */
    .evt_handler = fstorage_evt_handler,

    /* 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 = 0x42000,
    .end_addr = 0x50000,
    };

    and following is my code for implementation:

    NRF_LOG_INFO("fstorage example started.");

    nrf_fstorage_api_t * p_fs_api;
    #ifdef SOFTDEVICE_PRESENT
    NRF_LOG_INFO("SoftDevice is present.");
    NRF_LOG_INFO("Initializing nrf_fstorage_sd implementation...");
    /* Initialize an fstorage instance using the nrf_fstorage_sd backend.
    * nrf_fstorage_sd uses the SoftDevice to write to flash. This implementation can safely be
    * used whenever there is a SoftDevice, regardless of its status (enabled/disabled). */
    p_fs_api = &nrf_fstorage_sd;
    #else
    NRF_LOG_INFO("SoftDevice not present.");
    NRF_LOG_INFO("Initializing nrf_fstorage_nvmc implementation...");
    /* 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;
    #endif

    rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
    APP_ERROR_CHECK(rc);

    print_flash_info(&fstorage);
    /* It is possible to set the start and end addresses of an fstorage instance at runtime.
    * They can be set multiple times, should it be needed. The helper function below can
    * be used to determine the last address on the last page of flash memory available to
    * store data. */
    rc = nrf5_flash_end_addr_get();
    NRF_LOG_INFO("Last Address %x %d",rc,rc);
    NRF_LOG_INFO("2nd Last Address %x,%d",rc-1,rc-1);

    char datatest[]="hello_world!";
    /* Let's write to flash. */
    NRF_LOG_INFO("Writing \"%s\" to flash.", datatest);
    rc = nrf_fstorage_write(&fstorage,0x42001, &datatest, strlen(datatest), NULL);
    APP_ERROR_CHECK(rc);

    wait_for_flash_ready(&fstorage);
    NRF_LOG_INFO("Done.");

    I also tried to erase page but same output returns

  • I would recommend you to check the return code, rc, from nrf_fstorage_write. The destination address needs to be word-aligned, which it does not seems to be. 

    You may also debug the application to see exactly where the code is stuck.

  • i tried to debug and my data is multiple of program unit which is 4

Related