cancel
Showing results for 
Search instead for 
Did you mean: 

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

themarcman
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:

 

 

HAL_FLASH_Unlock();


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 ]);
update->current_byte_num++;
}

HAL_FLASH_Lock();

 

 

 

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:

Error: ST-LINK error (DEV_TARGET_NOT_HALTED)
Encountered Error when opening C:\ST\STM32CubeIDE_1.12.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.600.202301161003\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.

 

2 REPLIES 2
rk8266882
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..