MCU Debug Halt After Writing Struct Data to Flash (STM32F4)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-26 8:56 AM
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?
- Labels:
-
ST boards
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-26 2:58 PM
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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-26 3:29 PM - edited 2025-05-26 3:29 PM
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.
