Independent watchdog (IWDG) or Window watchdog (WWDG)

microcontrollerstm32watchdog

I'm still searching to find an answer for this question:

Why while the stm32 MCUs have a perfect watchdog (I mean Window watchdog (WWDG)), there is a simple watchdog (Independent watchdog (IWDG)) ?

I found this page that has said:

ST Microelectronics has a line of Cortex-M3 devices. The M3 has become extremely popular for lower-end embedded devices, and ST's STM32F is representative of these parts (though the WDT is an ST add-on, and does not necessarily mirror other vendors' implementations). The STM32F has two different protection mechanisms. An "Independent Watchdog" is a pretty vanilla design that has little going for it other than ease of use. But their Window Watchdog offers more robust protection. When a countdown timer expires, a reset is generated, which can be impeded by reloading the timer. Nothing special there. But if the reload happens too quickly, the system will also reset. In this case "too quickly" is determined by a value one programs into a control register.

Another cool feature: it can generate an interrupt just before
resetting. Write a bit of code to snag the interrupt and you can take
some action to, for instance, put the system in a safe state or to
snapshot data for debugging purposes. ST suggests using the ISR to
reload the watchdog — that is, kick the dog so a reset does not
occur. Don't take their advice. If the program crashes the interrupt
handlers may very well continue to function normally. And using an ISR
to reload the WDT invalidates the entire reason for a window watchdog.

and this:

STMicroelectronics' new series of STM32F4 Cortex™-M4 CPUs has two
independent watchdogs. One runs from its own internal RC oscillator.
That means that all kinds of things can collapse in the CPU and the
WDT will still fire. There is also a “window watchdog” (WWDT) which
requires the code to tickle it frequently, but not too often. This is
a very effective way to insure crashed code that randomly writes to
the protection mechanism does not cause a WDT tickle, and the WWDT can
generate an interrupt shortly before reset is asserted.

ok, let's to take a look in the reference manual:

The STM32F10xxx have two embedded watchdog peripherals which offer a
combination of high safety level, timing accuracy and flexibility of
use. Both watchdog peripherals (Independent and Window) serve to
detect and resolve malfunctions due to software failure, and to
trigger system reset or an interrupt (window watchdog only) when the
counter reaches a given timeout value. The independent watchdog (IWDG)
is clocked by its own dedicated low-speed clock (LSI) and thus stays
active even if the main clock fails. The window watchdog (WWDG) clock
is prescaled from the APB1 clock and has a configurable time-window
that can be programmed to detect abnormally late or early application
behavior. The IWDG is best suited to applications which require the
watchdog to run as a totally independent process outside the main
application, but have lower timing accuracy constraints. The WWDG is
best suited to applications which require the watchdog to react within
an accurate timing window.

The window watchdog is used to detect the occurrence of a software
fault, usually generated by external interference or by unforeseen
logical conditions, which causes the application program to abandon
its normal sequence. The watchdog circuit generates an MCU reset on
expiry of a programmed time period, unless the program refreshes the
contents of the downcounter before the T6 bit becomes cleared. An MCU
reset is also generated if the 7-bit downcounter value (in the control
register) is refreshed before the downcounter has reached the window
register value. This implies that the counter must be refreshed in a
limited window.

As you can see, none of them have said that Why there is two watchdog. if I ask that What are the differences between the both watchdog, you will count all features that you can see in the above and if you want compare the both, obviously the Window watchdog (WWDG) will be the winner! then Why there are two watchdog?

I want to know that when should I use IWDG and when WWDG?

and is there any reason that say us Why do they call the second watch by this name -> "Window watchdog"?

Best Answer

Regular watchdog timers must be reset at some time before they time out. If you have a 100ms WDT you can reset it every 99.9ms or every 10us and it will never time out.

Window watchdog timers have a time window within which they must be reset. If you reset it too early or too late (from the previous reset) it will cause the processor to reset.

The purpose, if it is not obvious, is to help ensure that the code resetting the WDT is the intended code, operating in the intended fashion. Some kind of unforeseen condition that generates high-frequency WDT resets won't prevent the system from being reset.

Running a WDT from the system clock could be a bit of an issue- if the clock fails and if there is not an independent clock monitor circuit, bad things can happen. The independent clock for the WDT means that if the thing for some reason started running at 1/10 speed, the WDT would reset (but the window WDT would not).

Use both if you can.

As the page says, resetting the WDT with an ISR is generally bad juju (but may be acceptable if the ISR verifies the reset of the firmware is functioning before resetting the timer).