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

[Persistent Storage Manager] Two application data storage mapped on same flash page

Hello

I'm using a pstorage_register from pstorage.c to register two application storage blocks in flash memory. But I have situation that first module have 6 blocks of 256B of data, which gives one and the half page of memory. The second module have only (at this moment) 2 blocks of 16B of data. Now, when I write (also checked in debuger) first block of second module, data are written on fifth block of first data module.

I do some debug and I nottice that second data module starts on next flash page to first flash page of first data module. This flash page should be occupied by blocks 5 i 6 of first data module.

In other words I got:

  1. 1st data module: 6 block x 256B = 1flash page (1024) + 0.5 flash page (512) -> (from debuger base addres of module is: 0x3f400 and it goes to last block: 0x3f900 )
  2. 2nd data module: 2 block x 16B = 1flash page (26B) -> from debuger I see that it gets address of next flash page: 0x3f800 which is occupied by 5th block previous data block

When I check pstorage_register function in pstorage.c I discovered that this fragment of code

    // Calculate number of flash pages allocated for the device.
page_count = 0;
total_size = p_module_param->block_size * p_module_param->block_count;
do
{
    page_count++;
    if (total_size > PSTORAGE_FLASH_PAGE_SIZE)
    {
        total_size -= PSTORAGE_FLASH_PAGE_SIZE;
    }
    else
    {
        total_size = 0;
    }
    m_next_page_addr += PSTORAGE_FLASH_PAGE_SIZE;
}
while (total_size >= PSTORAGE_FLASH_PAGE_SIZE);
m_app_table[m_next_app_instance].num_of_pages = page_count;

gives in this particular case page_cout equal 1 (flash_page) so next application data module gets same flash page which leads to data corruption.

Is this will be corrected? Can I somehow bypass elegantly this issue?

Parents Reply Children
No Data
Related