Skip to main content
Associate II
May 26, 2025
Question

MCU Debug Halt After Writing Struct Data to Flash (STM32F4)

  • May 26, 2025
  • 2 replies
  • 418 views

Hi everyone,

I’m working on an STM32F4 project where I save a configuration struct to internal flash memory to preserve settings across power cycles.

The first time I run my program and write the struct to flash, everything works fine. But the second time I try to debug, right after writing to flash, my debugger fails to halt the MCU and I get this error in STM32CubeProgrammer:

Error: ST-LINK error (DEV_TARGET_NOT_HALTED)

Encountered Error when opening C:\ST\STM32CubeIDE_1.15.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.2.0.202409170845\tools\bin\STM32_Programmer_CLI.exe

Error in STM32CubeProgrammer

Has anyone experienced this issue when writing to flash during debugging?

2 replies

Tesla DeLorean
Guru
May 26, 2025

Would suggest you instrument HardFault_Handler and Error_Handler to better understand if it fails there. Make it work independently of the debugger. This way you have some visibility in why its failing to connect via the debugger.

Have your FLASH code output progress data, where it's writing, what errors are being returned/flagged. Make sure the memory is erased/blank before use. It's a one-shot deal.

Don't erase active portions of the FLASH which your code is dependent on or contain the vector table, etc.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
TDK
Super User
May 26, 2025

Don't write to flash in the first 1 second of the program. Doing so will cause issues during debugging. A HAL_Delay(1000) prior to erasing/writing flash will fix this.

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