HAL IWDG Overview

Introducing IWDG

group IWDG_Introduction

The IWDG hardware abstraction layer provides a set of APIs to interface with the IWDG peripheral on STM32 microcontrollers.

The Independent Watchdog (IWDG) peripheral offers a high safety level thanks to its capability to detect malfunctions due to software or hardware failures.

The IWDG is clocked by an independent clock and stays active even if the main clock fails. In addition, the watchdog function runs in the VDD voltage domain, allowing the IWDG to remain functional even in low-power modes.

The IWDG is best suited for applications that require the watchdog to run as a fully independent process outside the main application, making it reliable for detecting unexpected behavior.

This abstraction layer guarantees portability and ease of use across different STM32 series.

Module and files

The following diagram illustrates the IWDG module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the IWDG module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.


@startuml
!$use_ppp_core = 1
!$use_ppp_ll = 1
!$use_ppp_hal = 1
!$use_api_itf = 1
!$use_hal_itf = 1
!$use_ll_itf = 1
!$use_core_itf = 1
!$use_ppp_isr = 1
!$use_hal_service = 1
!$use_hal_rcc = 1
!$use_hal_dma = 0
!$use_ll_rcc = 0
!$ppp = "IWDG"
!$hal_api_itf = "HAL " + $ppp + " API"
!$appli_itf = "User Callback"
!$ppp_name = "HAL_"+$ppp
!$ppp_ISR = $ppp+" ISR"
!$ll_ppp = "LL_"+$ppp
!$hal_dma_itf = "HAL_DMA_StartDirectXfer()\nHAL_DMA_Abort_IT"
!$hal_rcc_itf = "\t\t\tHAL_RCC_GetPCLK1Freq()\n\t\t\tHAL_RCC_"+$ppp+"_EnableClock()"
!$hal_ppp_itf = "DMA CallBacks\nDMA Half transfer complete CallBack\nError CallBacks"
!$hal_generic_itf = "HAL_GetTick()"
!$ll_ppp_itf = "LL " + $ppp +" API"
!$ppp_xIRQ = $ppp+"x_IRQ"
<style>
componentDiagram {
arrow {
FontSize 8
}
interface {
FontSize 8
}
}
</style>
title $ppp Software Component Diagram
Package "Application Layer" #DarkMagenta {
component [Appli]
interface "$appli_itf" as APPLI_Interface
[Appli] -r- APPLI_Interface
}
package "HAL" #DarkOrange {
[$ppp_name]
!if ($use_hal_dma == 1)
interface "$hal_ppp_itf" as HAL_PPP_Interface
[$ppp_name] -d- HAL_PPP_Interface
!endif
interface "$hal_api_itf" as HAL_PPP_APPLI_Interface
[$ppp_name] -u- HAL_PPP_APPLI_Interface
!if ($use_hal_service == 1)
  [HAL_SERVICE]
  interface "$hal_generic_itf" as HAL_Service_Interface
  [HAL_SERVICE] -r- HAL_Service_Interface
  [$ppp_name] -l-( HAL_Service_Interface
!endif
!if ($use_hal_dma == 1)
  [HAL_DMA]
  interface "$hal_dma_itf" as HAL_DMA_Interface
  [HAL_DMA] -u- HAL_DMA_Interface
  [HAL_DMA] -u-( HAL_PPP_Interface
  [$ppp_name] --( HAL_DMA_Interface
!endif
!if ($use_hal_rcc == 1)
  [HAL_RCC]
  interface "$hal_rcc_itf" as HAL_RCC_Interface
  [HAL_RCC] -l- HAL_RCC_Interface
  [$ppp_name] -r-( HAL_RCC_Interface
!endif
}
[Appli] -d-( HAL_PPP_APPLI_Interface
[$ppp_name] -u-( APPLI_Interface
package "Low Layer" #Technology {
!if ($use_ppp_ll == 1)
  [$ll_ppp]
  interface "$ll_ppp_itf" as LL_PPP_Interface
  [$ll_ppp]  -u- LL_PPP_Interface
!endif
!if ($use_ppp_isr == 1)
interface "$ppp_ISR" as PPP_ISR
[$ppp_ISR] -U- PPP_ISR
[$ppp_ISR]
!endif
[CMSIS-Devices]
!if ($use_ll_rcc == 1)
  [LL_RCC]
  interface "LL RCC API" as LL_RCC_API
  [LL_RCC] -u- LL_RCC_API
  [HAL_RCC] -d-(LL_RCC_API
!endif
!if ($use_hal_dma == 1)
  [DMA ISR]
  interface "DMA ISR" as DMA_ISR
  [DMA ISR] -u- DMA_ISR
!endif
}
package "HW" #LightCyan {
[STM32_HW]
!if ($use_ppp_isr == 1)
interface "$ppp_xIRQ" as PPPx_IRQ
[STM32_HW] -u- PPPx_IRQ
!endif
!if ($use_hal_dma == 1)
interface "DMAx_IRQ_Ch" as DMA_IRQ_CH
[STM32_HW] -u- DMA_IRQ_CH
[DMA ISR] -d-( DMA_IRQ_CH
[HAL_DMA] --( DMA_ISR
!endif
}
!if ($use_ppp_ll == 1)
[$ppp_name] -d-( LL_PPP_Interface
[$ll_ppp] .r.> [CMSIS-Devices]: $ppp register def
[STM32_HW] <.u. [$ll_ppp] : $ppp registers R/W
!else
[$ppp_name] .d.> [CMSIS-Devices]: $ppp register def
[STM32_HW] <.l. [$ppp_name] : $ppp registers R/W
!endif
!if ($use_ppp_isr == 1)
[$ppp_ISR] -d-( PPPx_IRQ
[$ppp_name] -d-( PPP_ISR
!endif
!if ($use_ll_rcc == 1)
[STM32_HW] <.u. [LL_RCC] : RCC registers R/W
!endif
@enduml

Configuration table

The following table lists the configuration defines for the HAL IWDG module, specifying their locations, default values, and descriptions:

group IWDG_Configuration_Table

Configuration inside the IWDG driver:

Config defines

Where

Default value

Note

USE_HAL_IWDG_MODULE

hal_conf.h

1

Enable the HAL IWDG module.

USE_HAL_IWDG_REGISTER_CALLBACKS

hal_conf.h

0

Enable register callback assertions.

USE_HAL_CHECK_PARAM

hal_conf.h

0

Enable checking of vital parameters at

runtime

USE_HAL_IWDG_HARDWARE_START

hal_conf.h

0

IWDG driver starts in HW mode

USE_HAL_IWDG_USER_DATA

hal_conf.h

0

Add user data in the HAL IWDG handle

USE_HAL_IWDG_TIME_UNIT (*)

hal_conf.h

HAL_IWDG_TIME_UNIT_MS

Time unit to be used for IWDG driver

USE_HAL_IWDG_LSI_FREQ (**)

hal_conf.h

LSI_VALUE

LSI value to be applied to the IWDG driver

USE_ASSERT_DBG_PARAM

PreProcessor env

NA

Enable parameter assertions.

USE_ASSERT_DBG_STATE

PreProcessor env

NA

Enable state assertions.

(*) Select the value of the time unit with the USE_HAL_IWDG_TIME_UNIT define:

  • HAL_IWDG_TIME_UNIT_US: IWDG driver time unit in microseconds.

  • HAL_IWDG_TIME_UNIT_MS: IWDG driver time unit in milliseconds.

  • HAL_IWDG_TIME_UNIT_S: IWDG driver time unit in seconds.

The default time unit is milliseconds if not set by the user.

(**) Select the value of the LSI frequency with the USE_HAL_IWDG_LSI_FREQ define:

  • LSI_VALUE_DYNAMIC: Dynamic LSI to be computed and set by the user.

  • LSI_VALUE: LSI value of 32kHz. The default LSI value is LSI_VALUE if not set by the user.

Allowed maximum time ranges:

The selection of prescaler is done as follows: as long as the requested reset time value is lower than the max_time of a time range n, the algorithm keeps the same prescaler n. Once it exceeds the max_time of the range n, the algorithm switches to the prescaler of the range n+1. The following table describes the possible maximum time ranges for each prescaler and with both standard values of the LSI frequency:

Note:

  • For “Not supported” values in s, switch to the ms or us unit. Similarly, for “Not supported” values in us, switch to the ms or s unit.

  • To cover all ranges, time unit static configuration has been introduced and can be expressed in us, ms, or seconds.

LSI(Hz)

Prescaler

Step(us)

Max(us)

Max(ms)

Max(s)

32000

4

125

512000

512

Not supported

32000

8

250

1024000

1024

1.024

32000

16

500

2048000

2048

2.048

32000

32

1000

4096000

4096

4.096

32000

64

2000

8192000

8192

8.192

32000

128

4000

16384000

16384

16.384

32000

256

8000

32768000

32768

32.768

32000

512

16000

65536000

65536

65.536

32000

1024

32000

131072000

131072

131.072