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

how can I specify the order of pstorage_register

I'm registering two p_storage modules, one allocates 3 blocks of 16 bytes (so one page to my understanding) and the other one 512kb ( 5 pages).

to my understanding,if I callpstorage_register with param_1 first, then I call pstorage_register with param2, pages allocated for param_1 are allocated before pages reserved for param_2 (before means they are closer to bootlader pages). butg I can see in flash memory dump that param_2 pages are located just above the bootlooder, then pages of param_1.

how can I specify that it's param_1 which should be located just above the bootloader. I need this configuration to keep the data of param_1 after performing dfu with minimal setting ofDFU_APP_DATA_RESERVED (no need to save pages of param_2 after DFU).

static void flash_init()
{
    uint32_t                    err_code;
    pstorage_module_param_t     param_1;
    pstorage_module_param_t     param_2;

    param_1.block_size    = 16;
    param_1.block_count   = 3;
    param_1.cb            = flash_callback_handler;

   // 5ko
    param_2.block_size    = 256; 
    param_2.block_count   = 20
    param_2.cb            = flash_callback_handler;

    err_code = pstorage_init();
    APP_ERROR_CHECK(err_code);

    // allocate storage blocks for data
    err_code = pstorage_register(&param_1, flash1_handler);
    APP_ERROR_CHECK(err_code);

    err_code = pstorage_register(&param_2, &flash2_handler);
    APP_ERROR_CHECK(err_code);
}
Parents
  • Pstorage allocates flash pages below the bootloader start address. First page below is the swap page, and cannot be used to store application data. So the 2nd flash page is the closest "app data" page to the bootlaoder that can be used. In other words, you need to reserve at least two pages to preserve the app data through DFU.

    To store the param_1 data in the 2nd page below the bootloader you need to change to order of the pstorage register from:

    err_code = pstorage_register(&param_1, flash1_handler);
    APP_ERROR_CHECK(err_code);
    
    err_code = pstorage_register(&param_2, &flash2_handler);
    APP_ERROR_CHECK(err_code);
    

    to:

    err_code = pstorage_register(&param_2, &flash2_handler);
    APP_ERROR_CHECK(err_code);
    
    err_code = pstorage_register(&param_1, flash1_handler);
    APP_ERROR_CHECK(err_code);
    
  • the swap page is used by pstorage for updating blocks within the flash page, but will be erased as soon as a new update task is issued, more details on swap usage can be found in the documentation I linked to in my comment above.

Reply Children
No Data
Related