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

keeping data in flash on fixed address

Hi,

with the pstorage library, is it possible to store data at a specific flash address? The background of the question is that I would like to store data in flash, and be able to access it again after a power cycle, e.g. when the batteries need to be replaced.

Also, I would like to keep the data even if a software update is done via the DFU boot loader.

How is that done?

Wim

Parents
  • Hi Wim

    This thread tells something about where data is actually stored in flash when using pstorage. Another option is to use pstorage in RAW mode where you write directly to addresses in the memory space.

    If you use bootloader, you need to configure the bootloader so it does not overwrite any application data stored in flash. The application data space is reserved with modifying the constant DFU_APP_DATA_RESERVED in dfu.types.h

  • Hi Wim

    If you are not using the device manager and only need one page for application data, I think you need to set

    #define DFU_APP_DATA_RESERVED 0x0800 
    

    in order to reserve one page for the swap page and one page for the application data. If you would need two pages, you should set

    #define DFU_APP_DATA_RESERVED 0x0C00
    

    in order to reserve one page for the swap page and two pages for the application data

    In the code snippet shown here, the identifier of block number 2 is returned, hence the number "2" as the second parameter in pstorage_block_identifier_get. The first block is number 0 and will have the address of the start of the page. Block number 1 will have the address start_of_page + 1, Block number 2 will have the address start_of_page + 2, etc.

    There is also a code example available here

Reply
  • Hi Wim

    If you are not using the device manager and only need one page for application data, I think you need to set

    #define DFU_APP_DATA_RESERVED 0x0800 
    

    in order to reserve one page for the swap page and one page for the application data. If you would need two pages, you should set

    #define DFU_APP_DATA_RESERVED 0x0C00
    

    in order to reserve one page for the swap page and two pages for the application data

    In the code snippet shown here, the identifier of block number 2 is returned, hence the number "2" as the second parameter in pstorage_block_identifier_get. The first block is number 0 and will have the address of the start of the page. Block number 1 will have the address start_of_page + 1, Block number 2 will have the address start_of_page + 2, etc.

    There is also a code example available here

Children
No Data
Related