Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 6 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | ============================================================================== |
14 | ============================================================================== |
15 | [..] |
15 | [..] |
16 | (+) The IWDG can be started by either software or hardware (configurable |
16 | (+) The IWDG can be started by either software or hardware (configurable |
17 | through option byte). |
17 | through option byte). |
18 | 18 | ||
19 | (+) The IWDG is clocked by Low-Speed clock (LSI) and thus stays active even |
19 | (+) The IWDG is clocked by the Low-Speed Internal clock (LSI) and thus stays |
20 | if the main clock fails. |
20 | active even if the main clock fails. |
21 | 21 | ||
22 | (+) Once the IWDG is started, the LSI is forced ON and both can not be |
22 | (+) Once the IWDG is started, the LSI is forced ON and both cannot be |
23 | disabled. The counter starts counting down from the reset value (0xFFF). |
23 | disabled. The counter starts counting down from the reset value (0xFFF). |
24 | When it reaches the end of count value (0x000) a reset signal is |
24 | When it reaches the end of count value (0x000) a reset signal is |
25 | generated (IWDG reset). |
25 | generated (IWDG reset). |
26 | 26 | ||
27 | (+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register, |
27 | (+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register, |
28 | the IWDG_RLR value is reloaded in the counter and the watchdog reset is |
28 | the IWDG_RLR value is reloaded into the counter and the watchdog reset |
29 | prevented. |
29 | is prevented. |
30 | 30 | ||
31 | (+) The IWDG is implemented in the VDD voltage domain that is still functional |
31 | (+) The IWDG is implemented in the VDD voltage domain that is still functional |
32 | in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY). |
32 | in STOP and STANDBY mode (IWDG reset can wake up the CPU from STANDBY). |
33 | IWDGRST flag in RCC_CSR register can be used to inform when an IWDG |
33 | IWDGRST flag in RCC_CSR register can be used to inform when an IWDG |
34 | reset occurs. |
34 | reset occurs. |
35 | 35 | ||
36 | (+) Debug mode : When the microcontroller enters debug mode (core halted), |
36 | (+) Debug mode: When the microcontroller enters debug mode (core halted), |
37 | the IWDG counter either continues to work normally or stops, depending |
37 | the IWDG counter either continues to work normally or stops, depending |
38 | on DBG_IWDG_STOP configuration bit in DBG module, accessible through |
38 | on DBG_IWDG_STOP configuration bit in DBG module, accessible through |
39 | __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros. |
39 | __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros. |
40 | 40 | ||
41 | [..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s |
41 | [..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s |
42 | The IWDG timeout may vary due to LSI frequency dispersion. STM32F0xx |
42 | The IWDG timeout may vary due to LSI clock frequency dispersion. |
43 | devices provide the capability to measure the LSI frequency (LSI clock |
43 | STM32F0xx devices provide the capability to measure the LSI clock |
44 | connected internally to TIM16 CH1 input capture). The measured value |
44 | frequency (LSI clock is internally connected to TIM16 CH1 input capture). |
45 | can be used to have an IWDG timeout with an acceptable accuracy. |
45 | The measured value can be used to have an IWDG timeout with an |
- | 46 | acceptable accuracy. |
|
- | 47 | ||
- | 48 | [..] Default timeout value (necessary for IWDG_SR status register update): |
|
- | 49 | Constant LSI_VALUE is defined based on the nominal LSI clock frequency. |
|
- | 50 | This frequency being subject to variations as mentioned above, the |
|
- | 51 | default timeout value (defined through constant HAL_IWDG_DEFAULT_TIMEOUT |
|
- | 52 | below) may become too short or too long. |
|
- | 53 | In such cases, this default timeout value can be tuned by redefining |
|
- | 54 | the constant LSI_VALUE at user-application level (based, for instance, |
|
- | 55 | on the measured LSI clock frequency as explained above). |
|
46 | 56 | ||
47 | ##### How to use this driver ##### |
57 | ##### How to use this driver ##### |
48 | ============================================================================== |
58 | ============================================================================== |
49 | [..] |
59 | [..] |
50 | (#) Use IWDG using HAL_IWDG_Init() function to : |
60 | (#) Use IWDG using HAL_IWDG_Init() function to : |
Line 53... | Line 63... | ||
53 | (++) Enable write access to configuration registers: |
63 | (++) Enable write access to configuration registers: |
54 | IWDG_PR, IWDG_RLR and IWDG_WINR. |
64 | IWDG_PR, IWDG_RLR and IWDG_WINR. |
55 | (++) Configure the IWDG prescaler and counter reload value. This reload |
65 | (++) Configure the IWDG prescaler and counter reload value. This reload |
56 | value will be loaded in the IWDG counter each time the watchdog is |
66 | value will be loaded in the IWDG counter each time the watchdog is |
57 | reloaded, then the IWDG will start counting down from this value. |
67 | reloaded, then the IWDG will start counting down from this value. |
58 | (++) Wait for status flags to be reset. |
- | |
59 | (++) Depending on window parameter: |
68 | (++) Depending on window parameter: |
60 | (+++) If Window Init parameter is same as Window register value, |
69 | (+++) If Window Init parameter is same as Window register value, |
61 | nothing more is done but reload counter value in order to exit |
70 | nothing more is done but reload counter value in order to exit |
62 | function with exact time base. |
71 | function with exact time base. |
63 | (+++) Else modify Window register. This will automatically reload |
72 | (+++) Else modify Window register. This will automatically reload |
64 | watchdog counter. |
73 | watchdog counter. |
- | 74 | (++) Wait for status flags to be reset. |
|
65 | 75 | ||
66 | (#) Then the application program must refresh the IWDG counter at regular |
76 | (#) Then the application program must refresh the IWDG counter at regular |
67 | intervals during normal operation to prevent an MCU reset, using |
77 | intervals during normal operation to prevent an MCU reset, using |
68 | HAL_IWDG_Refresh() function. |
78 | HAL_IWDG_Refresh() function. |
69 | 79 | ||
Line 106... | Line 116... | ||
106 | /* Private typedef -----------------------------------------------------------*/ |
116 | /* Private typedef -----------------------------------------------------------*/ |
107 | /* Private define ------------------------------------------------------------*/ |
117 | /* Private define ------------------------------------------------------------*/ |
108 | /** @defgroup IWDG_Private_Defines IWDG Private Defines |
118 | /** @defgroup IWDG_Private_Defines IWDG Private Defines |
109 | * @{ |
119 | * @{ |
110 | */ |
120 | */ |
111 | /* Status register need 5 RC LSI divided by prescaler clock to be updated. With |
121 | /* Status register needs up to 5 LSI clock periods divided by the clock |
112 | higher prescaler (256), and according to LSI variation, we need to wait at |
122 | prescaler to be updated. The number of LSI clock periods is upper-rounded to |
- | 123 | 6 for the timeout value calculation. |
|
- | 124 | The timeout value is calculated using the highest prescaler (256) and |
|
- | 125 | the LSI_VALUE constant. The value of this constant can be changed by the user |
|
- | 126 | to take into account possible LSI clock period variations. |
|
- | 127 | The timeout value is multiplied by 1000 to be converted in milliseconds. |
|
- | 128 | LSI startup time is also considered here by adding LSI_STARTUP_TIMEOUT |
|
113 | least 6 cycles so 48 ms. */ |
129 | converted in milliseconds. */ |
114 | #define HAL_IWDG_DEFAULT_TIMEOUT 48u |
130 | #define HAL_IWDG_DEFAULT_TIMEOUT (((6UL * 256UL * 1000UL) / LSI_VALUE) + ((LSI_STARTUP_TIME / 1000UL) + 1UL)) |
- | 131 | #define IWDG_KERNEL_UPDATE_FLAGS (IWDG_SR_WVU | IWDG_SR_RVU | IWDG_SR_PVU) |
|
115 | /** |
132 | /** |
116 | * @} |
133 | * @} |
117 | */ |
134 | */ |
118 | 135 | ||
119 | /* Private macro -------------------------------------------------------------*/ |
136 | /* Private macro -------------------------------------------------------------*/ |
Line 180... | Line 197... | ||
180 | 197 | ||
181 | /* Check pending flag, if previous update not done, return timeout */ |
198 | /* Check pending flag, if previous update not done, return timeout */ |
182 | tickstart = HAL_GetTick(); |
199 | tickstart = HAL_GetTick(); |
183 | 200 | ||
184 | /* Wait for register to be updated */ |
201 | /* Wait for register to be updated */ |
185 | while (hiwdg->Instance->SR != 0x00u) |
202 | while ((hiwdg->Instance->SR & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u) |
186 | { |
203 | { |
187 | if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT) |
204 | if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT) |
188 | { |
205 | { |
- | 206 | if ((hiwdg->Instance->SR & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u) |
|
- | 207 | { |
|
189 | return HAL_TIMEOUT; |
208 | return HAL_TIMEOUT; |
- | 209 | } |
|
190 | } |
210 | } |
191 | } |
211 | } |
192 | 212 | ||
193 | /* If window parameter is different than current value, modify window |
213 | /* If window parameter is different than current value, modify window |
194 | register */ |
214 | register */ |
Line 207... | Line 227... | ||
207 | 227 | ||
208 | /* Return function status */ |
228 | /* Return function status */ |
209 | return HAL_OK; |
229 | return HAL_OK; |
210 | } |
230 | } |
211 | 231 | ||
- | 232 | ||
212 | /** |
233 | /** |
213 | * @} |
234 | * @} |
214 | */ |
235 | */ |
215 | 236 | ||
216 | 237 | ||
Line 226... | Line 247... | ||
226 | 247 | ||
227 | @endverbatim |
248 | @endverbatim |
228 | * @{ |
249 | * @{ |
229 | */ |
250 | */ |
230 | 251 | ||
231 | - | ||
232 | /** |
252 | /** |
233 | * @brief Refresh the IWDG. |
253 | * @brief Refresh the IWDG. |
234 | * @param hiwdg pointer to a IWDG_HandleTypeDef structure that contains |
254 | * @param hiwdg pointer to a IWDG_HandleTypeDef structure that contains |
235 | * the configuration information for the specified IWDG module. |
255 | * the configuration information for the specified IWDG module. |
236 | * @retval HAL status |
256 | * @retval HAL status |
Line 242... | Line 262... | ||
242 | 262 | ||
243 | /* Return function status */ |
263 | /* Return function status */ |
244 | return HAL_OK; |
264 | return HAL_OK; |
245 | } |
265 | } |
246 | 266 | ||
- | 267 | ||
247 | /** |
268 | /** |
248 | * @} |
269 | * @} |
249 | */ |
270 | */ |
250 | 271 | ||
251 | /** |
272 | /** |