Using Watchdog in Bluetooth Applications

Description

In general, use Watchdog to reset your device should the Bluetooth stack stop working for any reason. This software example will show you how to use a Watchdog timer in the Bluetooth application context.

The Watchdog API is fairly simple. The Watchdog has to be initialized once after reset with WDOG_Init(&init) and it has to be fed from time to time before the Watchdog timer expires using WDOG_Feed(). In a Bluetooth context, the most suitable way to feed the Watchdog is by using a soft timer. A soft timer event is triggered by the stack each time the timer expires. If the stack stops working, a soft timer event is not generated and the Watchdog is not fed. Ultimately, this will reset the device.

To determine whether you recovered from a crash with a Watchdog reset or whether the device was reset normally, use the function RMU_ResetCauseGet();.

Setting up

  1. Create a new SoC - Empty project in Simplicity Studio.

  2. Copy em_wdog.c and em_wdog.h into the project from: C:\SiliconLabs\SimplicityStudio\vX\developer\sdks\gecko_sdk_suite\versionY\platform\emlib

  3. Copy gpiointerrupt.c into the project from: C:\SiliconLabs\SimplicityStudio\vX\developer\sdks\gecko_sdk_suite\versionY\platform\emdrv\gpiointerrupt\src\

  4. Copy the attached app.c file to your project (overwriting the existing one).

  5. Change DEBUG_LEVEL to 1 in app.h (enable log output).

  6. Build and flash the project to your board.

Usage

The attached example application sets a Watchdog period of 2 seconds and sets up a soft timer to feed the Watchdog every second (1 s). An LED is also toggled on every soft timer event to make the heartbeat visible. Pushbutton PB0 is set to trigger an interrupt when pressed down. The callback from the ISR will stop the soft timer from feeding and cause the Watchdog to reset the device. After the device boots again, a log message indicating a Watchdog reset is printed to UART. To see log messages, use any terminal program (e.g., TeraTerm).

Note: If you are implementing a low-energy application, set the timer to a period longer than 1 second because waking up the device every second results in high consumption.

Source