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.

Parents Reply Children
  • Same happens when I do not compile SDK as a library. I'm including nrf_sdh_soc.c directly as any other source file in my build. The problem is that if I remove it, the build still goes smoothly but the handler is not invoked. I tried to search the usages of nrf_sdh_soc_evts_poll() function in SDK and I cannot see any invocations. So there is no reason for the linker to complain that this function is referenced but not implemented. Can you please tell the place where it is being called?

  • Hi,

    radionoise said:
    The problem is that if I remove it, the build still goes smoothly but the handler is not invoked.

    Ah yes, my bad. This is due to the exotic nature of the section variables. I don't see any way you could get a compile-time warning about this since all is done by linker "magic".

    radionoise said:
    Can you please tell the place where it is being called?

    It is registered in the end of the nrf_sdh_soc.c by using the NRF_SDH_STACK_OBSERVER macro, which adds this to a section variable by the linker. This section variable (sdh_stack_observers) holds a list over event handlers to be called, and all handlers are called from the loop in nrf_sdh_evts_poll() in components\softdevice\common\nrf_sdh.c.

  • Can we have some dummy function in nrf_sdh_soc.c which will be called in fds_init() if softdevice is present to introduce some compile-time check?

    This will save many hours of debugging for developers in future.

    If it’s not possible, maybe we can have a warning in FDS documentation which clearly says that this file should be added to build and in some circumstances it can be thrown out by linker and handler will not be called?

  • Hi,

    I will forward the suggestion to the SDK developers so that they can consider it for a future release.

Related