Skip to main content
WBäck.1
Visitor II
March 1, 2023
Question

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

  • March 1, 2023
  • 4 replies
  • 1218 views

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?

This topic has been closed for replies.

4 replies

Piranha
Principal III
March 2, 2023

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

ST Technical Moderator
March 3, 2023

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 "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
Piranha
Principal III
March 3, 2023

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

ST Technical Moderator
March 5, 2023

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 "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL