cancel
Showing results for 
Search instead for 
Did you mean: 

After I write to flash memory I cannot do it again upon reflashing entire program onto chip, how to avoid this?

WBäck.1
Associate

I have an STM32F407 board and have worked out how to flash a certain flash-sector as well as erasing it.

My problem is that whenever I have written to flash, and I reboot my board, I cannot flash again until I reflash the entire programme from STM32CubeIDE. As far as I've understood it is that whenever flash is accessed it will lock it afterwards to avoid unauthorized access. But I want to be able to do it indefinitely without having to reflash the code. How do I do this?

My code is at the moment:

FLASH_Unlock();
FLASH_OB_Unlock();
 
FLASH_EraseSector(FLASH_Sector, VoltageRange);
flashFunction(param);
 
FLASH_Lock();
FLASH_OB_Lock();

Any suggestions what to do to be able to write to flash how much I want without reflashing?

4 REPLIES 4
Piranha
Chief II

Read the reference manual and debug the code. Look at FLASH status register, especially the error bits.

FBL
ST Employee

Hello @William Bäckström​,

As mentioned in the reference manual, the main Flash memory block is divided into 4 sectors of 16 Kbytes, 1 sector of 64 Kbytes, and 7 sectors of 128 Kbytes. You can program/erase the sectors word by word using HAL_FLASH_Program(); HAL_FLASHEx_Erase();

Maybe, jumping and executing your code from RAM could be a better choice.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

The person cannot implement a simple thing, but you are suggesting a more complex and rarely necessary one. Great advice!

Thank you for your feedback @Piranha​. Although, that's an interesting opinion, but I prefer to help anyways. We are here to help each other!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!