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

pstorage guide

HI,everyone!

I want to use pstorage to store some data, so I followed the steps given by devzone.nordicsemi.com/.../, but it didn't work. Then I checked ecah function and found out the

pstorage_register (&p_example_param, &m_p_example_id)

return NRF_ERROR_NULL,and I can't find out where the problems come from.

Can someone point out the problem or give me an example for pstorage use?

Thank you very much!

  • Are you using device manager along with your test psorage? You shouldn't initialize pstorage_init twice if you call example_pstorage_init after device manager init. Or you need to increase maximum number of applications PSTORAGE_MAX_APPLICATIONS in pstorage_platform.h.

    UPD:

    You can read more about pstorage here.

    There is a pstorage example code here

    Example handler:

    // Event Notification Handler.
    static void example_cb_handler(pstorage_handle_t  * handle,
                                    uint8_t              op_code,
                                    uint32_t             result,
                                    uint8_t            * p_data,
                                    uint32_t             data_len)
    {
        switch(op_code)
        {
            case PSTORAGE_LOAD_OP_CODE:
               if (result == NRF_SUCCESS)
               {
                   // Store operation successful.
               }
               else
               {
                   // Store operation failed.
               }
               // Source memory can now be reused or freed.
               break;       
            case PSTORAGE_UPDATE_OP_CODE:
               if (result == NRF_SUCCESS)
               {
                   // Update operation successful.
               }
               else
               {
                   // Update operation failed.
               }
               break;
           case PSTORAGE_CLEAR_OP_CODE:
               if (result == NRF_SUCCESS)
               {
                   // Clear operation successful.
               }
               else
               {
                   // Clear operation failed.
               }
               break;
        }
    }
    
  • thank you for your fast reply!

    Firstly,I did not use the device manager and I am sure the pstorage just be init once. Secondly,I have tried to increase the PSTORAGE_MAX_APPLICATIONS but nothing changed.

    By the way, as the error NRF_ERROR_NULL means 'if NULL parameter has been passed', and I noticed the parameter m_p_example_id is just created without any initialization like this: static pstorage_handle_t m_p_example_id; will this be the problem? Thank you very much!

  • sorry,I make a mistake! the NRF_ERROR_NULL comes from the NULL_PARAM_CHECK(p_module_param->cb); and I noticed my code just creat a parametr like this:p_example_param.cb = example_cb_handler; But I did not instantiate it because I don't konw how to. Can you give me an example to instantiate the cb_handler? Thank you very much!

  • to instantiate a callback handler one would create a function that mtaches the type required. Specifically:

    static void example_cb_handler( pstorage_handle_t *p_handle, uint8_t op_code, uint32_t result, uint8_t p_data, uint32_t dat_len ) { / do something */ }

    "example_cb_handler", then, is a pointer to the function itself, which can then be assigned in a statement

    example_param.cb = example_cb_handler;

    Please look to generic c-coding guides for typedef creations of function pointers. Function pointers are extremely useful tools, and can be used to greatly simplify otherwise very complex code.

Related