STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
IWDG

Independent watchdog start, refresh and debug freeze. More...

Collaboration diagram for IWDG:

Macros

#define IWDG_UPDATE_TIMEOUT_ITERATIONS   (100000U)
 Polls allowed for SR.PVU and SR.RVU to clear: an update takes up to 5 LSI cycles, under 300 us even at 17 kHz (see Poll-count timeouts).

Functions

DRIVER_MUST_CHECK DriverStatus_e iwdgStart (IwdgRegisters_t *iwdg, uint32_t prescaler, uint32_t reload)
 Start the watchdog, then set its prescaler and reload value.
void iwdgRefresh (IwdgRegisters_t *iwdg)
 Reload the counter from RLR (KR = 0xAAAA).
void iwdgFreezeInDebug (DbgmcuRegisters_t *dbgmcu)
 Stop the IWDG counter whenever the core is halted by a debugger.
static DriverStatus_e iwdgWaitUpdates (const IwdgRegisters_t *iwdg)
 Poll SR until no prescaler or reload update is in progress.

Detailed Description

Independent watchdog start, refresh and debug freeze.

Macro Definition Documentation

◆ IWDG_UPDATE_TIMEOUT_ITERATIONS

#define IWDG_UPDATE_TIMEOUT_ITERATIONS   (100000U)

Polls allowed for SR.PVU and SR.RVU to clear: an update takes up to 5 LSI cycles, under 300 us even at 17 kHz (see Poll-count timeouts).

Definition at line 15 of file iwdg.c.

Referenced by iwdgWaitUpdates().

Function Documentation

◆ iwdgStart()

DriverStatus_e iwdgStart ( IwdgRegisters_t * iwdg,
uint32_t prescaler,
uint32_t reload )

Start the watchdog, then set its prescaler and reload value.

Starting comes first because PR and RLR only take a new value while the LSI runs, and starting the IWDG is what turns the LSI on. The sequence is KR = start, KR = unlock, write PR and RLR, wait for SR.PVU and SR.RVU to clear, then refresh, so the new reload value is in the counter on return. Until then it runs from the previous values (/4 and 0xFFF after reset: about 0.5 s). Can be called again to change the timeout.

Parameters
iwdgIWDG block (e.g. IWDG).
prescalerAn IWDG_PR_DIV* value.
reloadCounter reload, 0 to 0xFFF. Timeout = (reload + 1) x divider / f_LSI.
Return values
DRIVER_STATUS_OKRunning with the new values, just refreshed.
DRIVER_STATUS_ERR_INVALID_PARAMprescaler or reload is out of range. Nothing written; a running watchdog keeps running.
DRIVER_STATUS_ERR_TIMEOUTSR.PVU or SR.RVU did not clear. The watchdog is running, and its values are not known.
Warning
Once started the watchdog cannot be stopped. Refresh it with iwdgRefresh() before every timeout, or the chip resets.

Definition at line 42 of file iwdg.c.

References DRIVER_STATUS_ERR_INVALID_PARAM, DRIVER_STATUS_OK, IWDG_KEY_ENABLE_ACCESS, IWDG_KEY_START, IWDG_PR_DIV256, IWDG_PR_PR_Pos, IWDG_RLR_RL_Msk, IWDG_RLR_RL_Pos, iwdgRefresh(), iwdgStart(), iwdgWaitUpdates(), IwdgRegisters_t::KR, IwdgRegisters_t::PR, and IwdgRegisters_t::RLR.

Referenced by iwdgStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iwdgRefresh()

void iwdgRefresh ( IwdgRegisters_t * iwdg)

Reload the counter from RLR (KR = 0xAAAA).

A single store, so it is safe from any context.

Parameters
iwdgIWDG block (e.g. IWDG).

Definition at line 78 of file iwdg.c.

References IWDG_KEY_RELOAD, iwdgRefresh(), and IwdgRegisters_t::KR.

Referenced by iwdgRefresh(), and iwdgStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iwdgFreezeInDebug()

void iwdgFreezeInDebug ( DbgmcuRegisters_t * dbgmcu)

Stop the IWDG counter whenever the core is halted by a debugger.

Without this, a breakpoint held for longer than the timeout resets the chip. It has no effect when no debugger halts the core. The bit is reset by power-on only, so it survives a watchdog reset. OpenOCD's stm32f4x target script also sets it when it attaches; this call does not depend on the debug tool.

Parameters
dbgmcuDBGMCU block (e.g. DBGMCU).

Definition at line 83 of file iwdg.c.

References DbgmcuRegisters_t::APB1_FZ, DBGMCU_APB1_FZ_DBG_IWDG_STOP, and iwdgFreezeInDebug().

Referenced by iwdgFreezeInDebug().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iwdgWaitUpdates()

DriverStatus_e iwdgWaitUpdates ( const IwdgRegisters_t * iwdg)
static

Poll SR until no prescaler or reload update is in progress.

Parameters
iwdgIWDG block; only SR is read.
Return values
DRIVER_STATUS_OKSR.PVU and SR.RVU are clear.
DRIVER_STATUS_ERR_TIMEOUTOne is still set after IWDG_UPDATE_TIMEOUT_ITERATIONS polls.

Definition at line 23 of file iwdg.c.

References DRIVER_STATUS_ERR_TIMEOUT, DRIVER_STATUS_OK, IWDG_SR_PVU, IWDG_SR_RVU, IWDG_UPDATE_TIMEOUT_ITERATIONS, iwdgWaitUpdates(), and IwdgRegisters_t::SR.

Referenced by iwdgStart(), and iwdgWaitUpdates().

Here is the call graph for this function:
Here is the caller graph for this function: