Fatfs operating with NOR flash: default values for clearing data are set to 0 instead of 0xFF

Hello,

I’m using FatFs plus (Lab), and the default value to put in this library is 0 (RAM oriatation) , not 0xFF (FLASH oriatation) , which is the default value when erasing FLASH. see example of FLASH memory below .

In my case, the basic size of writing block of data use by fatfs is set to the flash is 512 bytes.(in my case)

Normally, fatfs uses the FatFs writing API. (e.g., prvFFWrite()).

Option 1: (default “clear/erase” value is set to 0xFF)
To just write data to the flash without erasing the sector content (in this case, 4K for W25W32 windbond), set the default value to 0xFF. Then writing for Flash will be successful.

Option 2 :
If an erase is necessary and pre-writing procedures are performed, the sector must be read into RAM (4K) , modified the content (512 bytes copy to 4K in the desired address ) , erased the sector (4K) , and then written back (4K) to the flash.
This will be complicated if FATFS’s data writing exceeds the sector size. on this case we need to separte the writing to 2 chunk of data and do then same above procedure for 2 sector .

Option 3:
Increase the baseline fatfs writing block size to 4K (from 512 bytes). This will require a large amount of RAM memory to operate the pool of blocks for the fatfs.

So, the simple question is, can I avoid this by setting the fatfs default value to 0xFF rather
than 0?

note:
Here is how a normal flash memory is seen (before making any changes).
All of the highlighted areas in RED needed to be set to 0xFF.

Note: Option 1 will not always work if we try to write on the same area numerous times - thus it is advisable to use option -1 as the first step - then if comparing writing to read fails - then use option 3.

Thank you, William.

Hi @wshany1234
You cannot avoid the issue you mentioned by setting the FatFs default value to 0xFF.
NOR Flash requires erase before write. You can only change bits from 1 → 0,
but not from 0 → 1 unless you erase the sector first.