I am using Spansion's flash memory of 16MB. The sector size is 256KB. I am using the flash to read/write/delete 30 byte blocks(structures). I have found in the data sheet of the IC that minimum erasable size is 256KB. One way of deleting a particular block is to
I want to ask is there any better alternative logic to this.
There is no way to erase less than the minimum erasable sector size in flash.
However, there is a typical way to handle invalidating small structures on a large flash sector. Simply add a header to indicate the state of the data in that structure location.
Simple example:
0xffff
Structure is erased and available for use.0xa5a5
Structure contains data that is valid.0x0000
Structure contains data that is not valid.The header will be 0xffff
after erasing. When writing new data to a structure, set the header to 0xa5a5
. When that data is no longer needed, set the header to 0x0000
.
The data won't actually be erased, but it can be detected as invalid. This allows you to wait until the sector is full and then clean up the invalid records and perhaps compact the valid ones.