Failing to flash a new program after writing to memory -- STM32F439 microcontroller
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.
