Skip to main content
Visitor II
April 17, 2024
Question

VSCode GDB Debug - Enable Watchdog Halt

  • April 17, 2024
  • 4 replies
  • 2326 views

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.

4 replies

Mikk Leini
Senior
March 17, 2026

Hello ST! Waiting for an answer.

LaurentL
ST Employee
March 17, 2026

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Mikk Leini
Senior
March 18, 2026

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();

 

LaurentL
ST Employee
March 18, 2026

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...

 

 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Mikk Leini
Senior
March 19, 2026

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();
}