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,

Parents
  • Calling

    void fs_sys_event_handler( uint32_t  sys_evt	)	
    

    anywhere? WIthout that, no events are dispatched to the fstorage system so it won't do anything.

  • yeah - I don't think it does tell you that anywhere in the FDS documentation.

    One standard thing you get to 'know' in the Nordic SDK code is that almost every one of their modules needs to be fed with events, either system events or BTLE events. eg all the BTLE services need BTLE events, anything dealing with Flash needs system events (which are the flash read/write completion raw events). So there's almost always somewhere you have to hook that into your event loop.

    Of course FDS is an exception, because it relies on fstorage which has its own callbacks.

    I long-ago wrapped all this stuff in C++ and a generic event dispatcher so that all the modules I use register themselves at creation time, because I got sick of forgetting to do it!

Reply
  • yeah - I don't think it does tell you that anywhere in the FDS documentation.

    One standard thing you get to 'know' in the Nordic SDK code is that almost every one of their modules needs to be fed with events, either system events or BTLE events. eg all the BTLE services need BTLE events, anything dealing with Flash needs system events (which are the flash read/write completion raw events). So there's almost always somewhere you have to hook that into your event loop.

    Of course FDS is an exception, because it relies on fstorage which has its own callbacks.

    I long-ago wrapped all this stuff in C++ and a generic event dispatcher so that all the modules I use register themselves at creation time, because I got sick of forgetting to do it!

Children
No Data
Related