AnsweredAssumed Answered

Erase before new Flash write in STM32F0xx

Question asked by Vellingiri.Vairamani on Feb 5, 2017
Latest reply on Feb 5, 2017 by Clive One



I am working on STM32F072RB MCU. I can able to Program and Erase the Flash Page. But, I have few doubt about Flash programming. Sometimes the Data is not written in Flash, when i erase a same and write again it's work. So Flash programming is related to Erase, but can't understand clearly. Because it's not given datasheet also. 


The sequence i tried are given below..

A) Reset->Erase_Page10->Write_Page10 [Data is written]

B) Reset->Write_Page10 [Data is written]

C) Reset->Erase_Page10->Write_Page10(1st Data)->Erase_Page10->Write_Page10(2nd Data) [2nd Data is written]

D) Reset->Erase_Page10->Write_Page10(1st data)->Write_Page10(2nd data) [2nd Data is not written]

E)  Reset->Write_Page10(1st Data)->Write_Page9(1st Data)-->Write_Page10(2nd data) [2nd only Data is not written]


When i am referring the sample code in STM32Cube_FW_F0_V1.7.0, Flash driver.  In a HAL_StatusTypeDef HAL_FLASH_Program(..) function , the note is given as "FLASH should be previously erased before new programmation


By referring the above sequence we can tell..


I) After reset we can directly write in a page but it should erased previously.

II) After reset , if we writing a data on page at second time, then we need to erase and write. 


If above statements are true, then we need to keep one page or RAM for backup and when i am writing Page_X , the content should be shifted to Backup_page and after Page-X erase, we need to write a new data.


Related pages: Question about FLASH programming 

Please give a suggestion.