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

Retrieve saved info on restard with pstorage module

Hello,

I need to store some app configuration on the FLASH and I'd like to use the features of pstorage module. I don't understand the following thing ...

When the application starts, it uses the pstorage_register (after the pstorage_init of course) to register itself to the pstorage module and then uses it with load and store feature. On restart I can't read what I stored on the previous execution. How for each reboot of application the pstorage knows what's my app FLASH area with my saved info ? I can't find this information ...

Thanks. Paolo.

rgr_cfg.c rgr_cfg.h

  • Hi ppatierno,

    I am sure this question has been asked many times here, but I will try to answer you. pstorage_register will reserve flash page(s) and the flash page number it reserves depend on the the settings in pstorage_platform.h and the sequence of pstorage_register.

    For exampleyou code has something like this:

    pstorage_init
    .....
    .....
    pstorage_register two pages --> returns block_id1
    ......
    ......
    pstorage_register three pages -->return block_id2
    

    If the sequence of these two register function never changes over system reboots then they will always register the same physical flash page numbers, the block_id1 and block_id2 have same physical address mapping in this case and you can safely write and read your information over reboots.

    but if pstorage_register is done depending on some state machine after reboot, and if the order changes like this after reset

    pstorage_init
    .....
    .....
    pstorage_register three pages -->return block_id2
    ......
    ......
    pstorage_register two pages  --> returns block_id1
    

    Then the block_id to physical address mapping has changed and you wont find the information you stored at the block_id you registered before this reboot.

  • How do you check that your data is actually is stored?

  • The pstorage is initialize by the device manager module (I started from ANCS BLE example).

    My current code does following ...

    Registers to pstorage :

    pstorage_register(&param, &m_storage_handle);
    

    get the block identifier :

    pstorage_block_identifier_get(&m_storage_handle, 0, &block_handle);
    

    After, I read from this block to check if there is a pattern of data (it's my way to check if I already wrote first configuration on the first device startup). I need to read first 2 bytes at start of the block (offset 0).

    pstorage_load(data, &block_handle, 2, 0);
    

    Then I compare "data" with a pattern I know and if they are different I store the pattern in the first two bytes :

    pstorage_store(&block_handle, pattern, sizeof(pattern), 0);
    

    On reboot I'd like to have that the code read the first 2 bytes of the block and verifiy that the pattern is there ... but it doesn't happen !

  • Just to add that all pstorage calls return 0 (so NRF_SUCCESS) and the same is in the callback called after the pstorage_store.

  • debug it and see if block_handle->block_id which should be the physical address of the block is the same for both load and store.

Related