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

FDS event handler is not occur.

Hi,

I am developing using nRF52820 / SDK 17.0.2

In order to store data in FDS, the handlers were registered and initialized as follows.

void BLE_Init(void)
{		
	ble_stack_init();
	gap_params_init();
	gatt_init();
	advertising_init();
	services_init();
	conn_params_init();
	peer_manager_init();
	
	return;
}

static void FDS_Event_handler( fds_evt_t const * p_evt )
{
	SEGGER_RTT_printf(0, "FDS_Event_handler id : %d / result : %d\n", p_evt->id, p_evt->result);
    switch (p_evt->id)
    {
        case FDS_EVT_INIT:
		case FDS_EVT_GC:
		case FDS_EVT_WRITE:
		case FDS_EVT_DEL_RECORD:
		case FDS_EVT_UPDATE:
        break;
    }
}

int main( void )
{
	fds_record_desc_t desc = {0};
	fds_find_token_t  tok  = {0};
	fds_record_t RecordData;

	RecordData.file_id = DATA_FILE_ID;
	RecordData.key = DEFAULT_RKEY;
	RecordData.data.p_data = pData;
	RecordData.data.length_words = DATA_FILE_SIZE;
	
    .....
    BLE_Init();
    fds_register(FDS_Event_handler); 
    
    .....
    
    if( fds_record_find( RecordData.file_id, RecordData.key, &desc, &tok ) == NRF_SUCCESS )
	{		
		if( fds_record_update( &desc, &RecordData ) == FDS_ERR_NO_SPACE_IN_FLASH )
		{			
			fds_gc();					// run garbage collection
			fds_record_update ( &desc, &RecordData );			
		}
	}
    .....
}

FDS_Event_handler does not occur after fds_record_update().

Why the event is not occurring?

An event occurs when garbage collection is executed, but an event does not occur when FDS update.

And how can I check that the update is completed in queue process after the update?

I would like to know that the FDS update is complete without using a event handler if possible.

Parents Reply Children
  • I initialize the peer manager as in the example code.
    It was confirmed that pds_init() was called in pm_init().

    So, fds_init() was not executed again, and only event handlers were registered.

    ret_code_t pds_init()
    {
        ret_code_t ret;
    
        // Check for re-initialization if debugging.
        NRF_PM_DEBUG_CHECK(!m_module_initialized);
    
        ret = fds_register(fds_evt_handler);
        if (ret != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("Could not initialize flash storage. fds_register() returned 0x%x.", ret);
            return NRF_ERROR_INTERNAL;
        }
    
        ret = fds_init();
        if (ret != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("Could not initialize flash storage. fds_init() returned 0x%x.", ret);
            return NRF_ERROR_STORAGE_FULL;
        }
    
        peer_id_init();
        peer_ids_load();
    
        m_module_initialized = true;
    
        return NRF_SUCCESS;
    }

  • Hi,

    Any chance you could upload a minimal version of your project here so I can try to debug it? I don't see any obvious problems in the code you have posted.

    A suggestion if you want to try debug this yourself is to place a breakpoint inside nrf_sdh_soc.c::nrf_sdh_soc_evts_poll() after sd_evt_get() to check if you receive any Softdevice flash events at all.

  • Hi.

    Sorry for the late reply

    I tested it as you told me.

    Softdevice event did not occur after FDS update was executed.

    00> BLE_GAP_EVT_CONNECTED
    00> PM_EVT_(0x05) 
    00> PM_EVT_CONN_SEC_START
    00> PM_EVT_(0x05) 
    00> PM_EVT_CONN_SEC_SUCCEEDED
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> Start FDS update

    I run an FDS update to store the Peer ID in FDS after pairing.

    But the FDS event handler(fds_evt_handler) I added doesn't executed.

    Is it because of the peer manager?

  • You should register all FDS users before fds_init() is called from pm_init(), but I don't think that is related to the problem. From the snippet you posted I noticed that you are not doing any error checks. Can you check if fds_record_update() is being called, and if it is returning an error code or not?

  • This is the log that added the FDS update error code.

    00> 
    00> BLE_GAP_EVT_CONNECTED
    00> PM_EVT_(0x05) 
    00> PM_EVT_CONN_SEC_START
    00> PM_EVT_(0x05) 
    00> PM_EVT_CONN_SEC_SUCCEEDED
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> FDS_Event_handler occurred. ID : 0x1, Result : 0x0
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> FDS_Event_handler occurred. ID : 0x1, Result : 0x0
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> FDS_Event_handler occurred. ID : 0x1, Result : 0x0
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> SoC event: 0x2.
    00> PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    00> FDS_Event_handler occurred. ID : 0x1, Result : 0x0
    00> Start FDS update
    00> record update error code : 0x0

    FDS update is executed even at boot time, but in that case, FDS handler occurs normally.

Related