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

pstorage handle never called

Hello everybody,

I'm trying to use pstorage module but it seems that the example_cb_handler function is never called when I try to store data.

I noticed similar issues in the forum and read pstorage documentation but It still doesn't work...

static void example_cb_handler(pstorage_handle_t  * handle,
				               uint8_t              op_code,
                               uint32_t             result,
                               uint8_t            * p_data,
                               uint32_t             data_len)
{
	
		nrf_gpio_pin_set(LED_4);    				// Clear Led if example_cb_handler called 
		if(handle->block_id == pstorage_wait_handle) { pstorage_wait_flag = 0; }  //If we are waiting for this callback, clear the wait flag.
}
static void pstorage_test_store_and_update(uint8_t*dest_data_0)
{
		pstorage_handle_t       handle;
		pstorage_handle_t	    block_0_handle;
		pstorage_module_param_t param;
	
		uint8_t                 source_data_0[16] = {0x00, 0x01, 0x31, 0x20, 0x22, 0x05, 0x06, 0x21, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
		uint32_t                retval;
 	
		retval = pstorage_init();
		if(retval != NRF_SUCCESS)
		{
			nrf_gpio_pin_set(LED_4);  
		}
		
		param.block_size  = 16;                   //Select block size of 16 bytes
		param.block_count = 10;                   //Select 10 blocks, total of 160 bytes
		param.cb          = example_cb_handler;   //Set the pstorage callback handler
			
		retval = pstorage_register(&param, &handle);
		if(retval != NRF_SUCCESS)
		{
			nrf_gpio_pin_set(LED_4);  
		}
	
		pstorage_block_identifier_get(&handle, 0, &block_0_handle);	

		pstorage_wait_handle = block_0_handle.block_id;            //Specify which pstorage handle to wait for 
		pstorage_wait_flag = 1;   
		pstorage_store(&block_0_handle, source_data_0, 16, 0);     //Write to flash, only one block is allowed for each pstorage_store command
		while(pstorage_wait_flag) { power_manage(); }   

		pstorage_load(dest_data_0, &block_0_handle, 16, 0);				 //Read from flash, only one block is allowed for each pstorage_load command
}

int main(void)
{
		uint8_t dest_data_0[16];
            . . .
		pstorage_test_store_and_update(dest_data_0);
		
    for (;;)
    { 
		power_manage();
		ble_attempt_to_send(dest_data_0, 16);
    }
}

I didn't forget to do this part :

static void sys_evt_dispatch(uint32_t sys_evt)
{
    pstorage_sys_event_handler(sys_evt);
}

static void ble_stack_init(void)
{
    uint32_t err_code;
    
    // Initialize SoftDevice.
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, false);

    // Enable BLE stack 
    ble_enable_params_t ble_enable_params;
    memset(&ble_enable_params, 0, sizeof(ble_enable_params));
    ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
    err_code = sd_ble_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);
    
    // Subscribe for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);
	
		// Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
		
} 

My Led is never off so I assume the handle function is never called when I store the data to the flash... I'd be really grateful is somebody can help me !

Regards, Damien

Parents
  • Hello!

    When I initialize my led I turn it on, "nrf_gpio_pin_set(LED_4);" turn my led off, So my led turn off when pstorage failed to initialize or when the handler is called successfully, both of those events never happens.

    Like you Kyu, pstorage_load function call the handler but not pstorage_store... I need the handler call to be sure that the store operation is done...

Reply
  • Hello!

    When I initialize my led I turn it on, "nrf_gpio_pin_set(LED_4);" turn my led off, So my led turn off when pstorage failed to initialize or when the handler is called successfully, both of those events never happens.

    Like you Kyu, pstorage_load function call the handler but not pstorage_store... I need the handler call to be sure that the store operation is done...

Children
No Data
Related