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

FDS not working after SD initialize

HI, I have nrf52832 and I am using latest SDK 14.2.0. 

I am using FDS and the problem is that before setting up BLE fds_record_write works fine but after setting up BLE all data using fds_record_write goes to dirty records. My ble part is just simple central what scanns advertisements and creates connectioin. Here is my main code.


ret_code_t ret;

ret = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(ret);

NRF_LOG_DEFAULT_BACKENDS_INIT();

ret = app_timer_init();
APP_ERROR_CHECK(ret);

NRF_LOG_INFO("RUN\r\n");

//INIT FLASH
fds_register(fds_evt_handler);

NRF_LOG_INFO("Initializing fds...");

ret = fds_init();
APP_ERROR_CHECK(ret);

wait_for_fds_ready();

fds_stat_t stat = {0};

ret = fds_stat(&stat);
APP_ERROR_CHECK(ret);

NRF_LOG_INFO("Found %d valid records.", stat.valid_records);
NRF_LOG_INFO("Found %d dirty records (ready to be garbage collected).", stat.dirty_records);

fds_gc();

//When I call here fds_record_write it works fine

ble_init();

//When I call here fds_record_write it goes to dirty records

Parents
  • Hello,

    What backend do you use for FDS? I assume you use NVMC, because it is used when you do not use the softdevice. While you use the softdevice however, you must use the softdevice backend.

    If you look into the sdk_config.h file for your project, there should be a #define called FDS_BACKEND. If this is set to 1 you use the NVMC backend, but you want to set it to 2, which is the SD backend.

    You will see in fds.h that this will change what nrf_fstorage_---.h file you use. Try to change to NRF_FSTORAGE_SD (2), and see if this solves the issue.

    Best regards,

    Edvin

Reply
  • Hello,

    What backend do you use for FDS? I assume you use NVMC, because it is used when you do not use the softdevice. While you use the softdevice however, you must use the softdevice backend.

    If you look into the sdk_config.h file for your project, there should be a #define called FDS_BACKEND. If this is set to 1 you use the NVMC backend, but you want to set it to 2, which is the SD backend.

    You will see in fds.h that this will change what nrf_fstorage_---.h file you use. Try to change to NRF_FSTORAGE_SD (2), and see if this solves the issue.

    Best regards,

    Edvin

Children
  • I have backend sd. I copied it from flash_fds example.

    // <e> FDS_ENABLED - fds - Flash data storage module
    //==========================================================
    #ifndef FDS_ENABLED
    #define FDS_ENABLED 1
    #endif
    // <h> Pages - Virtual page settings

    // <i> Configure the number of virtual pages to use and their size.
    //==========================================================
    // <o> FDS_VIRTUAL_PAGES - Number of virtual flash pages to use.
    // <i> One of the virtual pages is reserved by the system for garbage collection.
    // <i> Therefore, the minimum is two virtual pages: one page to store data and one page to be used by the system for garbage collection.
    // <i> The total amount of flash memory that is used by FDS amounts to @ref FDS_VIRTUAL_PAGES * @ref FDS_VIRTUAL_PAGE_SIZE * 4 bytes.

    #ifndef FDS_VIRTUAL_PAGES
    #define FDS_VIRTUAL_PAGES 3
    #endif

    // <o> FDS_VIRTUAL_PAGE_SIZE - The size of a virtual flash page.


    // <i> Expressed in number of 4-byte words.
    // <i> By default, a virtual page is the same size as a physical page.
    // <i> The size of a virtual page must be a multiple of the size of a physical page.
    // <1024=> 1024
    // <2048=> 2048

    #ifndef FDS_VIRTUAL_PAGE_SIZE
    #define FDS_VIRTUAL_PAGE_SIZE 1024
    #endif

    // </h>
    //==========================================================

    // <h> Backend - Backend configuration

    // <i> Configure which nrf_fstorage backend is used by FDS to write to flash.
    //==========================================================
    // <o> FDS_BACKEND - FDS flash backend.


    // <i> NRF_FSTORAGE_SD uses the nrf_fstorage_sd backend implementation using the SoftDevice API. Use this if you have a SoftDevice present.
    // <i> NRF_FSTORAGE_NVMC uses the nrf_fstorage_nvmc implementation. Use this setting if you don't use the SoftDevice.
    // <1=> NRF_FSTORAGE_NVMC
    // <2=> NRF_FSTORAGE_SD

    #ifndef FDS_BACKEND
    #define FDS_BACKEND 2
    #endif

    // </h>
    //==========================================================

    // <h> Queue - Queue settings

    //==========================================================
    // <o> FDS_OP_QUEUE_SIZE - Size of the internal queue.
    // <i> Increase this value if you frequently get synchronous FDS_ERR_NO_SPACE_IN_QUEUES errors.

    #ifndef FDS_OP_QUEUE_SIZE
    #define FDS_OP_QUEUE_SIZE 4
    #endif

    // </h>
    //==========================================================

    // <h> CRC - CRC functionality

    //==========================================================
    // <e> FDS_CRC_CHECK_ON_READ - Enable CRC checks.

    // <i> Save a record's CRC when it is written to flash and check it when the record is opened.
    // <i> Records with an incorrect CRC can still be 'seen' by the user using FDS functions, but they cannot be opened.
    // <i> Additionally, they will not be garbage collected until they are deleted.
    //==========================================================
    #ifndef FDS_CRC_CHECK_ON_READ
    #define FDS_CRC_CHECK_ON_READ 0
    #endif
    // <o> FDS_CRC_CHECK_ON_WRITE - Perform a CRC check on newly written records.


    // <i> Perform a CRC check on newly written records.
    // <i> This setting can be used to make sure that the record data was not altered while being written to flash.
    // <1=> Enabled
    // <0=> Disabled

    #ifndef FDS_CRC_CHECK_ON_WRITE
    #define FDS_CRC_CHECK_ON_WRITE 0
    #endif

    // </e>

    // </h>
    //==========================================================

    // <h> Users - Number of users

    //==========================================================
    // <o> FDS_MAX_USERS - Maximum number of callbacks that can be registered.
    #ifndef FDS_MAX_USERS
    #define FDS_MAX_USERS 4
    #endif
Related