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

pstorage store issue

HI,all!

I recently using pstorage to store data

and the pstorage_store(); funtion always returns NRF_SUCCESS, but never triggle the cb_handler, is that normal?

by the way, i just sucessfully store the data once and never success again.(the loaded data is 0xff)

Can someone points out the problems? Thank you very much!

here is my code:

void mypstorage_init(void)
{
	uint16_t block=0;
	uint8_t flash2[16]={16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
	uint16_t size=16;
	uint16_t offset=0;
	pstorage_handle_t p_block_id;	

	cb_init mycbinit;

	pstorage_module_param_t p_example_param;

	    // Setup pstorage with 60blocks of 16byte in each.
            p_example_param.block_size  = 0x10; // recommended to be >= 4 byte
            p_example_param.block_count = 60;//60
            p_example_param.cb          = mycbinit.example_cb_handler;
	pstorage_init();

	pstorage_register(&p_example_param, &m_p_example_id);

	pstorage_block_identifier_get(&m_p_example_id, block, &p_block_id);
	pstorage_store(&p_block_id,flash2,size,offset);
	
	pstorage_load(myflash2,&p_block_id,size,offset);

}

 typedef struct
{
      pstorage_ntf_cb_t   example_cb_handler;                   
} cb_init;

void example_cb_handler(pstorage_handle_t *  p_handle,
                              uint8_t              op_code,
                              uint32_t             result,
                              uint8_t *            p_data,
                              uint32_t             data_len)
  {
          ;
  }
Parents
  • pstorage_store(); funtion always returns NRF_SUCCESS, but never triggle the cb_handler, is that normal?

    You need to init pstorage callback like this:

    void mypstorage_init(void)
    {
    ...
                p_example_param.cb          = example_cb_handler;
        pstorage_init();
    ...
    
    void example_cb_handler(pstorage_handle_t *  p_handle,
                                  uint8_t              op_code,
                                  uint32_t             result,
                                  uint8_t *            p_data,
                                  uint32_t             data_len)
    {
            ;
    }
    

    by the way, i just sucessfully store the data once and never success again.(the loaded data is 0xff)

    You are doing it wrong, if you do it like this:

    pstorage_store(&p_block_id,flash2,size,offset);
    pstorage_load(myflash2,&p_block_id,size,offset);
    

    Then when you call pstorage_store you just send request to store your data to pstorage and when this function will return with NRF_SUCCESS your data won't be stored in flash yet. It will be stored after a while and then pstorage will report this in callback example_cb_handler. And only after this you can try to load this stored data.

    Read this.

    UPD:

    What do you mean by running out of control?

    For the proper pstorage functioning you need to set sys events handler like this:

    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        pstorage_sys_event_handler(sys_evt);
    }
    
    static void ble_stack_init(void)
    {
    ...
        // Register with the SoftDevice handler module for SYS events.
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    }
    
  • I tried use the original example project "ble_app_template" and try again, and I successfully get into the cb_handler and load the data successfully, I think it might just because I modified the schedluer or something else in my project to cause the problem. Thank you very much!

Reply Children
No Data
Related