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

Store Data without Soft Device

I have to store some data in the flash. Because I need to keep data when I power off and power on the device. Now I found on the SDK 11.0/peripheral a falshwrite example. Is this for application which needs to store data, but dont use softdevice?

I know for pstorage. But I'm not sure, if I can use pstorage without softdevice.

  • pg_size and page_num in the example is read from Factory information configuration registers (FICR). This is read-only information stored in the chip. The values will vary, depending on which chip you have. CODEPAGESIZE * CODESIZE will correspond to the total flash size in kB. On nRF52832, CODEPAGESIZE is 4096 and CODESIZE is 128, totaling 512kB flash. On nRF51 series, CODEPAGESIZE is 1024, while CODESIZE is 128 or 256 depending on your IC revison. You can store 4096 uint8_t values in on page on the nRF52832. Read from flash is shown in the example. You simply get the value by reading the data using the address. After power-up you need to read the the data from the flash-address. You must hardcode into your application which address to read on powerup.

  • okei I see. Than I have to change only the codesize. as example, value_1 is CODESIZE-1 and then value_2 is CODESIZE-2 and so on. If I understand that right. And how do I change between the pages? Or how do I choose pages?

  • I would recommend that you use a similar method to what is used in the flashwrite example:

    • Select a free location in memory to store your data. In example, last page is selected.
    • Calculate start address - addr = (uint32_t *)(pg_size * pg_num);
    • Increase the address for each write

    You do not have to "change pages", when you have filled one page, your address will point at the next page in flash.

Related