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

  • 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

  • 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
  • Do you check all the returns from the FDS functions?

    Attached is an example using the FDS from the ble_app_uart example. Check the UART log to see if it works. At least from here, I can start the FDS module after ble_stack_init();

     

    ble_app_uart_FDS.zip

     

    Best regards,

    Edvin

  • Hi, that looks working. I can take it as reference to my project. Thanks.

    <warning> nrf_sdh_ble: RAM starts at 0x20002A68, can be adjusted to 0x20002760.

    <warning> nrf_sdh_ble: RAM size can be adjusted to 0xD8A0.

    <info> app: UART Start!

    <info> app: fds_test_write()

    <info> app: read from record: 

    <info> app: DEADBEEF

    <info> app: DEADBEEF

    <info> app: DEADBEEF

    <info> app: DEADBEEF

    <info> app: DEADBEEF

    <info> app: DEADBEEF

    <info> app: 

    <info> app: Found 6 valid records.

    <info> app: Found 0 dirty records (ready to be garbage collected).

  • Hi, I tested it with one of my custom boards what don't have second crystal and it does not run. 

    I use this config

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

    // <h> Clock - SoftDevice clock configuration

    //==========================================================
    // <o> NRF_SDH_CLOCK_LF_SRC - SoftDevice clock source.

    // <0=> NRF_CLOCK_LF_SRC_RC
    // <1=> NRF_CLOCK_LF_SRC_XTAL
    // <2=> NRF_CLOCK_LF_SRC_SYNTH

    #ifndef NRF_SDH_CLOCK_LF_SRC
    #define NRF_SDH_CLOCK_LF_SRC 0
    #endif

    // <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval.
    #ifndef NRF_SDH_CLOCK_LF_RC_CTIV
    #define NRF_SDH_CLOCK_LF_RC_CTIV 16
    #endif

    // <o> NRF_SDH_CLOCK_LF_RC_TEMP_CTIV - SoftDevice calibration timer interval under constant temperature.
    // <i> How often (in number of calibration intervals) the RC oscillator shall be calibrated
    // <i> if the temperature has not changed.

    #ifndef NRF_SDH_CLOCK_LF_RC_TEMP_CTIV
    #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 2
    #endif

    // <o> NRF_SDH_CLOCK_LF_XTAL_ACCURACY - External crystal clock accuracy used in the LL to compute timing windows.

    // <0=> NRF_CLOCK_LF_XTAL_ACCURACY_250_PPM
    // <1=> NRF_CLOCK_LF_XTAL_ACCURACY_500_PPM
    // <2=> NRF_CLOCK_LF_XTAL_ACCURACY_150_PPM
    // <3=> NRF_CLOCK_LF_XTAL_ACCURACY_100_PPM
    // <4=> NRF_CLOCK_LF_XTAL_ACCURACY_75_PPM
    // <5=> NRF_CLOCK_LF_XTAL_ACCURACY_50_PPM
    // <6=> NRF_CLOCK_LF_XTAL_ACCURACY_30_PPM
    // <7=> NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM

    #ifndef NRF_SDH_CLOCK_LF_XTAL_ACCURACY
    #define NRF_SDH_CLOCK_LF_XTAL_ACCURACY 0
    #endif
Related