cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F40xx - Need for erase before flash programming

florian23
Associate
Posted on February 13, 2014 at 09:33

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.
7 REPLIES 7
chen
Associate II
Posted on February 13, 2014 at 10:02

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.

trevor23
Associate III
Posted on February 13, 2014 at 11:10

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.

florian23
Associate
Posted on February 13, 2014 at 11:29

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.

Uwe Bonnes
Principal II
Posted on February 13, 2014 at 11:50

>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.

chen
Associate II
Posted on February 13, 2014 at 12:14

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.

Uwe Bonnes
Principal II
Posted on February 14, 2014 at 15:50

> 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 a

big

buffer...

No - I do not see anything about it either. I would take that as a NO there is no such functionality.

Posted on February 14, 2014 at 16:21

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.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..