- Sun May 24, 2015 12:02 am
#18286
Write operations on the (NOR) flash memory can only toggle bits from 1 to 0. To get a bit back to 1, you need to perform an erase operation. An erase can only be performed on an entire memory block (at least 4KB), so when you want to write repeatedly to the same memory location, you always need to erase the entire block first.
What you could do to work around this limitation is to write new data to a new memory location after the old one, until the sector is full. To find your data, you can write a fixed marker (any int with at least a few 0 bits) before your data. At startup you would read the entire sector to find the last occurence of that marker and safe a pointer to that location (which will point to your most recent data).
This obviously adds quite a bit of complexity to your code, which only pays of, when you write new data quite frequently. The Winbond W25Qxx flash modules most commonly used are rated for 100,000 erase/write cycles, so if you erase a sector every 30 minutes, your flash should still be good for about 5 years.