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

Not getting a write call-back with FDS

I've been doing some exercises with the FDS module to ensure I understand it and have come across an issue. When I write I am not seeing a write call-back in the fds_event_handler to say it has occurred even though I am getting a success message on calling the write function.

In terms of registering the fds_event_handler and initializing FDS that all seems fine. I get the call-backs and the success messages.

When I 'fds_record_write()' I get a success message but when I immediately read it returns record not found (0x0a). Writing is asynchronous so I want to perform a read only when I know the system has actually written to flash. However in my fds_event_handler I never see case "FDS_EVT_WRITE".

This is the event handler registration and initialization of the module. These all return success and I get the init call-back.

void fds_module_register()
{
    ret_code_t ret = fds_register(fds_evt_handler);
    if (ret != FDS_SUCCESS)
    {
        // Registering of the event handler has failed.
    }

    if (ret == FDS_SUCCESS)
    {
        NRF_LOG_PRINTF("FDS event handler sucessfully registered \r\n");
    }
}

void fds_module_init()
{
    ret_code_t ret = fds_init();
    if (ret == FDS_SUCCESS)
    {
         NRF_LOG_PRINTF("FDS sucessfully initialized \r\n");
    }	
     if (ret != FDS_SUCCESS)
    {
         NRF_LOG_PRINTF("FDS NOT initialized \r\n");
    }	 
}

This is the fds_event_handler()

void 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)
            {
                NRF_LOG_PRINTF("In fds_evt_handler and initialization successful \n\r");
            }
            if (p_fds_evt->result != FDS_SUCCESS)
            {
                NRF_LOG_PRINTF("Initialization had a problem \n\r");
            }
            break;

      case FDS_EVT_WRITE:
            if (p_fds_evt->result == FDS_SUCCESS)
            {
		        NRF_LOG_PRINTF("In fds_evt_handler and write successful \n\r");
            }
            if (p_fds_evt->result != FDS_SUCCESS)
            {
		        NRF_LOG_PRINTF("In fds_evt_handler and there was an issue with write \n\r");
            }
            break;

       default:
            break;
    }
}

This is my write() which returns FDS_SUCCESS

ret_code_t module_fds_write(void)
{

    #define FILE_ID     0x2222
    #define REC_KEY     0x3333

    uint32_t data_for_store = DEAD_F00D;
    fds_record_t          record;
    fds_record_desc_t     descriptor;
    fds_record_chunk_t    record_chunk;

    record_chunk.p_data = &data_for_store;
    record_chunk.length_words = 1;

    // Fill in the record keys.
    record.key     = REC_KEY;
    record.file_id = FILE_ID;
    record.data.p_chunks = &record_chunk;
    record.data.num_chunks = 1;

    ret_code_t retval = fds_record_write(&descriptor, &record);

    if (retval == FDS_SUCCESS)
    {
      NRF_LOG_PRINTF("Writing was a success = %d \r\n", retval);
      NRF_LOG_PRINTF("Writing Record ID = %d \r\n",descriptor.record_id);
    }

    return retval;
}

Am I right in thinking that all FDS events will call-back to the fds_event_handler? I've looked closely at the SDK11 on FDS and it doesn't suggest anything more is needed, but is there another step needed to get the call-backs? Or is there another problem here that is preventing the call-back even though the write function returns FDS_SUCCESS?

This is nRF52, pca10040, S132 V2.0, Segger Embedded Studio.

Thanks,

Related