Showing results for 
Search instead for 
Did you mean: 

Failing to flash a new program after writing to memory -- STM32F439 microcontroller

Associate II

Hello everyone, I am running into the following problem when reprogramming after a write to flash memory.

I am unable to reprogram the microcontroller after writing to flash memory.

In my program I write to bank 2 ( address 0x08100000 ) of the microcontroller using:




EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
EraseInitStruct.Sector = FLASH_SECTOR_12;
EraseInitStruct.NbSectors = 2;
EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3;

HAL_FLASHEx_Erase(&EraseInitStruct, &flash_error_information);

while(update->start_address + update->current_byte_num != update->end_address)
HAL_FLASH_Program( FLASH_TYPEPROGRAM_BYTE, update->start_address + update->current_byte_num, update->data_to_write_in_flash[ update->current_byte_num ]);





After running the program and attempting to flash another program, I then get the following error on a message box:

Error message from debugger back end:

Error finishing flash operation


The console returns the following:

Encountered Error when opening C:\ST\STM32CubeIDE_1.12.0\STM32CubeIDE\plugins\\tools\bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer



The only solution I have found is adding a delay such as HAL_Delay(250); after unlocking the flash memory, but this is far from a permanent solution.

Any help would be greatly apreciated.


Associate II

Hi , Iam also facing the same issue, did you found any solution..?

Is the code you put in the second bank bad, partial, corrupt?

The System Loader will try to identify second-bank code at 0x08100000

Does behaviour change if you put it deeper ? say 0x08110000 ?

Can you access the device with BOOT0 = HIGH ?

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