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

FDS SDK13 : Failure to initialise from time to time

So I have been integrating FDS into a project under SDK13. It's based on an example that Hung updated for SDK12.1. So after init of fds the method fds_test_find_and_delete() is called. However I am having trouble with it not initialising from time to time.

When it gets to the garbage collection call in the snippet below I will get back error 0x2 or Failure to Initialize. Now if you skip this and just go to a read or write call, the same error occurs.

static ret_code_t fds_test_find_and_delete (void)
{
    #define FILE_ID     0x1111
    #define REC_KEY     0x2222
    fds_record_desc_t   record_desc;
    fds_find_token_t    ftok;
	
    ftok.page=0;
    ftok.p_addr=NULL;
    // Loop and find records with same ID and rec key and mark them as deleted. 
    while (fds_record_find(FILE_ID, REC_KEY, &record_desc, &ftok) == FDS_SUCCESS)
    {
	fds_record_delete(&record_desc);
	NRF_LOG_INFO("Deleted record ID: %d \r\n",record_desc.record_id);
    }
    // call the garbage collector to empty them, don't need to do this all the time, this is just for demonstration
    ret_code_t ret = fds_gc();
    if (ret != FDS_SUCCESS)
    {
        APP_ERROR_CHECK(ret);
	return ret;
    }
    return NRF_SUCCESS;
}

I have added this to ble_stack_init()

err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);

And have added this method

static void sys_evt_dispatch(uint32_t sys_evt)
{
    fs_sys_event_handler(sys_evt);
    ble_advertising_on_sys_evt(sys_evt);
}

I have also enabled the module in sdk_config.h. So I think I have pretty much covered the main reasons for a failure to initialise.

And the odd thing was that when I first enabled it as above it did not work, same error. At one point I added fstorage.h even though I wasn't getting any errors and then it started working. Then while I was experimenting with some write record_chunk.p_data structs it suddenly stopped working again.

What am I missing?

Parents
  • UPDATE:

    After much searching I got it to work by adding nrf_delay_ms(2) between fds_init() and fds_test_find_and_delete(). Then it began working. Out of interest I then commented out the nrf_delay_ms(2) and it still works! I'll keep an eye on it since it seems a little unstable.

    UPDATE 2:

    During the course of the day I notice that FDS will fail from time to time. At one stage it failed even when the delays was 2ms, but changing it to 10ms solved it. It seems in my case there can be a delay in FDS initing that needs to be taken into account. I am not sure if this is expected behaviour or not, but that's my observation.

Reply
  • UPDATE:

    After much searching I got it to work by adding nrf_delay_ms(2) between fds_init() and fds_test_find_and_delete(). Then it began working. Out of interest I then commented out the nrf_delay_ms(2) and it still works! I'll keep an eye on it since it seems a little unstable.

    UPDATE 2:

    During the course of the day I notice that FDS will fail from time to time. At one stage it failed even when the delays was 2ms, but changing it to 10ms solved it. It seems in my case there can be a delay in FDS initing that needs to be taken into account. I am not sure if this is expected behaviour or not, but that's my observation.

Children
No Data
Related