What does the qspi erase put in memeory?


I have been workigg with the qspi erase function and it appears that is erases the memory section to have all 1’s in them vs erasing it to zero.

Is that correct?


Yes. That is correct. Expanded to >20 characters to satisfy the forum’s demand!

1 Like

That’s the nature of flash memory. Erasing flash memory puts every bit in its default state (set to 1) and writing to it changes some bits to 0. You can overwrite data without erasing it too, but that can only change values in individual bits from 1 to 0. Effectively you perform a binary AND operation between current value and what gets written.

This feature is quite convenient and can be exploited in some cases. I.e. OWL firmare includes a simple file system and it marks files as deleted by toggling just a single bit in file metadata instead of formatting multiple pages to physically erase it. Longer procedure to reclaim space from from deleted files only has to run when you’re out of space for writing new data.

Internal flash works the same way, but on newer chips (including STM32H7 on Daisy) internal flash is configured as ECC memory that knows checksum of currently written value. This means that overwriting internal flash with a different value will lead to a hardware exception.

1 Like

@antisvin ,
Thank you, that is very good to know.