2014-02-13 12:33 AM
Is there a need to erase a sector of the internal flash memory of STM32F40xx-Devices before writing new data to that sector?
I couldn't find a hint in PM0081. The flash_program example of STM32F4xx_DSP_StdPeriph_Lib_V1.3.0 does so, but is there a need for it? I want to implement a read-modify-write operation an if it is not possible, I couldn't do so on 128kB Sectors.2014-02-13 01:02 AM
Hi
''Is there a need to erase a sector of the internal flash memory of STM32F40xx-Devices before writing new data to that sector?'' The simple answer is Yes. ''I want to implement a read-modify-write operation'' The way Flash works is that the erase operation sets all the bits to 1s. Once the bit in Flash is set to 0 it cannot be set back to 1 unless the whole sector goes through the erase cycle. So you can 'write' multiple times into Flash but once a bit gets set to 0 it cannot be set to 1 with a normal write operation.2014-02-13 02:10 AM
I see this type of question a lot and just wanted to make it clear that this is how all flash works i.e. it must be erased in full sectors at a time. This is not just some awkward limitation of STM32 flash.
2014-02-13 02:29 AM
I'm aware of low level flash programming process.
But I was wondering if there is some functionality in the memory interface, that handles read-modify-write access e.g. to buffer the sector, modify it an then write the whole sector to flash.2014-02-13 02:50 AM
>Is there a need to erase a sector of the internal flash memory of
> STM32F40xx-Devices before writing new data to that sector? If the flash data before write has the erased value ''FF'' you can write without erase. If the data you want to write it the complement of the erased value, so if you want to write ''00'', you can write without erase. If you write non-zero data to already programmed memory, the write will fail, so sector erase is needed.2014-02-13 03:14 AM
Hi
''I'm aware of low level flash programming process. But I was wondering if there is some functionality in the memory interface, that handles read-modify-write access e.g. to buffer the sector, modify it an then write the whole sector to flash.'' What does the reference manual say?? No - I do not see anything about it either. I would take that as a NO there is no such functionality.2014-02-14 06:50 AM
> But I was wondering if there is some functionality in the memory > interface, that handles read-modify-write access e.g. to buffer the > sector, modify it an then write the whole sector to flash.''
Flash sector size of the F2 and F4 is up to 128 kiB. That would require abig
buffer... No - I do not see anything about it either. I would take that as a NO there is no such functionality.2014-02-14 07:21 AM
Like most flash devices you have to manage the ''deblocking'' issue yourself. The larger the block the less manageable this becomes.
The general method would be to journal rather than read-modify-write, ie you index through your own structures and add new material to the end, and when reading to navigate to the end of the list, and if you run out of erased space you move to another block, or erase the current block and start over.