cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am using STM32F401CC mcu. I want to erase the value of a specific flash memory address . Is it possible ? Is there any function like EraseFlashAddress ? Thanks

FYumb
Associate
 
3 REPLIES 3
Bob S
Principal

You cannot erase just a single FLASH location, but you can erase a "page". I don't know the page sizes on the F401, but the F407 had some of 16K bytes, some of 64K bytes and some of 128K bytes. If you are using HAL, then look for (EDIT: fixed function name) HAL_FLASHEx_Erase() - or at least that is what it is called in the L4xx HAL library.

FYumb
Associate

Hi Bob,

F401 FLASH->CR register doesn't support page erasing. Actually, it supports only mass erase and sector erase. But I have to erase just a single address. I wrote the flash sector to RAM which is I am using. But this solution is not available for me. Because I need to use value of a single address after reset. So I cannot use RAM. Is there any solution to do that ?

Thanks.

Bob S
Principal

You can't use RAM, even as a temporary buffer????? In that case your only other option is to use 2 sectors and ping-pong between them. I am presuming that all of the other bytes in this FLASH sector contain data that you must preserve and can't re-create on the fly.

Do you have to update this FLASH location **EVERY** time you come out of reset? If so, you MAY have issues with lifetime erase/program cycles and reliability. I don't recall if the F4xx series was 100,000 or 10,000 flash erase/program cycles (or even 1 million????). Yeah, even 10,000 sounds like a lot as 10,000 cycles at one erase/program per day is 27+ years. But what if the device resets once every hour? Now you are down to just over a year.

Usually for data stored in FLASH like this the trick is to use 2 or more FLASH sectors to emulate an EEPROM. There are app notes on the ST site on doing this for some CPU families. The basic idea is that each data "item" gets a header and checksum/CRC. Each time you update the value in FLASH, you simply write the new value into the next available locations in FLASH. When trying to read the value from FLASH, start at the beginning of the sector and look for the last version of that data that is stored. Some STM32 chips allow you to write all zeros into a FLASH location that has already been programmed. If the F401 allows this, then the EEPROM emulation code can write zeros to the CRC/checksum value of the "old" data so that it is no longer valid.