01. IWDG概述6 x+ p! G- n3 p# t( o# M
stm32f4xx_iwdg.h和stm32f4xx_iwdg.c文件中
. K! c3 B# Z) T- _) `% {
5 {% v0 r5 I5 ?7 U% Q7 R02. 相关类型+ t2 B, [! e) x* D G, y% T! S
IWDG_WriteAccess- /** @defgroup IWDG_WriteAccess! o/ ^6 V: Z! w: c6 r* U: B
- * @{# v6 T$ e* x0 i
- */
2 B) P. T E$ z0 j* s K2 ` - #define IWDG_WriteAccess_Enable ((uint16_t)0x5555)# p i! C2 W& G0 L
- #define IWDG_WriteAccess_Disable ((uint16_t)0x0000)
" F$ G0 g8 K0 r& e - #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \
+ d0 r0 c F: ]. u% d - ((ACCESS) == IWDG_WriteAccess_Disable))
复制代码 2 d) v5 K- |* u1 e5 o9 P
IWDG_prescaler8 c! t' l: X" y" y0 Y; S! |
9 n; w% T% i- ?. G7 c' \/ R
- /** @defgroup IWDG_prescaler 2 x8 X1 \6 z# ?, c" I( o. `
- * @{5 L/ U2 ?) o: U* h H6 N( o
- */
s% B7 c9 v3 Z P% Y. K6 W: p - #define IWDG_Prescaler_4 ((uint8_t)0x00)
& A0 t2 m" a% ?: b0 `* D - #define IWDG_Prescaler_8 ((uint8_t)0x01)
6 ?' w, [: x4 m7 ^- |$ W- R" D - #define IWDG_Prescaler_16 ((uint8_t)0x02)
* i3 z+ h7 `" V - #define IWDG_Prescaler_32 ((uint8_t)0x03)2 ?/ ], W' r! Q1 ? D3 }' \
- #define IWDG_Prescaler_64 ((uint8_t)0x04)/ B& T/ h) g0 C
- #define IWDG_Prescaler_128 ((uint8_t)0x05)0 L- D" K5 w* ]8 Z
- #define IWDG_Prescaler_256 ((uint8_t)0x06)) C' e8 |' L" B7 q
- #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \
$ M M5 G t- p+ e - ((PRESCALER) == IWDG_Prescaler_8) || \0 U& b, O2 d/ ~: O* N
- ((PRESCALER) == IWDG_Prescaler_16) || \
: M! F$ u1 t5 D# o - ((PRESCALER) == IWDG_Prescaler_32) || \
! D- ]$ b' h! R" n7 ] - ((PRESCALER) == IWDG_Prescaler_64) || \
]# t, Q U1 }; Y - ((PRESCALER) == IWDG_Prescaler_128)|| \
# J) w$ r3 a" K% h0 K& ?( }' @4 z - ((PRESCALER) == IWDG_Prescaler_256))
复制代码 1 [0 d& k# {" b9 i8 Y: F" w
IWDG_Flag- T1 b8 Z& b' n% H
1 R9 O; z7 g& {3 c2 L
- /** @defgroup IWDG_Flag
# p- r4 d( U0 g1 e* I - * @{ M o0 ^+ T8 `) r2 D, X- G3 f
- */
: |4 D: p: n& _ - #define IWDG_FLAG_PVU ((uint16_t)0x0001)
, w% m) q; E1 A( [8 K - #define IWDG_FLAG_RVU ((uint16_t)0x0002)5 J9 J* l9 Y6 I
- #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU))
" H% ?) k2 C1 r# G: N: n - #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF)
复制代码 2 y' L8 g5 ^7 O& I! t+ @9 Z
03. 相关函数
/ h" ?0 n C* Z: _4 ~0 ^- /* Exported macro ------------------------------------------------------------*// R) N( {7 ^+ P1 q
- /* Exported functions --------------------------------------------------------*/8 n1 i4 v, X! n$ e: `
- % P$ Y, A; k* w$ e
- /* Prescaler and Counter configuration functions ******************************/
1 j( @0 v0 r9 X - void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess);
+ [( R) o9 _% Y3 F - void IWDG_SetPrescaler(uint8_t IWDG_Prescaler);( ~" y" [4 |% M2 c! C( |4 t, Z+ z
- void IWDG_SetReload(uint16_t Reload);# @% ^) \6 A5 L, W
- void IWDG_ReloadCounter(void);
; c! O; t9 V8 c: D( c) @
7 x) q2 d( N) ?: Y- /* IWDG activation function ***************************************************/% }, l# h2 t; }; Z" p X
- void IWDG_Enable(void);, k2 k$ t0 b1 o# [
( F, S5 M! J9 a. ]' q& e2 [- /* Flag management function ***************************************************/ z" Z2 x, d+ x5 s& N
- FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG);
复制代码 4 X: \, i4 [. `: T6 a( v
04. 结构体封装6 [; F; D/ c& b+ J( s
- /**
( T2 ^" a8 x- w. g, R - * @brief Independent WATCHDOG
+ x N6 k: o# [5 a7 G9 O - */
4 b5 ^6 H9 p6 e% s5 s2 W - , W( c( m+ a( B3 u( F8 p) ~
- typedef struct/ u. ^4 k9 X- r8 h6 z8 i( f1 v
- {
2 a7 s/ o& w# ~( D/ _1 T6 h0 d - __IO uint32_t KR; /*!< IWDG Key register, Address offset: 0x00 */! i+ _; W1 A3 p% S! U
- __IO uint32_t PR; /*!< IWDG Prescaler register, Address offset: 0x04 */
# `4 L+ I3 d6 x( u - __IO uint32_t RLR; /*!< IWDG Reload register, Address offset: 0x08 */
9 y/ q5 N0 R3 O1 v4 r - __IO uint32_t SR; /*!< IWDG Status register, Address offset: 0x0C */
% b1 D4 ~' n7 Q. T! v, b - } IWDG_TypeDef;
复制代码
% u& m, a! H$ y+ D' U |