2024-04-17 1:41 PM - last edited on 2026-03-17 5:09 AM by Andrew Neil
Hi,
I am not sure how to categorize this problem. I have a custom board that I had done an initial software development cycle on STM32CubeIDE. I am working a newer version in VSCode with the STM32 Extension. Everything is working with the exception of one problem. I am using a watchdog on my MCU (STM32L4R9ZGJ6), which triggers while I have the processor halted. I know how to fix this in CubeIDE (Debugger tab, Enable Suspend Watchdogs) but cannot figure it out on the VSCode/GDB side. Below is the launch.json I have so far:
{
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceFolder}",
"executable": "./build/debug/build/test.elf",
"name": "Debug with ST-Link",
"request": "launch",
"type": "cortex-debug",
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"servertype": "stlink"
},
{
"name": "Launch",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${command:cmake.launchTargetPath}",
"MIMode": "gdb",
"miDebuggerPath": "${command:vscode-embedded.st.gdb}",
"miDebuggerServerAddress": "localhost:3333",
"debugServerPath": "${command:vscode-embedded.st.gdbserver}",
"debugServerArgs": "--stm32cubeprogrammer-path ${command:vscode-embedded.st.cubeprogrammer} --swd --port-number 3333",
"serverStarted": "Waiting for connection on port .*\\.\\.\\.",
"stopAtConnect": true,
"postRemoteConnectCommands": [
{
"text": "load build/debug/build/UPADermitron.elf"
}
],
"logging": {
"engineLogging": true
},
"preLaunchTask": "Build",
"svdPath": "${command:vscode-embedded.st.svd}/STM32L4R9.svd"
}
]
}Any help is appreciated! Sorry if this has come up but I have tried to find with no luck.
2026-03-17 5:00 AM
Hello ST! Waiting for an answer.
2026-03-17 6:10 AM
Hello,
To freeze WDGs counters when halted, you need to update the DBGMCU registers.
In "STM32CUBE REGISTERS TREE" view, open DBGMCU registers and in APB1_FZR1 register, you need to set the DBG_WWDG_STOP and/or DBG_IWDG_STOP register bits.
Regards,
Laurent
2026-03-17 11:36 PM
Hi @LaurentL.
Is there any vscode debug option to do it automatically? Feature request!?!
If doing it programmatically, clock needs to be enabled also:
__HAL_RCC_DBGMCU_CLK_ENABLE();
__HAL_DBGMCU_FREEZE_IWDG(); /* and/or */ __HAL_DBGMCU_FREEZE_WWDG();
2026-03-18 3:07 AM
Hi,
This feature is under development on STM32CubeIDE for Visual Studio Code and should be available for next version.
"Low Power Modes" and "Watchdogs Freeze" will have a server attribute in launch configuration.
"RCC DBGMCU CLK Enable" is not present on STM32L4 devices so I didn't mentioned it.
But it is on some other series like STM32L0/G0/C0...
2026-03-19 7:43 AM
Great to hear it's coming.
Thanks for clarifying the debug clock difference.
However I use STM32N6 and for some reason, if I call the lines that I wrote above, then device does not run without debugger - it just hangs. Doesn't even make a watchdog reset. Didn't check in details what happens. The cure is to allow freezing IWDG only when debugger is connected:
if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) != 0U)
{
__HAL_RCC_DBGMCU_CLK_ENABLE();
__HAL_DBGMCU_FREEZE_IWDG();
}