|
STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
|
Independent watchdog start, refresh and debug freeze. More...
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. | |
Independent watchdog start, refresh and debug freeze.
| #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().
| 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.
| iwdg | IWDG block (e.g. IWDG). |
| prescaler | An IWDG_PR_DIV* value. |
| reload | Counter reload, 0 to 0xFFF. Timeout = (reload + 1) x divider / f_LSI. |
| DRIVER_STATUS_OK | Running with the new values, just refreshed. |
| DRIVER_STATUS_ERR_INVALID_PARAM | prescaler or reload is out of range. Nothing written; a running watchdog keeps running. |
| DRIVER_STATUS_ERR_TIMEOUT | SR.PVU or SR.RVU did not clear. The watchdog is running, and its values are not known. |
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().
| void iwdgRefresh | ( | IwdgRegisters_t * | iwdg | ) |
Reload the counter from RLR (KR = 0xAAAA).
A single store, so it is safe from any context.
| iwdg | IWDG 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().
| 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.
| dbgmcu | DBGMCU 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().
|
static |
Poll SR until no prescaler or reload update is in progress.
| iwdg | IWDG block; only SR is read. |
| DRIVER_STATUS_OK | SR.PVU and SR.RVU are clear. |
| DRIVER_STATUS_ERR_TIMEOUT | One 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().