Flash API

In the flash API the function “NAFlashWrite(WORD32 sectorNumber, WORD32 sectorOffset, WORD32 bytesToWrite, char * buffer, char options);” has option for ERASE_AS_NEEDED as below. How is the partial writing of a sector performed? The sector has to be completely erased, no? Is the remaining data stored in dram and then rewritten together with the new data? What if there is a powerfail exactly in the moment the data is stored in dram and the flash is erased? Everthing is lost? — ERASE_AS_NEEDED - For a full sector write, erases the sector (if necessary) and writes the new data. For a partial sector write, updates the new data but does not destroy the rest of the sector data.

You are correct. The sector is stored in ram, erased, and then rewritten. You actually have the source code for all these routines (naflash.c) so if you want to change it you can. If you get a powerloss after it has been erased, but before it has been rewritten, the data is lost. Note that the ram area where the sector is stored is not dynamically allocated, it is static, so if you have any memory with battery backup you could link the area to this ram and your could recover the data and write it to flash again.