Hello friends,

Before publishing my EFM32 timer drivers, I want explane a little the WatchDog timer – it’s purpose and how to use it.

Watchdog  timer’s purpose is to restart the MCU in case of some errors, that occurred in MCU and “froze” it.
On power, you have to ensure that your code always running. In some cases, your MCU gets errors that can’t be handled and ensure proper work. This is an exact case when you have to use the WhatsDog!

Let’s see, how we configure the WatchDog in EFM32 MCUs.

First of all and the last thing, we have to initiate the Watchdog:

void wdogSetup() {
   WDOG_Init_TypeDef wdog_init;
   //start it automatically after the initialization
   wdog_init.enable     = 1;
   //don't run it during debugging
   wdog_init.debugRun   = 0;
   //run it at EM2 energy mode
   wdog_init.em2Run     = 1;
   //run it at EM3 energy mode
   wdog_init.em3Run     = 1;
   //don't block the MCU from entering to EM4 energy mode (shutdown)
   wdog_init.em4Block   = 0;
   //don't block software from disabling of LF oscillators
   wdog_init.swoscBlock = 0;
   //don't lock the wdog configuration - possible to change the wdog configuration at run time
   wdog_init.lock       = 0;
   //chose the clock source for the wdog
   //if it have to work at EM3 - choose Ultra Low Energy Clock: 1KHz
   //for example I choose the Low Energy Clock: 32.768 KHz
   wdog_init.clkSel     = wdogClkSelLFXO;
   //choose period for wdog
   wdog_init.perSel     = wdogPeriod_4k;
   /*
   In this case, I configured the wdog to reset the MCU each 125 miliseconds :
   Formula -> Time = (1/Clock) * period
   0.125 sec = (1/32768) * 4096
   */
   //So, lets init it:
   WDOG_Init(&wdog_init);
   //WatchDog count starts immediately.  
}

Don’t forget to restart the WatchDog!!! Otherwise your MCU restart occurs automatically on configuration (125 msec in our example)
To restart the WatchDog, call the WDOG_Feed() function.

That’s all! 🙂
Simple, not?!