This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What does PSTORAGE_LOAD_OP_CODE mean?

What exactly does the PSTORAGE_LOAD_OP_CODE (0x03) mean? The documentation says (online) that it is an "Error when Load Operation was requested".

The code is pretty straightforward: storage.cpp

Is there something specific to the S130 device that it doesn't work perhaps? This is my pstorage_platform.h file.

If I can debug this somehow, that would be great!

  • When you call pstorage_register, you provide a callback function. This function is invoked when storage operations complete (see pstorage_ntf_cb_t in pstorage.h). The various OP_CODE macro constants, including PSTORAGE_LOAD_OP_CODE, are passed back in the op_code (second) parameter to your callback. Saying it's an "Error" is a bit confusing, since it's just the type of operation that completed, and you get the call back on success too; the result (third) callback parameter holds the error code and it will be NRF_SUCCESS on success.

    pstorage_load is somewhat of a special case among the storage operations in that it isn't put into the operation queue like stores and erases are; instead under the covers it's just a memcpy and it always succeeds. It's useful to know this in case you were relying on queuing for ordering. For example, if you:

    • Erase memory at, say, 0x3FC00 to 0x3FFFF.
    • Write "ABCD" at 0x3FC00.
    • Read back memory at 0x3FC00 with pstorage_load,

    then it's likely that your pstorage_load will return before your write has completed, returning old data.

    On edit: Having taken a look at your code, (1) your callback should check for result != NRF_SUCCESS before alerting on an error, and (2) note that pstorage_store expects the given data buffer to persist until you get a callback; from pstorage.h:

     * @warning    No copy of the data is made, and hence memory provided for data source to be written
     *             to flash cannot be freed or reused by the application until this procedure
     *             is complete. End of this procedure is notified to the application using the
     *             notification callback registered by the application.
    

    Your test variable will of course go out of scope when you return from the init function.

  • This is a bit of a guess on my part, but I think the PSTORAGE_LOAD_OP_CODE is not an error. I suspect it is just telling you a load operation has completed. I think you have to look at the result passed back to see if it is NRF_SUCCESS or not to know if the operation succeeded or not. At least that is how my pstorage callback handler is structured. I stole it blatantly from a Nordic pstorage example.

  • Nice. I see now the number of pending operations go up indeed on pstorage_store. I don't know if I should ask a separate question for this, but it seems also pstorage_sys_event_handler is required to be called from sys_evt_dispatch which is called from softdevice_sys_evt_handler_set. Does pstorage indeed depend on the softdevice?

    Moreover in pstorage.c it states:

    // Its possible the flash access was not initiated by bond manager, hence                                           
    // event is processed only if the event triggered was for an operation requested by the                             
    // bond manager.            
    

    What does this mean?

    Never mind, from devzone.nordicsemi.com/.../a00018.html I understand that this is indeed the case.

Related