Skip to main content
Associate
March 12, 2025
Solved

Unable to write data to flash memory

  • March 12, 2025
  • 2 replies
  • 841 views

Hey,

I have a stm32f407 discovery board, I flashed a code using stm32ide to store some integer data in sector 11 of flash memory(0x080E0000) and then read the data and blink led if it matched.
Now I commented the code to write data and tried just read data at that location, but when i tried to flash code using stm32ide onto the board it failed. Got this error in the console.

Error: ST-LINK error (DEV_TARGET_NOT_HALTED)

Error message from debugger back end:

Error finishing flash operation

Failed to execute MI command:

load D:\\Stm32_projects\\flash_memory\\Debug\\flash_memory.elf

 

Error message from debugger back end:

Error finishing flash operation

Failed to execute MI command:

load D:\\Stm32_projects\\flash_memory\\Debug\\flash_memory.elf

 

Error message from debugger back end:

Error finishing flash operation

Error finishing flash operation



But if I try to flash code using stlink utility it works fine.

Best answer by TDK

In your program, wait 1 second before accessing the flash. Doing so just after reset causes the debugger to be unable to attach.

2 replies

Senior III
March 12, 2025

If you enabled Watchdog Timer (IWDG) or certain low-power modes, the MCU might reset or lock up before the debugger can connect.

Try a full chip erase using ST-Link Utility or STM32CubeProgrammer

 

st-flash erase

 

Then reflash your firmware.

 

SorabhRAuthor
Associate
March 12, 2025

I do not have any watchdog enabled 

Yes it does work after full chip erase but it that case my purpose of storing data in flash goes away as the data is no more available.

TDK
TDKBest answer
Super User
March 12, 2025

In your program, wait 1 second before accessing the flash. Doing so just after reset causes the debugger to be unable to attach.

"If you feel a post has answered your question, please click ""Accept as Solution""."