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
  • Hi,

    Are you waiting for the FDS_INIT callback after calling fds_init()? It sounds like you are trying to do FDS operations before the module is porperly initiated. Refer to the FDS documentation:

    Initialization, like all other operations in FDS that involve writing or erasing flash memory, is an asynchronous operation.

  • Ok I see, perfectly logical. This is quite a key point but doesn't seem to be drawn out very well in the demos nor in the FDS documentation. So what I did was raise the write_flag in the init step, so the next call had to wait until the flag cleared.

    static void my_fds_evt_handler(fds_evt_t const * const p_fds_evt)
    {
        switch (p_fds_evt->id)
        {
            case FDS_EVT_INIT:
                if (p_fds_evt->result != FDS_SUCCESS)
                {
    
                    APP_ERROR_CHECK(p_fds_evt->result);
                    // Initialization failed.
                }
                if (p_fds_evt->result == FDS_SUCCESS)
                {
                    write_flag=1;
    
                }
                break;
    	case FDS_EVT_WRITE:
                if (p_fds_evt->result == FDS_SUCCESS)
                {
    		write_flag=1;
                }
                break;
            default:
                break;
        }
    }
    

    On a quick test this seems to have solved the problem entirely. Surprised it's not suggested as standard practice just like the flag on the other elements of FDS?

Reply
  • Ok I see, perfectly logical. This is quite a key point but doesn't seem to be drawn out very well in the demos nor in the FDS documentation. So what I did was raise the write_flag in the init step, so the next call had to wait until the flag cleared.

    static void my_fds_evt_handler(fds_evt_t const * const p_fds_evt)
    {
        switch (p_fds_evt->id)
        {
            case FDS_EVT_INIT:
                if (p_fds_evt->result != FDS_SUCCESS)
                {
    
                    APP_ERROR_CHECK(p_fds_evt->result);
                    // Initialization failed.
                }
                if (p_fds_evt->result == FDS_SUCCESS)
                {
                    write_flag=1;
    
                }
                break;
    	case FDS_EVT_WRITE:
                if (p_fds_evt->result == FDS_SUCCESS)
                {
    		write_flag=1;
                }
                break;
            default:
                break;
        }
    }
    

    On a quick test this seems to have solved the problem entirely. Surprised it's not suggested as standard practice just like the flag on the other elements of FDS?

Children
No Data
Related