Library 20- Independent watchdog timer on STM32F4

Sometimes you need watchdog timer to look at your system if it gets stuck. I made a little library to work with it.

Watchdog in STM32F4xx device has it’s own clock which is independent from main system clock. You have to constantly reset it’s counter value or it will elapse and reset MCU.

Watchdog Library


  • Detect if system was reset by watchdog
  • Supports different timeouts
  • Reset watchdog


    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx IWDG
  • TM
    • defines.h

Timeout structure

I made a structure with different timings for watchdog reset.

Initialize watchdog timer

Before you can use it, you have to initialize it. Function below initializes watchdog timer.

As parameter you have to pass one of members of watchdog structure.

This function returns 1 if system was reset by watchdog, otherwise 0.

Reset watchdog timer

You want system reset by watchdog only if system stuck somewhere. So you don’t want that watchdog reset your system all the time. For this, you have to reset timer’s counter periodically faster than he can count to it’s top value.

Reset timer with


Project available onĀ Github, download library 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!