cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Flash rewrite variables

cool26happy
Associate II
Posted on October 22, 2014 at 13:35

Hello.

I use STM32F4 and CoIDE. I use Flash sector 11 (because problem with linker when use sector 2) for store application parameters.

I write code...

FLASH_Unlock();

FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);

FLASH_EraseSector(FLASH_Sector_11, VoltageRange_3);

FLASH_ProgramWord(0x080E0000, 12);

FLASH_Lock();

But, this is work only first time (after sector erase).

How to rewrite variable without sector erase?

Best regards,

Cool Happy

#stm32f #rewrite #flash #eeprom
4 REPLIES 4
frankmeyer9
Associate II
Posted on October 22, 2014 at 14:07

But, this is work only first time (after sector erase).

 

How to rewrite variable without sector erase?

 

You can't. Flash is designed to be only sector-erasable.

Either use external EEPROM chips, which are byte/word erasable, or use an algorithm to work around your problem. For instance, write consecutive blocks/datasets, and use two Flash sectors in ping-pong mode.

But keep in mind, the number of guaranteed erase/write cycles of Flash is limited.

Posted on October 22, 2014 at 14:11

According to RM0090 rev.7, ch.3.6.4 on p.86:

Successive write operations are possible without the need of an erase operation when

 

changing bits from ‘1’ to ‘0’. Writing ‘1’ requires a Flash memory erase operation.

 

JW
cool26happy
Associate II
Posted on October 22, 2014 at 14:41

:(((

OK. How to setup linker for this... sector 2 and sector 3 are eeprom, others main code?

Posted on October 22, 2014 at 14:57

You'd have to create two discontinuous sections/segments, and direct specific sections/objects/functions into them.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..