STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
wwdg.h File Reference

WWDG driver: start, refresh and debug-freeze the window watchdog. More...

#include "dbgmcu_reg.h"
#include "driver_status.h"
#include "wwdg_reg.h"
#include <stdint.h>
Include dependency graph for wwdg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WWDG_COUNTER_MIN   (0x40U)
 Lowest counter or window value: 0x3F is the reset point.
#define WWDG_COUNTER_MAX   (0x7FU)
 Highest counter or window value (7 bits).

Functions

DRIVER_MUST_CHECK DriverStatus_e wwdgStart (WwdgRegisters_t *wwdg, uint32_t prescaler, uint32_t window, uint32_t counter)
 Set the window and timer base, then start the watchdog counting from counter.
DRIVER_MUST_CHECK DriverStatus_e wwdgRefresh (WwdgRegisters_t *wwdg, uint32_t counter)
 Reload the counter with counter (CR = WDGA | counter).
void wwdgEnableEarlyWakeup (WwdgRegisters_t *wwdg)
 Raise WWDG_IRQn when the counter reaches 0x40, one count before reset.
void wwdgClearEarlyWakeup (WwdgRegisters_t *wwdg)
 Clear the early-wakeup flag (SR.EWIF, write 0 to clear).
void wwdgFreezeInDebug (DbgmcuRegisters_t *dbgmcu)
 Stop the WWDG counter whenever the core is halted by a debugger.

Detailed Description

WWDG driver: start, refresh and debug-freeze the window watchdog.

The 7-bit counter CR.T counts down at PCLK1 / 4096 / 2^WDGTB and resets the chip when it falls from 0x40 to 0x3F. A refresh also resets the chip if it comes while the counter is still above the window CFR.W, so the WWDG catches code that runs too fast as well as too slow. With PCLK1 at 45 MHz and /8, one count is 728 us, and 0x7F to 0x3F is about 46 ms.

The usual pattern refreshes from the early-wakeup interrupt, raised at 0x40, which is inside the window as long as W is above 0x40:

if (wwdgStart(WWDG, WWDG_CFR_WDGTB_DIV8, 0x5FU, 0x7FU) != DRIVER_STATUS_OK) { ... }
if (nvicEnableIrq(NVIC, WWDG_IRQn) != DRIVER_STATUS_OK) { ... }
// in WWDG_IRQHandler: wwdgClearEarlyWakeup(WWDG); then refresh with 0x7F
#define DBGMCU
The DBGMCU instance.
Definition dbgmcu_reg.h:31
@ DRIVER_STATUS_OK
Succeeded.
DRIVER_MUST_CHECK DriverStatus_e nvicEnableIrq(NvicRegisters_t *nvic, IRQn_e irqn)
Enable a device interrupt.
Definition nvic.c:97
#define NVIC
The NVIC instance.
Definition nvic_reg.h:45
void rccWwdgClockEnable(RccRegisters_t *rcc)
Enable the WWDG's clock; needed before any WWDG access.
Definition rcc.c:107
#define RCC
The RCC instance.
Definition rcc_reg.h:61
void wwdgFreezeInDebug(DbgmcuRegisters_t *dbgmcu)
Stop the WWDG counter whenever the core is halted by a debugger.
Definition wwdg.c:86
void wwdgEnableEarlyWakeup(WwdgRegisters_t *wwdg)
Raise WWDG_IRQn when the counter reaches 0x40, one count before reset.
Definition wwdg.c:75
DRIVER_MUST_CHECK DriverStatus_e wwdgStart(WwdgRegisters_t *wwdg, uint32_t prescaler, uint32_t window, uint32_t counter)
Set the window and timer base, then start the watchdog counting from counter.
Definition wwdg.c:30
#define WWDG
The WWDG instance.
Definition wwdg_reg.h:29
#define WWDG_CFR_WDGTB_DIV8
WDGTB value: PCLK1 / 4096 / 8.
Definition wwdg_reg.h:52

After a reset, rccResetFlags() reports whether the WWDG caused it.

Definition in file wwdg.h.