Running WDT in FreeRTOS

This application note explains how to use the WDT in the FreeRTOS demo application.

1. Understanding FreeRTOS WDT Interfaces

1.1. FreeRTOS WDI Implementation

The FreeRTOS BSP make uses of the STM32CubeH7 software component to provide a device driver for the STM32H7 WDT. The driver is configured (enabled / disabled) at the BSP build time, using the HAL_IWDG_MODULE_ENABLED configuration option, defined in the stm32h7xx_hal_conf.h file.

1.2. FreeRTOS WDT C-Binding API

The WDT driver implements the following C-binding API:




HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef * hiwdg )


Initialize the WDT according to the parameters specified by hiwdg and start the WDT

hiwdg is a WDT handle; returns one of {HAL_OK, HAL_ERROR, HAL_BUSY, HAL_TIMEOUT}

HAL_StatusTypeDef HAL_IWDG_Refresh (IWDG_HandleTypeDef *hiwdg)


Refresh the WDT


The IWDG_HandleTypeDef data structure used in the HAL_IWDG_Init interface has the following definition:

typedef struct { IWDG_TypeDef * Instance; /* Register base address */ IWDG_InitTypeDef Init; /* IWDG required parameters */ } IWDG_HandleTypeDef;

The IWDG_InitTypeDef data structure used in IWDG_HandleTypeDef has the following definition:

typedef struct { uint32_t Prescaler; /* Select the prescaler of the IWDG. */ uint32_t Reload; /* Specifies the IWDG down-counter reload value. */ uint32_t Window; /* Specifies the window value to be compared to the down-counter. */ } IWDG_InitTypeDef;

1.3. FreeRTOS WDT Strobing Task

The FreeRTOS tdemo application implements a separate thread (called the "WDT thread"), whose only task will be to strobe the WDT periodically, to ensure that the WDT does not reset the system.

The WDT will be enabled at the start of the WDT thread, before it enters the endless WDT strobing loop.

The WDT period will be set to 2 seconds.

2. WDT CLI Command

The FreeRTOS application implements the following WDT related CLI command:





Command the WDT thread to stop the WDT strobing (which will result in resetting the system on WDT expiration)


3. Validating WDT Operation

Use the following step-wise procedure to validate the FreeRTOS WDT operation:

  1. Power cycle the target board and let it boot to the FreeRTOS CLI.

  2. Let the board sit idle for 5 minutes, validate that no reset occurs.

  3. From the CLI, stop the WDT strobing:

    CLI> wdt_stop
  4. Validate that the board resets within several seconds: