Using Reserved virtual page space for storing very critical value which needs to be saved for a very long time.

Value can only be changed on characteristics write. Every time a new value has to be written to the critical component , I first erase the page and then write on that page.

/** Erase the page and then write to the reserved flash**/
ret_code_t ret = nrf_fstorage_erase(&reserve_fs,write_address,1,NULL);
return nrf_fstorage_write(&reserve_fs, write_address, page_tag_data1, 4 * sizeof(uint32_t), NULL);

This is the code snippet.

Is there a possibility that this method breaks at some point.

I am also doing GC(garbage collection) on the rest of the pages, can gc be done on this page as well.

Parents Reply Children
  • Just to add on the failure mode. We have seen FDS page getting marked as "UNDEFINED" header and the data was present on the half page and wiped out on other half.

    Is this behavior normal, because we have replicated several times and seen it.

  • Not sure I fully understand, but if you want to reserve flash pages between FDS and bootloader for your own usage (and have it untouched by FDS module), the look into using this define from sdk_config.h:

    // <o> FDS_VIRTUAL_PAGES_RESERVED - The number of virtual flash pages that are used by other modules.
    // <i> FDS module stores its data in the last pages of the flash memory.
    // <i> By setting this value, you can move flash end address used by the FDS.
    // <i> As a result the reserved space can be used by other modules.

    #ifndef FDS_VIRTUAL_PAGES_RESERVED
    #define FDS_VIRTUAL_PAGES_RESERVED 0
    #endif

  • That's correct Kenneth, I have used same reserved section and wrote on the address pointed to this page. But is the erase or write a blocking function and do we have to wait for them to finish of their tasks.

  • The CPU wil be totally blocked while erase and write operations occur, so any interrupts and code executing will be halted until the flash operation completes. Though have in mind that the flash operation will be scheduled by the softdevice, so it does not happen immediately when the flash api is called.

    Kenneth

  • Thanks Kenneth. 

    Does this mean that the function call nrf_fstorage_erase is fully blocking, i.e. we dont have to wait for the callback event registered during NRF_FSTORAGE_DEF(nrf_fstorage_t reserve_fs)?

    I ask this so that we can avoid doing any other transactions till the callback signifying end of erase page is recieved.

    Another issue that we have seen during further debug is that when GC is getting interrupted during supply glitch, we are seeing that only the first 1024 words are getting erased in a page (whose size is 2048 words). For example if the page 0x60000 - 0x62000 was interrupted during erase, we see that all words between 0x60000-0x61000  are 0xFFFFFFFF, whereas 0x61000-0x62000 still has its original data. This behavior is very consistent in the way that every single corrupted page is erased only midway. Is this expected behavior? Does this also mean that if we keep FDS_PAGE_SIZE as 1024 words we will be able to avoid page corruption?


    Request your urgent assistance on these questions as we have had to keep the production on hold and are unsure of the fix we have implemented.

    Best,

    Gaurav

Related