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

PStorage behaviour changed from sdk v8 to v10

I used to store 10 bytes to flash with pstorage under sdk version 8.2 and it always worked fine. As I also use the mesh app, the timeslot_handler dispatches the pstorage events like this:

case NRF_EVT_FLASH_OPERATION_SUCCESS:
case NRF_EVT_FLASH_OPERATION_ERROR:            
	pstorage_sys_event_handler(evt);
	break;

Now I updated to sdk10 and the storage_callback_handler is no longer called for store, update and clear operations. Has there been a change in the pstorage api that I missed? This is the init and store code:

void storage_callback_handler(pstorage_handle_t  * handle,
                               uint8_t             op_code,
                               uint32_t            result,
                               uint8_t           * p_data,
                               uint32_t            data_len)
{
	m_result = result;
	SEGGER_RTT_printf(RTT_CHANNEL, "callback handler called\n");
	if(handle->block_id == pstorage_wait_handle) 
	{ 
		pstorage_wait_flag = 0; 
	} 
}

uint32_t localizer_storage_init(void) 
{
	pstorage_module_param_t param;
	uint32_t error_code = pstorage_init();
	if(error_code != NRF_SUCCESS)
	{
		return error_code;
	}
      
	param.block_size  = LOCALIZER_LEN;
	param.block_count = 1;
	param.cb          = storage_callback_handler;
    
	error_code = pstorage_register(&param, &m_localizerHandle);	
	if(error_code != NRF_SUCCESS)
	{
		return error_code;
	}
	return NRF_SUCCESS;
}

uint32_t localizer_store(void)
{
	uint32_t error_code;
	pstorage_handle_t block_handle;

	error_code = pstorage_block_identifier_get(&m_localizerHandle, 0, &block_handle);
	if (error_code == NRF_SUCCESS)
	{
		SEGGER_RTT_printf(RTT_CHANNEL, "localizer_store clear\n");
		pstorage_wait_handle = block_handle.block_id;            //Specify which pstorage handle to wait for
		pstorage_wait_flag = 1;                                    //Set the wait flag. Cleared in the example_cb_handler
		error_code = pstorage_clear(&block_handle, LOCALIZER_LEN);
		if (error_code != NRF_SUCCESS)
		{
			return error_code;
		}
		while(pstorage_wait_flag) 
		{ 
			app_sched_execute();
			sd_app_evt_wait();
		}   //Sleep until store operation is finished.
		SEGGER_RTT_printf(RTT_CHANNEL, "localizer_store ");
		for(int i=0; i<MAX_LOCVAL_LEN; i++) 
		{
			SEGGER_RTT_printf(RTT_CHANNEL, "%02x", m_localizer[i]);
		}
		SEGGER_RTT_printf(RTT_CHANNEL, "\n");

		pstorage_wait_handle = block_handle.block_id;            //Specify which pstorage handle to wait for
		pstorage_wait_flag = 1;                                    //Set the wait flag. Cleared in the example_cb_handler
		error_code = pstorage_store(&block_handle, (uint8_t *)&m_localizer, LOCALIZER_LEN, 0);
		if (error_code != NRF_SUCCESS)
		{
			return error_code;
		}
		while(pstorage_wait_flag) 
		{ 
			app_sched_execute();
			sd_app_evt_wait();
		}   //Sleep until store operation is finished.

		if (m_result != NRF_SUCCESS)
		{
			return m_result;
		}
	}
	return NRF_SUCCESS;
}
Parents
  • No, I read the migration stuff. This is the start of the module:

    #define LOCALIZER_LEN						16
    #define MAX_LOCVAL_LEN					10
    
    // storage of metadata
    static uint8_t 					pstorage_wait_flag = 0;
    static pstorage_block_t 				pstorage_wait_handle = 0;
    static pstorage_handle_t       			m_localizerHandle;
    static uint8_t						m_localizer[LOCALIZER_LEN];						
    static uint32_t					m_result;
    
    APP_TIMER_DEF(m_store_timer_id);	
    #define APP_TIMER_PRESCALER             0
    #define STORAGE_DELAY			        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER)
    

    I have no more ideas. With the storage clear command I already omitted the waiting on the callback and it clears somehow. But no callback as no event reaches my event loop. I'll try to pump up the pstorage module with printfs to see what happens...

Reply
  • No, I read the migration stuff. This is the start of the module:

    #define LOCALIZER_LEN						16
    #define MAX_LOCVAL_LEN					10
    
    // storage of metadata
    static uint8_t 					pstorage_wait_flag = 0;
    static pstorage_block_t 				pstorage_wait_handle = 0;
    static pstorage_handle_t       			m_localizerHandle;
    static uint8_t						m_localizer[LOCALIZER_LEN];						
    static uint32_t					m_result;
    
    APP_TIMER_DEF(m_store_timer_id);	
    #define APP_TIMER_PRESCALER             0
    #define STORAGE_DELAY			        APP_TIMER_TICKS(100, APP_TIMER_PRESCALER)
    

    I have no more ideas. With the storage clear command I already omitted the waiting on the callback and it clears somehow. But no callback as no event reaches my event loop. I'll try to pump up the pstorage module with printfs to see what happens...

Children
No Data
Related