Rev 56 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 56 | Rev 61 | ||
|---|---|---|---|
| Line 19... | Line 19... | ||
| 19 | 19 | ||
| 20 | (+) An MCU reset is also generated if the counter value is refreshed |
20 | (+) An MCU reset is also generated if the counter value is refreshed |
| 21 | before the counter has reached the refresh window value. This |
21 | before the counter has reached the refresh window value. This |
| 22 | implies that the counter must be refreshed in a limited window. |
22 | implies that the counter must be refreshed in a limited window. |
| 23 | (+) Once enabled the WWDG cannot be disabled except by a system reset. |
23 | (+) Once enabled the WWDG cannot be disabled except by a system reset. |
| - | 24 | (+) If required by application, an Early Wakeup Interrupt can be triggered |
|
| - | 25 | in order to be warned before WWDG expiration. The Early Wakeup Interrupt |
|
| - | 26 | (EWI) can be used if specific safety operations or data logging must |
|
| - | 27 | be performed before the actual reset is generated. When the downcounter |
|
| - | 28 | reaches 0x40, interrupt occurs. This mechanism requires WWDG interrupt |
|
| - | 29 | line to be enabled in NVIC. Once enabled, EWI interrupt cannot be |
|
| - | 30 | disabled except by a system reset. |
|
| 24 | (+) WWDGRST flag in RCC CSR register can be used to inform when a WWDG |
31 | (+) WWDGRST flag in RCC CSR register can be used to inform when a WWDG |
| 25 | reset occurs. |
32 | reset occurs. |
| 26 | (+) The WWDG counter input clock is derived from the APB clock divided |
33 | (+) The WWDG counter input clock is derived from the APB clock divided |
| 27 | by a programmable prescaler. |
34 | by a programmable prescaler. |
| 28 | (+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler) |
35 | (+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler) |
| Line 30... | Line 37... | ||
| 30 | where T[5;0] are the lowest 6 bits of Counter. |
37 | where T[5;0] are the lowest 6 bits of Counter. |
| 31 | (+) WWDG Counter refresh is allowed between the following limits : |
38 | (+) WWDG Counter refresh is allowed between the following limits : |
| 32 | (++) min time (mS) = 1000 * (Counter - Window) / WWDG clock |
39 | (++) min time (mS) = 1000 * (Counter - Window) / WWDG clock |
| 33 | (++) max time (mS) = 1000 * (Counter - 0x40) / WWDG clock |
40 | (++) max time (mS) = 1000 * (Counter - 0x40) / WWDG clock |
| 34 | (+) Typical values: |
41 | (+) Typical values: |
| 35 | (++) Counter min (T[5;0] = 0x00) @32MHz (PCLK1) with zero prescaler: |
42 | (++) Counter min (T[5;0] = 0x00) at 32MHz (PCLK1) with zero prescaler: |
| 36 | max timeout before reset: approximately 41.79µs |
43 | max timeout before reset: approximately 41.79µs |
| 37 | (++) Counter max (T[5;0] = 0x3F) @32MHz (PCLK1) with prescaler dividing by 8: |
44 | (++) Counter max (T[5;0] = 0x3F) at 32MHz (PCLK1) with prescaler |
| - | 45 | dividing by 8: |
|
| 38 | max timeout before reset: approximately 342.38ms |
46 | max timeout before reset: approximately 342.38ms |
| 39 | 47 | ||
| 40 | ============================================================================== |
- | |
| 41 | ##### How to use this driver ##### |
48 | ##### How to use this driver ##### |
| 42 | ============================================================================== |
49 | ============================================================================== |
| 43 | 50 | ||
| 44 | *** Common driver usage *** |
51 | *** Common driver usage *** |
| 45 | =========================== |
52 | =========================== |
| 46 | 53 | ||
| 47 | [..] |
54 | [..] |
| 48 | (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE(). |
55 | (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE(). |
| 49 | (+) Set the WWDG prescaler, refresh window and counter value |
56 | (+) Configure the WWDG prescaler, refresh window value, counter value and early |
| 50 | using HAL_WWDG_Init() function. |
57 | interrupt status using HAL_WWDG_Init() function. This will automatically |
| 51 | (+) Start the WWDG using HAL_WWDG_Start() function. |
58 | enable WWDG and start its downcounter. Time reference can be taken from |
| 52 | When the WWDG is enabled the counter value should be configured to |
59 | function exit. Care must be taken to provide a counter value |
| 53 | a value greater than 0x40 to prevent generating an immediate reset. |
60 | greater than 0x40 to prevent generation of immediate reset. |
| 54 | (+) Optionally you can enable the Early Wakeup Interrupt (EWI) which is |
61 | (+) If the Early Wakeup Interrupt (EWI) feature is enabled, an interrupt is |
| 55 | generated when the counter reaches 0x40, and then start the WWDG using |
62 | generated when the counter reaches 0x40. When HAL_WWDG_IRQHandler is |
| - | 63 | triggered by the interrupt service routine, flag will be automatically |
|
| 56 | HAL_WWDG_Start_IT(). At EWI HAL_WWDG_WakeupCallback is executed and user can |
64 | cleared and HAL_WWDG_WakeupCallback user callback will be executed. User |
| 57 | add his own code by customization of callback HAL_WWDG_WakeupCallback. |
65 | can add his own code by customization of callback HAL_WWDG_WakeupCallback. |
| 58 | Once enabled, EWI interrupt cannot be disabled except by a system reset. |
- | |
| 59 | (+) Then the application program must refresh the WWDG counter at regular |
66 | (+) Then the application program must refresh the WWDG counter at regular |
| 60 | intervals during normal operation to prevent an MCU reset, using |
67 | intervals during normal operation to prevent an MCU reset, using |
| 61 | HAL_WWDG_Refresh() function. This operation must occur only when |
68 | HAL_WWDG_Refresh() function. This operation must occur only when |
| 62 | the counter is lower than the refresh window value already programmed. |
69 | the counter is lower than the refresh window value already programmed. |
| 63 | 70 | ||
| 64 | *** Callback registration *** |
71 | *** Callback registration *** |
| 65 | ============================= |
72 | ============================= |
| 66 | 73 | ||
| 67 | [..] |
74 | [..] |
| 68 | The compilation define USE_HAL_WWDG_REGISTER_CALLBACKS when set to 1 allows |
75 | The compilation define USE_HAL_WWDG_REGISTER_CALLBACKS when set to 1 allows |
| 69 | the user to configure dynamically the driver callbacks. Use Functions |
76 | the user to configure dynamically the driver callbacks. Use Functions |
| 70 | @ref HAL_WWDG_RegisterCallback() to register a user callback. |
77 | HAL_WWDG_RegisterCallback() to register a user callback. |
| 71 | 78 | ||
| 72 | (+) Function @ref HAL_WWDG_RegisterCallback() allows to register following |
79 | (+) Function HAL_WWDG_RegisterCallback() allows to register following |
| 73 | callbacks: |
80 | callbacks: |
| 74 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
81 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
| 75 | (++) MspInitCallback : WWDG MspInit. |
82 | (++) MspInitCallback : WWDG MspInit. |
| 76 | This function takes as parameters the HAL peripheral handle, the Callback ID |
83 | This function takes as parameters the HAL peripheral handle, the Callback ID |
| 77 | and a pointer to the user callback function. |
84 | and a pointer to the user callback function. |
| 78 | 85 | ||
| 79 | (+) Use function @ref HAL_WWDG_UnRegisterCallback() to reset a callback to |
86 | (+) Use function HAL_WWDG_UnRegisterCallback() to reset a callback to |
| 80 | the default weak (surcharged) function. @ref HAL_WWDG_UnRegisterCallback() |
87 | the default weak (surcharged) function. HAL_WWDG_UnRegisterCallback() |
| 81 | takes as parameters the HAL peripheral handle and the Callback ID. |
88 | takes as parameters the HAL peripheral handle and the Callback ID. |
| 82 | This function allows to reset following callbacks: |
89 | This function allows to reset following callbacks: |
| 83 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
90 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
| 84 | (++) MspInitCallback : WWDG MspInit. |
91 | (++) MspInitCallback : WWDG MspInit. |
| 85 | 92 | ||
| 86 | [..] |
93 | [..] |
| 87 | When calling @ref HAL_WWDG_Init function, callbacks are reset to the |
94 | When calling HAL_WWDG_Init function, callbacks are reset to the |
| 88 | corresponding legacy weak (surcharged) functions: |
95 | corresponding legacy weak (surcharged) functions: |
| 89 | @ref HAL_WWDG_EarlyWakeupCallback() and HAL_WWDG_MspInit() only if they have |
96 | HAL_WWDG_EarlyWakeupCallback() and HAL_WWDG_MspInit() only if they have |
| 90 | not been registered before. |
97 | not been registered before. |
| 91 | 98 | ||
| 92 | [..] |
99 | [..] |
| 93 | When compilation define USE_HAL_WWDG_REGISTER_CALLBACKS is set to 0 or |
100 | When compilation define USE_HAL_WWDG_REGISTER_CALLBACKS is set to 0 or |
| 94 | not defined, the callback registering feature is not available |
101 | not defined, the callback registering feature is not available |
| 95 | and weak (surcharged) callbacks are used. |
102 | and weak (surcharged) callbacks are used. |
| 96 | 103 | ||
| 97 | *** WWDG HAL driver macros list *** |
104 | *** WWDG HAL driver macros list *** |
| 98 | =================================== |
105 | =================================== |
| 99 | [..] |
106 | [..] |
| 100 | Below the list of most used macros in WWDG HAL driver. |
107 | Below the list of available macros in WWDG HAL driver. |
| 101 | (+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral |
108 | (+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral |
| 102 | (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status |
109 | (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status |
| 103 | (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags |
110 | (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags |
| 104 | (+) __HAL_WWDG_ENABLE_IT: Enable the WWDG early wakeup interrupt |
111 | (+) __HAL_WWDG_ENABLE_IT: Enable the WWDG early wakeup interrupt |
| 105 | 112 | ||
| Line 196... | Line 203... | ||
| 196 | /* Init the low level hardware */ |
203 | /* Init the low level hardware */ |
| 197 | hwwdg->MspInitCallback(hwwdg); |
204 | hwwdg->MspInitCallback(hwwdg); |
| 198 | #else |
205 | #else |
| 199 | /* Init the low level hardware */ |
206 | /* Init the low level hardware */ |
| 200 | HAL_WWDG_MspInit(hwwdg); |
207 | HAL_WWDG_MspInit(hwwdg); |
| 201 | #endif |
208 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
| 202 | 209 | ||
| 203 | /* Set WWDG Counter */ |
210 | /* Set WWDG Counter */ |
| 204 | WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter)); |
211 | WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter)); |
| 205 | 212 | ||
| 206 | /* Set WWDG Prescaler and Window */ |
213 | /* Set WWDG Prescaler and Window */ |
| Line 241... | Line 248... | ||
| 241 | * @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID |
248 | * @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID |
| 242 | * @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID |
249 | * @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID |
| 243 | * @param pCallback pointer to the Callback function |
250 | * @param pCallback pointer to the Callback function |
| 244 | * @retval status |
251 | * @retval status |
| 245 | */ |
252 | */ |
| 246 | HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, pWWDG_CallbackTypeDef pCallback) |
253 | HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, |
| - | 254 | pWWDG_CallbackTypeDef pCallback) |
|
| 247 | { |
255 | { |
| 248 | HAL_StatusTypeDef status = HAL_OK; |
256 | HAL_StatusTypeDef status = HAL_OK; |
| 249 | 257 | ||
| 250 | if (pCallback == NULL) |
258 | if (pCallback == NULL) |
| 251 | { |
259 | { |
| Line 302... | Line 310... | ||
| 302 | break; |
310 | break; |
| 303 | } |
311 | } |
| 304 | 312 | ||
| 305 | return status; |
313 | return status; |
| 306 | } |
314 | } |
| 307 | #endif |
315 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
| 308 | 316 | ||
| 309 | /** |
317 | /** |
| 310 | * @} |
318 | * @} |
| 311 | */ |
319 | */ |
| 312 | 320 | ||
| Line 370... | Line 378... | ||
| 370 | /* Early Wakeup registered callback */ |
378 | /* Early Wakeup registered callback */ |
| 371 | hwwdg->EwiCallback(hwwdg); |
379 | hwwdg->EwiCallback(hwwdg); |
| 372 | #else |
380 | #else |
| 373 | /* Early Wakeup callback */ |
381 | /* Early Wakeup callback */ |
| 374 | HAL_WWDG_EarlyWakeupCallback(hwwdg); |
382 | HAL_WWDG_EarlyWakeupCallback(hwwdg); |
| 375 | #endif |
383 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
| 376 | } |
384 | } |
| 377 | } |
385 | } |
| 378 | } |
386 | } |
| 379 | 387 | ||
| 380 | 388 | ||