Microchip® Advanced Software Framework

Quickstart guide for SAM4L watchdog driver

This is the quickstart guide for the SAM4L watchdog driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Use cases

Basic use case

In this basic use case, the watchdog will use the RCSYS as the source clock and the timeout period will be configured as 0.57 second. Then the watchdog will be kicked every 100ms.

Prerequisites

Setup Steps

Note
The watchdog clock (CLK_WDT) is enabled at reset and the default source is system RC oscillator(RCSYS). If you want to use 32KHz oscillator as watchdog clock, please make sure it is enabled first:
// Enable WDT clock source if need
if (BPM->BPM_PMCON & BPM_PMCON_CK32S) {
// Enable 32K RC oscillator
}
} else {
// Enable external OSC32 oscillator
}
}

Setup Example Code

Add the following code in the application C-file to setup watchdog:

// WDT instance
// WDT configuration
// Initialize and enable the watchdog

Setup Workflow

  1. Create variables to store the watchdog instance and configuration:
  2. Get default configuration but change timeout period to 0.57s (Ttimeout = 2pow(PSEL+1) / Fclk_cnt = 65535 / 115000).
  3. Initialize the watchdog:

Usage Steps

Usage Example Code

Add to, e.g., main loop in application C-file:

while (1) {
// delay 100ms
}

Usage Workflow

  1. Enable the watchdog:
  2. Kick the watchdog in every 100ms:
    while (1) {
    // delay 100ms
    }
  3. A daemon program is created now. The MCU tasks can be added after the code of wdt_clear() then the tasks are under the monitor of watchdog. If the tasks lasted more than 0.57 second, the options of the watchdog timeout period should be adjusted accordingly.

Reset MCU by the WDT

We can reset MCU by generating a WDT reset as soon as possible.

bool ret;
ret = wdt_reset_mcu();