GD32 combat 19__ watchdog

Why do we need a watchdog

Our products can always expect stable operation never been down, but the truth is always unsatisfactory, a variety of unexpected happens, downtime is inevitable, took the second, we want to happen in case dang machine, the system can detect and recover itself. The watchdog is to detect faults and to restore a common means.

Why is it called a watchdog? It is actually a very image of the call, just like a dog, like the janitor, fixed CPU time required to feed a food, regardless of CPU for any reason not to feed the dog, the dog will be called, we know CPU is definitely a problem.

Watchdog usually of two kinds,

  1. External watchdog, watchdog chip increases beyond the MCU, MCU can check hardware failure and recovery.
  2. Internal watchdog, internal use comes with MCU watchdog, can not check the MCU hardware failure, software failure can only check and recovery.

How to configure

GD32 comes with an internal watchdog and independent watchdog window.

  1. Independent watchdog has a separate clock source, even if the main clock fails, it still can work, is ideal for stand-alone environment and timing accuracy is not required for the scene.
  2. Window watchdog applies to scenarios require precise timing

Is essentially a counter, configuration is very simple, directly on the code

#define DRV_IWDG_FeedWDog IWDG_ReloadCounter

VOID DRV_IWDG_Init(VOID)
{
    /* Enable write access to IWDG_PSR and IWDG_RLDR registers */
    IWDG_Write_Enable(IWDG_WRITEACCESS_ENABLE);

    /* IWDG counter clock: 40KHz(LSI) / 64 = 0.625 KHz */
    IWDG_SetPrescaler(IWDG_PRESCALER_16);

    /* Set counter reload value to 625 */
    IWDG_SetReloadValue(0x0fff);

    /* Reload IWDG counter */
    IWDG_ReloadCounter();

    /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
    IWDG_Enable();
}

The test results, as shown, when there is no feed the dog, will continue to be bitten by a dog, as shown in FIG restarted reason, after the dogs, normal system.

Here Insert Picture Description

Code path

https://github.com/YaFood/GD32F103/tree/master/TestWDG

Guess you like

Origin blog.csdn.net/qq_17854661/article/details/92575770