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

FDS event FDS_EVT_WRITE not triggered when using SDK 16.0.0 and Softdevice S132 7.0.1

Trying to get FDS working with the latest SDK 16.0.0 and Softdevice S132 7.0.1. The problem is that FDS event handler triggers only when softdevice is disabled. Here is the snippet:

volatile bool fdsInitialized;

void fdsEventHandler(fds_evt_t const *event) {
    switch (event->id) {
        case FDS_EVT_INIT:
            if (event->result == NRF_SUCCESS) {
                NRF_LOG_INFO("FDS initialized");
                fdsInitialized = true;
            }
            break;
        case FDS_EVT_WRITE:
            if (event->result == NRF_SUCCESS) {
                NRF_LOG_INFO("FDS write completed");
                NRF_LOG_INFO("Record ID: 0x%04x", event->write.record_id);
                NRF_LOG_INFO("File ID: 0x%04x", event->write.file_id);
                NRF_LOG_INFO("Record key: 0x%04x", event->write.record_key);
            }
            break;
    }
}

void softdeviceInit() {
    ret_code_t err = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err);

    uint32_t ramStart = 0;
    err = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ramStart);
    APP_ERROR_CHECK(err);

    err = nrf_sdh_ble_enable(&ramStart);
    APP_ERROR_CHECK(err);
}

int main() {
    // Log
    ret_code_t err = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err);

    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("Started");

    // Power management
    err = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err);

    // Softdevice
    softdeviceInit();

    // FDS
    err = fds_register(fdsEventHandler);
    APP_ERROR_CHECK(err);
    err = fds_init();
    APP_ERROR_CHECK(err);

    NRF_LOG_INFO("Waiting for FDS to be initialized");
    while (!fdsInitialized) {
        nrf_pwr_mgmt_run();
    }

    uint32_t d[] = {1, 2, 3};
    fds_record_t record;
    record.file_id = 0x1111;
    record.key = 0x2222;
    record.data.p_data = d;
    record.data.length_words = 3;

    fds_record_desc_t recordDesc;
    err = fds_record_write(&recordDesc, &record);
    APP_ERROR_CHECK(err);

    NRF_LOG_INFO("Wrote record ID: %d", recordDesc.record_id);

    while (true) {
        nrf_pwr_mgmt_run();
    }
}

I have FDS_VIRTUAL_PAGES set to 3 in my sdk_config.h. I erase the chip, flash the softdevice, then flash the application and see the following log output:

<info> app: Started
<info> app: Waiting for FDS to be initialized
*** RESET ***
<info> app: Started
<info> app: Waiting for FDS to be initialized
*** RESET ***
<info> app: Started
<info> app: Waiting for FDS to be initialized
*** RESET ***
<info> app: Started
<info> app: FDS initialized
<info> app: Waiting for FDS to be initialized
<info> app: Wrote record ID: 1

It seems that FDS initializes one page at a time. After 3 resets I get past FDS initialization and get NRF_SUCCESS code returned from fds_record_write function. However, FDS_EVT_WRITE is not triggered. If I disable softdevice, everything goes smoothly and I see the following output:

<info> app: Started
<info> app: FDS initialized
<info> app: Waiting for FDS to be initialized
<info> app: FDS write completed
<info> app: Record ID: 0x0001
<info> app: File ID: 0x1111
<info> app: Record key: 0x2222
<info> app: Wrote record ID: 1

I've seen similar posts regarding SDK 14 with the same behavior but the solution there didn't work for me:

https://devzone.nordicsemi.com/f/nordic-q-a/32582/fds_evt_handler-not-invoked-for-52840-sdkv14-2-s140

https://devzone.nordicsemi.com/f/nordic-q-a/29089/nrf_fstorage_sd-not-receiving-soc-events

However, the missing nrf_sdh_soc.c which was the cause of the issue is already included in my target.

Related