Disable peripherals in debug mode on STM32F4xx

Have you ever used watchdog in your application? Have you ever debug your application when watchdog was enabled and you hit stop? Watchdog did not stop in this case and when you pressed “continue” in your debugger, your program starts over because WDG has reset your system. One choice is that you remove line where you initialize IWDG, but you then must recompile and redownload and all that stuff. Wasting useful time.

To avoid this problem, STM32 devices have possibility to disable some peripherals when you are in debug mode. And one of that peripherals is also WDG timer which won’t count and won’t reset your system when you will be in debug mode, even if you enable it somewhere in your code. This gives you a possibility to STOP execution in your program (breakpoint) anytime and continue program without worries about system reset.

DBGMCU (DeBuG MicroController Unit) is called section in STM32 with possibility to disable other peripherals when you are in debug mode. For STM32F4xx series, you can disable these peripherals:

Basically all timers only can be disabled with CAN and I2C. So, to disable IWDG in debug mode, you can do like in example below.



Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!