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

fs_store event handler not being fired

I have a NRF52382 DK and cannot seem to get the fs_store callback to fire.

here is my fs_config callback function:

static uint8_t fs_callback_flag;
void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result){
    fs_callback_flag = 0;}

here is my storage write function is as follows:

FS_REGISTER_CFG(fs_config_t fs_config) =
{
	.callback  = fs_evt_handler, 							// Function for event callbacks.
	.num_pages = 8, 
	.p_start_addr = (uint32_t*)0x00030000,		// Start Address of Reserved Free Space
	.p_end_addr = (uint32_t*)0x00038000,
	.priority  = 0xFE            							// Priority for flash usage.
};

fs_ret_t init_ret = fs_init();

if(init_ret == FS_SUCCESS)
{
	fs_callback_flag = 1;
	fs_ret_t store_ret = fs_store(&fs_config, address, &data[0], data_length, fs_config.callback);
	if(store_ret == FS_SUCCESS)	
	{					
		while(fs_callback_flag == 1)  
		{ 
			power_manage(); 
		}
	}
}

I have set the sys event handlers inside the ble_stack_init as specified in some examples, i have found online.

static void sys_evt_dispatch(uint32_t sys_evt){
    ble_advertising_on_sys_evt(sys_evt);
    fs_sys_event_handler(sys_evt);}
   
 //This is at the bottom of ble_stack_init(void) function called on main startup...
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);

the fs_evt_handler function is never getting fired so, the code gets stuck in the while(fs_callback_flag == 1) {}

Any help would be much appreciated.

UPDATE: I have an application that acts as a central device, this application is based of the blinky example.

This central device listens for adverts from other peripheral devices and connects sending a payload of data and then disconnects and goes to sleep for a given period.

I have a new requirement where i can send data from the peripheral device to the central and then the central device will write this to flash storage.

i have a simple storage write function that registers the fs_config, calls fs_init() and then calls fs_store().

This works fine when calling it from in main(), the callback fs_evt_handler gets called and the data gets written perfectly to flash.

However I would like to perform a storage write after receiving data from a ble push notification event. the fs_store is successful but will break sometime later and the callback fs_evt_handler is never fired.

Related