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

How to understand Pstorage

I'm confused. in other platform, i know flash stard and end adress ,alse page size ,i can read and write data directly. But use pstorage mode as follows : pstorage_init() ->pstorage_register()->read (for use)-> write(for persistenct storage)

Firstly, my code works correctly. But I can't understand,when power restart , code runs the same procedure(pstorage_init() ->pstorage_register()->read (for use)-> write(for persistenct storage)) 1.why i can read correctly? It allocates the same blocks as code runs last time ? 2.Once allocated,is there something to mark it ?

  • Hello Linxi

    The pstorage employs two areas in flash, a swap area for temporary storage of data and the flash area used for persistant storage. The swap area is one page at the end of the flash code memory (except when a bootloader is used), and is used when blocks of data are cleared and updated.

    The flash storage area is further down in flash and its size and location is defined in the pstorage_platform.h file. The size of flash and page size is defined in the memory sections of the product specifications for the chips. As an example nRF51822 has 256 kB of code flash, where each page is 1024 bytes, resulting in 256 pages.

    When a user of pstorage registers, memory is allocated to it. Whoever registers first gets the lower address in flash. This is why you read the correct values after a restart. There are no flags to mark the used flash, but since the code executes the same sequence every time, the users of pstorage registers in the same order and you always end up at the same blocks in flash.

    For more information on pstorage, see the following link infocenter.nordicsemi.com/.../lib_pstorage.html

    Best regards

    Jørn Frøysa

Related