Running WDT in FreeRTOS Print


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

Understanding FreeRTOS WDT Interfaces

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.

FreeRTOS WDT C-Binding API

The WDT driver implements the following C-binding API:

Function Description Comments
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 Returns one of {HAL_OK, HAL_ERROR, HAL_BUSY, HAL_TIMEOUT}

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;

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.

WDT CLI Command

The FreeRTOS application implements the following WDT related CLI command:

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

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:
  4. CLI> wdt_stop

  5. Validate that the board resets within several seconds:
  6. CLI>
    U-Boot SPL 2019.04-00007-g8b8880c8e2 (May 04 2019 - 13:33:41 +0300)
    U-Boot 2019.04-00007-g8b8880c8e2 (May 04 2019 - 13:33:41 +0300)
    STM32H7-SOM U-Boot >