Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 61 | Rev 77 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | ****************************************************************************** |
2 | ****************************************************************************** |
| 3 | * @file stm32l1xx_hal_wwdg.c |
3 | * @file stm32l1xx_hal_wwdg.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @brief WWDG HAL module driver. |
5 | * @brief WWDG HAL module driver. |
| 6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
| 7 | * functionalities of the Window Watchdog (WWDG) peripheral: |
7 | * functionalities of the Window Watchdog (WWDG) peripheral: |
| 8 | * + Initialization and Configuration functions |
8 | * + Initialization and Configuration functions |
| 9 | * + IO operation functions |
9 | * + IO operation functions |
| 10 | @verbatim |
10 | ****************************************************************************** |
| 11 | ============================================================================== |
11 | * @attention |
| 12 | ##### WWDG Specific features ##### |
12 | * |
| 13 | ============================================================================== |
13 | * Copyright (c) 2016 STMicroelectronics. |
| 14 | [..] |
14 | * All rights reserved. |
| 15 | Once enabled the WWDG generates a system reset on expiry of a programmed |
15 | * |
| 16 | time period, unless the program refreshes the counter (T[6;0] downcounter) |
16 | * This software is licensed under terms that can be found in the LICENSE file |
| 17 | before reaching 0x3F value (i.e. a reset is generated when the counter |
17 | * in the root directory of this software component. |
| 18 | value rolls down from 0x40 to 0x3F). |
18 | * If no LICENSE file comes with this software, it is provided AS-IS. |
| 19 | 19 | * |
|
| 20 | (+) An MCU reset is also generated if the counter value is refreshed |
20 | ****************************************************************************** |
| 21 | before the counter has reached the refresh window value. This |
21 | @verbatim |
| 22 | implies that the counter must be refreshed in a limited window. |
22 | ============================================================================== |
| 23 | (+) Once enabled the WWDG cannot be disabled except by a system reset. |
23 | ##### WWDG Specific features ##### |
| 24 | (+) If required by application, an Early Wakeup Interrupt can be triggered |
24 | ============================================================================== |
| 25 | in order to be warned before WWDG expiration. The Early Wakeup Interrupt |
25 | [..] |
| 26 | (EWI) can be used if specific safety operations or data logging must |
26 | Once enabled the WWDG generates a system reset on expiry of a programmed |
| 27 | be performed before the actual reset is generated. When the downcounter |
27 | time period, unless the program refreshes the counter (T[6;0] downcounter) |
| 28 | reaches 0x40, interrupt occurs. This mechanism requires WWDG interrupt |
28 | before reaching 0x3F value (i.e. a reset is generated when the counter |
| 29 | line to be enabled in NVIC. Once enabled, EWI interrupt cannot be |
29 | value rolls down from 0x40 to 0x3F). |
| 30 | disabled except by a system reset. |
30 | |
| 31 | (+) WWDGRST flag in RCC CSR register can be used to inform when a WWDG |
31 | (+) An MCU reset is also generated if the counter value is refreshed |
| 32 | reset occurs. |
32 | before the counter has reached the refresh window value. This |
| 33 | (+) The WWDG counter input clock is derived from the APB clock divided |
33 | implies that the counter must be refreshed in a limited window. |
| 34 | by a programmable prescaler. |
34 | (+) Once enabled the WWDG cannot be disabled except by a system reset. |
| 35 | (+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler) |
35 | (+) If required by application, an Early Wakeup Interrupt can be triggered |
| 36 | (+) WWDG timeout (mS) = 1000 * (T[5;0] + 1) / WWDG clock (Hz) |
36 | in order to be warned before WWDG expiration. The Early Wakeup Interrupt |
| 37 | where T[5;0] are the lowest 6 bits of Counter. |
37 | (EWI) can be used if specific safety operations or data logging must |
| 38 | (+) WWDG Counter refresh is allowed between the following limits : |
38 | be performed before the actual reset is generated. When the downcounter |
| 39 | (++) min time (mS) = 1000 * (Counter - Window) / WWDG clock |
39 | reaches 0x40, interrupt occurs. This mechanism requires WWDG interrupt |
| 40 | (++) max time (mS) = 1000 * (Counter - 0x40) / WWDG clock |
40 | line to be enabled in NVIC. Once enabled, EWI interrupt cannot be |
| 41 | (+) Typical values: |
41 | disabled except by a system reset. |
| 42 | (++) Counter min (T[5;0] = 0x00) at 32MHz (PCLK1) with zero prescaler: |
42 | (+) WWDGRST flag in RCC CSR register can be used to inform when a WWDG |
| 43 | max timeout before reset: approximately 41.79µs |
43 | reset occurs. |
| 44 | (++) Counter max (T[5;0] = 0x3F) at 32MHz (PCLK1) with prescaler |
44 | (+) The WWDG counter input clock is derived from the APB clock divided |
| 45 | dividing by 8: |
45 | by a programmable prescaler. |
| 46 | max timeout before reset: approximately 342.38ms |
46 | (+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler) |
| 47 | 47 | (+) WWDG timeout (mS) = 1000 * (T[5;0] + 1) / WWDG clock (Hz) |
|
| 48 | ##### How to use this driver ##### |
48 | where T[5;0] are the lowest 6 bits of Counter. |
| 49 | ============================================================================== |
49 | (+) WWDG Counter refresh is allowed between the following limits : |
| 50 | 50 | (++) min time (mS) = 1000 * (Counter - Window) / WWDG clock |
|
| 51 | *** Common driver usage *** |
51 | (++) max time (mS) = 1000 * (Counter - 0x40) / WWDG clock |
| 52 | =========================== |
52 | (+) Typical values: |
| 53 | 53 | (++) Counter min (T[5;0] = 0x00) at 32MHz (PCLK1) with zero prescaler: |
|
| 54 | [..] |
54 | max timeout before reset: approximately 41.79us |
| 55 | (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE(). |
55 | (++) Counter max (T[5;0] = 0x3F) at 32MHz (PCLK1) with prescaler |
| 56 | (+) Configure the WWDG prescaler, refresh window value, counter value and early |
56 | dividing by 8: |
| 57 | interrupt status using HAL_WWDG_Init() function. This will automatically |
57 | max timeout before reset: approximately 342.38ms |
| 58 | enable WWDG and start its downcounter. Time reference can be taken from |
58 | |
| 59 | function exit. Care must be taken to provide a counter value |
59 | ##### How to use this driver ##### |
| 60 | greater than 0x40 to prevent generation of immediate reset. |
60 | ============================================================================== |
| 61 | (+) If the Early Wakeup Interrupt (EWI) feature is enabled, an interrupt is |
61 | |
| 62 | generated when the counter reaches 0x40. When HAL_WWDG_IRQHandler is |
62 | *** Common driver usage *** |
| 63 | triggered by the interrupt service routine, flag will be automatically |
63 | =========================== |
| 64 | cleared and HAL_WWDG_WakeupCallback user callback will be executed. User |
64 | |
| 65 | can add his own code by customization of callback HAL_WWDG_WakeupCallback. |
65 | [..] |
| 66 | (+) Then the application program must refresh the WWDG counter at regular |
66 | (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE(). |
| 67 | intervals during normal operation to prevent an MCU reset, using |
67 | (+) Configure the WWDG prescaler, refresh window value, counter value and early |
| 68 | HAL_WWDG_Refresh() function. This operation must occur only when |
68 | interrupt status using HAL_WWDG_Init() function. This will automatically |
| 69 | the counter is lower than the refresh window value already programmed. |
69 | enable WWDG and start its downcounter. Time reference can be taken from |
| 70 | 70 | function exit. Care must be taken to provide a counter value |
|
| 71 | *** Callback registration *** |
71 | greater than 0x40 to prevent generation of immediate reset. |
| 72 | ============================= |
72 | (+) If the Early Wakeup Interrupt (EWI) feature is enabled, an interrupt is |
| 73 | 73 | generated when the counter reaches 0x40. When HAL_WWDG_IRQHandler is |
|
| 74 | [..] |
74 | triggered by the interrupt service routine, flag will be automatically |
| 75 | The compilation define USE_HAL_WWDG_REGISTER_CALLBACKS when set to 1 allows |
75 | cleared and HAL_WWDG_WakeupCallback user callback will be executed. User |
| 76 | the user to configure dynamically the driver callbacks. Use Functions |
76 | can add his own code by customization of callback HAL_WWDG_WakeupCallback. |
| 77 | HAL_WWDG_RegisterCallback() to register a user callback. |
77 | (+) Then the application program must refresh the WWDG counter at regular |
| 78 | 78 | intervals during normal operation to prevent an MCU reset, using |
|
| 79 | (+) Function HAL_WWDG_RegisterCallback() allows to register following |
79 | HAL_WWDG_Refresh() function. This operation must occur only when |
| 80 | callbacks: |
80 | the counter is lower than the refresh window value already programmed. |
| 81 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
81 | |
| 82 | (++) MspInitCallback : WWDG MspInit. |
82 | *** Callback registration *** |
| 83 | This function takes as parameters the HAL peripheral handle, the Callback ID |
83 | ============================= |
| 84 | and a pointer to the user callback function. |
84 | |
| 85 | 85 | [..] |
|
| 86 | (+) Use function HAL_WWDG_UnRegisterCallback() to reset a callback to |
86 | The compilation define USE_HAL_WWDG_REGISTER_CALLBACKS when set to 1 allows |
| 87 | the default weak (surcharged) function. HAL_WWDG_UnRegisterCallback() |
87 | the user to configure dynamically the driver callbacks. Use Functions |
| 88 | takes as parameters the HAL peripheral handle and the Callback ID. |
88 | HAL_WWDG_RegisterCallback() to register a user callback. |
| 89 | This function allows to reset following callbacks: |
89 | |
| 90 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
90 | (+) Function HAL_WWDG_RegisterCallback() allows to register following |
| 91 | (++) MspInitCallback : WWDG MspInit. |
91 | callbacks: |
| 92 | 92 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
|
| 93 | [..] |
93 | (++) MspInitCallback : WWDG MspInit. |
| 94 | When calling HAL_WWDG_Init function, callbacks are reset to the |
94 | This function takes as parameters the HAL peripheral handle, the Callback ID |
| 95 | corresponding legacy weak (surcharged) functions: |
95 | and a pointer to the user callback function. |
| 96 | HAL_WWDG_EarlyWakeupCallback() and HAL_WWDG_MspInit() only if they have |
96 | |
| 97 | not been registered before. |
97 | (+) Use function HAL_WWDG_UnRegisterCallback() to reset a callback to |
| 98 | 98 | the default weak (surcharged) function. HAL_WWDG_UnRegisterCallback() |
|
| 99 | [..] |
99 | takes as parameters the HAL peripheral handle and the Callback ID. |
| 100 | When compilation define USE_HAL_WWDG_REGISTER_CALLBACKS is set to 0 or |
100 | This function allows to reset following callbacks: |
| 101 | not defined, the callback registering feature is not available |
101 | (++) EwiCallback : callback for Early WakeUp Interrupt. |
| 102 | and weak (surcharged) callbacks are used. |
102 | (++) MspInitCallback : WWDG MspInit. |
| 103 | 103 | ||
| 104 | *** WWDG HAL driver macros list *** |
104 | [..] |
| 105 | =================================== |
105 | When calling HAL_WWDG_Init function, callbacks are reset to the |
| 106 | [..] |
106 | corresponding legacy weak (surcharged) functions: |
| 107 | Below the list of available macros in WWDG HAL driver. |
107 | HAL_WWDG_EarlyWakeupCallback() and HAL_WWDG_MspInit() only if they have |
| 108 | (+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral |
108 | not been registered before. |
| 109 | (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status |
109 | |
| 110 | (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags |
110 | [..] |
| 111 | (+) __HAL_WWDG_ENABLE_IT: Enable the WWDG early wakeup interrupt |
111 | When compilation define USE_HAL_WWDG_REGISTER_CALLBACKS is set to 0 or |
| 112 | 112 | not defined, the callback registering feature is not available |
|
| 113 | @endverbatim |
113 | and weak (surcharged) callbacks are used. |
| 114 | ****************************************************************************** |
114 | |
| 115 | * @attention |
115 | *** WWDG HAL driver macros list *** |
| 116 | * |
116 | =================================== |
| 117 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
117 | [..] |
| 118 | * All rights reserved.</center></h2> |
118 | Below the list of available macros in WWDG HAL driver. |
| 119 | * |
119 | (+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral |
| 120 | * This software component is licensed by ST under BSD 3-Clause license, |
120 | (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status |
| 121 | * the "License"; You may not use this file except in compliance with the |
121 | (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags |
| 122 | * License. You may obtain a copy of the License at: |
122 | (+) __HAL_WWDG_ENABLE_IT: Enable the WWDG early wakeup interrupt |
| 123 | * opensource.org/licenses/BSD-3-Clause |
123 | |
| 124 | * |
124 | @endverbatim |
| 125 | ****************************************************************************** |
125 | ****************************************************************************** |
| 126 | */ |
126 | */ |
| 127 | 127 | ||
| 128 | /* Includes ------------------------------------------------------------------*/ |
128 | /* Includes ------------------------------------------------------------------*/ |
| 129 | #include "stm32l1xx_hal.h" |
129 | #include "stm32l1xx_hal.h" |
| 130 | 130 | ||
| 131 | /** @addtogroup STM32L1xx_HAL_Driver |
131 | /** @addtogroup STM32L1xx_HAL_Driver |
| 132 | * @{ |
132 | * @{ |
| 133 | */ |
133 | */ |
| 134 | 134 | ||
| 135 | #ifdef HAL_WWDG_MODULE_ENABLED |
135 | #ifdef HAL_WWDG_MODULE_ENABLED |
| 136 | /** @defgroup WWDG WWDG |
136 | /** @defgroup WWDG WWDG |
| 137 | * @brief WWDG HAL module driver. |
137 | * @brief WWDG HAL module driver. |
| 138 | * @{ |
138 | * @{ |
| 139 | */ |
139 | */ |
| 140 | 140 | ||
| 141 | /* Private typedef -----------------------------------------------------------*/ |
141 | /* Private typedef -----------------------------------------------------------*/ |
| 142 | /* Private define ------------------------------------------------------------*/ |
142 | /* Private define ------------------------------------------------------------*/ |
| 143 | /* Private macro -------------------------------------------------------------*/ |
143 | /* Private macro -------------------------------------------------------------*/ |
| 144 | /* Private variables ---------------------------------------------------------*/ |
144 | /* Private variables ---------------------------------------------------------*/ |
| 145 | /* Private function prototypes -----------------------------------------------*/ |
145 | /* Private function prototypes -----------------------------------------------*/ |
| 146 | /* Exported functions --------------------------------------------------------*/ |
146 | /* Exported functions --------------------------------------------------------*/ |
| 147 | 147 | ||
| 148 | /** @defgroup WWDG_Exported_Functions WWDG Exported Functions |
148 | /** @defgroup WWDG_Exported_Functions WWDG Exported Functions |
| 149 | * @{ |
149 | * @{ |
| 150 | */ |
150 | */ |
| 151 | 151 | ||
| 152 | /** @defgroup WWDG_Exported_Functions_Group1 Initialization and Configuration functions |
152 | /** @defgroup WWDG_Exported_Functions_Group1 Initialization and Configuration functions |
| 153 | * @brief Initialization and Configuration functions. |
153 | * @brief Initialization and Configuration functions. |
| 154 | * |
154 | * |
| 155 | @verbatim |
155 | @verbatim |
| 156 | ============================================================================== |
156 | ============================================================================== |
| 157 | ##### Initialization and Configuration functions ##### |
157 | ##### Initialization and Configuration functions ##### |
| 158 | ============================================================================== |
158 | ============================================================================== |
| 159 | [..] |
159 | [..] |
| 160 | This section provides functions allowing to: |
160 | This section provides functions allowing to: |
| 161 | (+) Initialize and start the WWDG according to the specified parameters |
161 | (+) Initialize and start the WWDG according to the specified parameters |
| 162 | in the WWDG_InitTypeDef of associated handle. |
162 | in the WWDG_InitTypeDef of associated handle. |
| 163 | (+) Initialize the WWDG MSP. |
163 | (+) Initialize the WWDG MSP. |
| 164 | 164 | ||
| 165 | @endverbatim |
165 | @endverbatim |
| 166 | * @{ |
166 | * @{ |
| 167 | */ |
167 | */ |
| 168 | 168 | ||
| 169 | /** |
169 | /** |
| 170 | * @brief Initialize the WWDG according to the specified. |
170 | * @brief Initialize the WWDG according to the specified. |
| 171 | * parameters in the WWDG_InitTypeDef of associated handle. |
171 | * parameters in the WWDG_InitTypeDef of associated handle. |
| 172 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
172 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
| 173 | * the configuration information for the specified WWDG module. |
173 | * the configuration information for the specified WWDG module. |
| 174 | * @retval HAL status |
174 | * @retval HAL status |
| 175 | */ |
175 | */ |
| 176 | HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg) |
176 | HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg) |
| 177 | { |
177 | { |
| 178 | /* Check the WWDG handle allocation */ |
178 | /* Check the WWDG handle allocation */ |
| 179 | if (hwwdg == NULL) |
179 | if (hwwdg == NULL) |
| 180 | { |
180 | { |
| 181 | return HAL_ERROR; |
181 | return HAL_ERROR; |
| 182 | } |
182 | } |
| 183 | 183 | ||
| 184 | /* Check the parameters */ |
184 | /* Check the parameters */ |
| 185 | assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance)); |
185 | assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance)); |
| 186 | assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler)); |
186 | assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler)); |
| 187 | assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window)); |
187 | assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window)); |
| 188 | assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter)); |
188 | assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter)); |
| 189 | assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode)); |
189 | assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode)); |
| 190 | 190 | ||
| 191 | #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) |
191 | #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) |
| 192 | /* Reset Callback pointers */ |
192 | /* Reset Callback pointers */ |
| 193 | if (hwwdg->EwiCallback == NULL) |
193 | if (hwwdg->EwiCallback == NULL) |
| 194 | { |
194 | { |
| 195 | hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback; |
195 | hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback; |
| 196 | } |
196 | } |
| 197 | 197 | ||
| 198 | if (hwwdg->MspInitCallback == NULL) |
198 | if (hwwdg->MspInitCallback == NULL) |
| 199 | { |
199 | { |
| 200 | hwwdg->MspInitCallback = HAL_WWDG_MspInit; |
200 | hwwdg->MspInitCallback = HAL_WWDG_MspInit; |
| 201 | } |
201 | } |
| 202 | 202 | ||
| 203 | /* Init the low level hardware */ |
203 | /* Init the low level hardware */ |
| 204 | hwwdg->MspInitCallback(hwwdg); |
204 | hwwdg->MspInitCallback(hwwdg); |
| 205 | #else |
205 | #else |
| 206 | /* Init the low level hardware */ |
206 | /* Init the low level hardware */ |
| 207 | HAL_WWDG_MspInit(hwwdg); |
207 | HAL_WWDG_MspInit(hwwdg); |
| 208 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
208 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
| 209 | 209 | ||
| 210 | /* Set WWDG Counter */ |
210 | /* Set WWDG Counter */ |
| 211 | WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter)); |
211 | WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter)); |
| 212 | 212 | ||
| 213 | /* Set WWDG Prescaler and Window */ |
213 | /* Set WWDG Prescaler and Window */ |
| 214 | WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window)); |
214 | WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window)); |
| 215 | 215 | ||
| 216 | /* Return function status */ |
216 | /* Return function status */ |
| 217 | return HAL_OK; |
217 | return HAL_OK; |
| 218 | } |
218 | } |
| 219 | 219 | ||
| 220 | 220 | ||
| 221 | /** |
221 | /** |
| 222 | * @brief Initialize the WWDG MSP. |
222 | * @brief Initialize the WWDG MSP. |
| 223 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
223 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
| 224 | * the configuration information for the specified WWDG module. |
224 | * the configuration information for the specified WWDG module. |
| 225 | * @note When rewriting this function in user file, mechanism may be added |
225 | * @note When rewriting this function in user file, mechanism may be added |
| 226 | * to avoid multiple initialize when HAL_WWDG_Init function is called |
226 | * to avoid multiple initialize when HAL_WWDG_Init function is called |
| 227 | * again to change parameters. |
227 | * again to change parameters. |
| 228 | * @retval None |
228 | * @retval None |
| 229 | */ |
229 | */ |
| 230 | __weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg) |
230 | __weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg) |
| 231 | { |
231 | { |
| 232 | /* Prevent unused argument(s) compilation warning */ |
232 | /* Prevent unused argument(s) compilation warning */ |
| 233 | UNUSED(hwwdg); |
233 | UNUSED(hwwdg); |
| 234 | 234 | ||
| 235 | /* NOTE: This function should not be modified, when the callback is needed, |
235 | /* NOTE: This function should not be modified, when the callback is needed, |
| 236 | the HAL_WWDG_MspInit could be implemented in the user file |
236 | the HAL_WWDG_MspInit could be implemented in the user file |
| 237 | */ |
237 | */ |
| 238 | } |
238 | } |
| 239 | 239 | ||
| 240 | 240 | ||
| 241 | #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) |
241 | #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) |
| 242 | /** |
242 | /** |
| 243 | * @brief Register a User WWDG Callback |
243 | * @brief Register a User WWDG Callback |
| 244 | * To be used instead of the weak (surcharged) predefined callback |
244 | * To be used instead of the weak (surcharged) predefined callback |
| 245 | * @param hwwdg WWDG handle |
245 | * @param hwwdg WWDG handle |
| 246 | * @param CallbackID ID of the callback to be registered |
246 | * @param CallbackID ID of the callback to be registered |
| 247 | * This parameter can be one of the following values: |
247 | * This parameter can be one of the following values: |
| 248 | * @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 |
| 249 | * @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID |
249 | * @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID |
| 250 | * @param pCallback pointer to the Callback function |
250 | * @param pCallback pointer to the Callback function |
| 251 | * @retval status |
251 | * @retval status |
| 252 | */ |
252 | */ |
| 253 | HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, |
253 | HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, |
| 254 | pWWDG_CallbackTypeDef pCallback) |
254 | pWWDG_CallbackTypeDef pCallback) |
| 255 | { |
255 | { |
| 256 | HAL_StatusTypeDef status = HAL_OK; |
256 | HAL_StatusTypeDef status = HAL_OK; |
| 257 | 257 | ||
| 258 | if (pCallback == NULL) |
258 | if (pCallback == NULL) |
| 259 | { |
259 | { |
| 260 | status = HAL_ERROR; |
260 | status = HAL_ERROR; |
| 261 | } |
261 | } |
| 262 | else |
262 | else |
| 263 | { |
263 | { |
| 264 | switch (CallbackID) |
264 | switch (CallbackID) |
| 265 | { |
265 | { |
| 266 | case HAL_WWDG_EWI_CB_ID: |
266 | case HAL_WWDG_EWI_CB_ID: |
| 267 | hwwdg->EwiCallback = pCallback; |
267 | hwwdg->EwiCallback = pCallback; |
| 268 | break; |
268 | break; |
| 269 | 269 | ||
| 270 | case HAL_WWDG_MSPINIT_CB_ID: |
270 | case HAL_WWDG_MSPINIT_CB_ID: |
| 271 | hwwdg->MspInitCallback = pCallback; |
271 | hwwdg->MspInitCallback = pCallback; |
| 272 | break; |
272 | break; |
| 273 | 273 | ||
| 274 | default: |
274 | default: |
| 275 | status = HAL_ERROR; |
275 | status = HAL_ERROR; |
| 276 | break; |
276 | break; |
| 277 | } |
277 | } |
| 278 | } |
278 | } |
| 279 | 279 | ||
| 280 | return status; |
280 | return status; |
| 281 | } |
281 | } |
| 282 | 282 | ||
| 283 | 283 | ||
| 284 | /** |
284 | /** |
| 285 | * @brief Unregister a WWDG Callback |
285 | * @brief Unregister a WWDG Callback |
| 286 | * WWDG Callback is redirected to the weak (surcharged) predefined callback |
286 | * WWDG Callback is redirected to the weak (surcharged) predefined callback |
| 287 | * @param hwwdg WWDG handle |
287 | * @param hwwdg WWDG handle |
| 288 | * @param CallbackID ID of the callback to be registered |
288 | * @param CallbackID ID of the callback to be registered |
| 289 | * This parameter can be one of the following values: |
289 | * This parameter can be one of the following values: |
| 290 | * @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID |
290 | * @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID |
| 291 | * @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID |
291 | * @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID |
| 292 | * @retval status |
292 | * @retval status |
| 293 | */ |
293 | */ |
| 294 | HAL_StatusTypeDef HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID) |
294 | HAL_StatusTypeDef HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID) |
| 295 | { |
295 | { |
| 296 | HAL_StatusTypeDef status = HAL_OK; |
296 | HAL_StatusTypeDef status = HAL_OK; |
| 297 | 297 | ||
| 298 | switch (CallbackID) |
298 | switch (CallbackID) |
| 299 | { |
299 | { |
| 300 | case HAL_WWDG_EWI_CB_ID: |
300 | case HAL_WWDG_EWI_CB_ID: |
| 301 | hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback; |
301 | hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback; |
| 302 | break; |
302 | break; |
| 303 | 303 | ||
| 304 | case HAL_WWDG_MSPINIT_CB_ID: |
304 | case HAL_WWDG_MSPINIT_CB_ID: |
| 305 | hwwdg->MspInitCallback = HAL_WWDG_MspInit; |
305 | hwwdg->MspInitCallback = HAL_WWDG_MspInit; |
| 306 | break; |
306 | break; |
| 307 | 307 | ||
| 308 | default: |
308 | default: |
| 309 | status = HAL_ERROR; |
309 | status = HAL_ERROR; |
| 310 | break; |
310 | break; |
| 311 | } |
311 | } |
| 312 | 312 | ||
| 313 | return status; |
313 | return status; |
| 314 | } |
314 | } |
| 315 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
315 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
| 316 | 316 | ||
| 317 | /** |
317 | /** |
| 318 | * @} |
318 | * @} |
| 319 | */ |
319 | */ |
| 320 | 320 | ||
| 321 | /** @defgroup WWDG_Exported_Functions_Group2 IO operation functions |
321 | /** @defgroup WWDG_Exported_Functions_Group2 IO operation functions |
| 322 | * @brief IO operation functions |
322 | * @brief IO operation functions |
| 323 | * |
323 | * |
| 324 | @verbatim |
324 | @verbatim |
| 325 | ============================================================================== |
325 | ============================================================================== |
| 326 | ##### IO operation functions ##### |
326 | ##### IO operation functions ##### |
| 327 | ============================================================================== |
327 | ============================================================================== |
| 328 | [..] |
328 | [..] |
| 329 | This section provides functions allowing to: |
329 | This section provides functions allowing to: |
| 330 | (+) Refresh the WWDG. |
330 | (+) Refresh the WWDG. |
| 331 | (+) Handle WWDG interrupt request and associated function callback. |
331 | (+) Handle WWDG interrupt request and associated function callback. |
| 332 | 332 | ||
| 333 | @endverbatim |
333 | @endverbatim |
| 334 | * @{ |
334 | * @{ |
| 335 | */ |
335 | */ |
| 336 | 336 | ||
| 337 | /** |
337 | /** |
| 338 | * @brief Refresh the WWDG. |
338 | * @brief Refresh the WWDG. |
| 339 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
339 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
| 340 | * the configuration information for the specified WWDG module. |
340 | * the configuration information for the specified WWDG module. |
| 341 | * @retval HAL status |
341 | * @retval HAL status |
| 342 | */ |
342 | */ |
| 343 | HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg) |
343 | HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg) |
| 344 | { |
344 | { |
| 345 | /* Write to WWDG CR the WWDG Counter value to refresh with */ |
345 | /* Write to WWDG CR the WWDG Counter value to refresh with */ |
| 346 | WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter)); |
346 | WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter)); |
| 347 | 347 | ||
| 348 | /* Return function status */ |
348 | /* Return function status */ |
| 349 | return HAL_OK; |
349 | return HAL_OK; |
| 350 | } |
350 | } |
| 351 | 351 | ||
| 352 | /** |
352 | /** |
| 353 | * @brief Handle WWDG interrupt request. |
353 | * @brief Handle WWDG interrupt request. |
| 354 | * @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations |
354 | * @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations |
| 355 | * or data logging must be performed before the actual reset is generated. |
355 | * or data logging must be performed before the actual reset is generated. |
| 356 | * The EWI interrupt is enabled by calling HAL_WWDG_Init function with |
356 | * The EWI interrupt is enabled by calling HAL_WWDG_Init function with |
| 357 | * EWIMode set to WWDG_EWI_ENABLE. |
357 | * EWIMode set to WWDG_EWI_ENABLE. |
| 358 | * When the downcounter reaches the value 0x40, and EWI interrupt is |
358 | * When the downcounter reaches the value 0x40, and EWI interrupt is |
| 359 | * generated and the corresponding Interrupt Service Routine (ISR) can |
359 | * generated and the corresponding Interrupt Service Routine (ISR) can |
| 360 | * be used to trigger specific actions (such as communications or data |
360 | * be used to trigger specific actions (such as communications or data |
| 361 | * logging), before resetting the device. |
361 | * logging), before resetting the device. |
| 362 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
362 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
| 363 | * the configuration information for the specified WWDG module. |
363 | * the configuration information for the specified WWDG module. |
| 364 | * @retval None |
364 | * @retval None |
| 365 | */ |
365 | */ |
| 366 | void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg) |
366 | void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg) |
| 367 | { |
367 | { |
| 368 | /* Check if Early Wakeup Interrupt is enable */ |
368 | /* Check if Early Wakeup Interrupt is enable */ |
| 369 | if (__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET) |
369 | if (__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET) |
| 370 | { |
370 | { |
| 371 | /* Check if WWDG Early Wakeup Interrupt occurred */ |
371 | /* Check if WWDG Early Wakeup Interrupt occurred */ |
| 372 | if (__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET) |
372 | if (__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET) |
| 373 | { |
373 | { |
| 374 | /* Clear the WWDG Early Wakeup flag */ |
374 | /* Clear the WWDG Early Wakeup flag */ |
| 375 | __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF); |
375 | __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF); |
| 376 | 376 | ||
| 377 | #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) |
377 | #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) |
| 378 | /* Early Wakeup registered callback */ |
378 | /* Early Wakeup registered callback */ |
| 379 | hwwdg->EwiCallback(hwwdg); |
379 | hwwdg->EwiCallback(hwwdg); |
| 380 | #else |
380 | #else |
| 381 | /* Early Wakeup callback */ |
381 | /* Early Wakeup callback */ |
| 382 | HAL_WWDG_EarlyWakeupCallback(hwwdg); |
382 | HAL_WWDG_EarlyWakeupCallback(hwwdg); |
| 383 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
383 | #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ |
| 384 | } |
384 | } |
| 385 | } |
385 | } |
| 386 | } |
386 | } |
| 387 | 387 | ||
| 388 | 388 | ||
| 389 | /** |
389 | /** |
| 390 | * @brief WWDG Early Wakeup callback. |
390 | * @brief WWDG Early Wakeup callback. |
| 391 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
391 | * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains |
| 392 | * the configuration information for the specified WWDG module. |
392 | * the configuration information for the specified WWDG module. |
| 393 | * @retval None |
393 | * @retval None |
| 394 | */ |
394 | */ |
| 395 | __weak void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg) |
395 | __weak void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg) |
| 396 | { |
396 | { |
| 397 | /* Prevent unused argument(s) compilation warning */ |
397 | /* Prevent unused argument(s) compilation warning */ |
| 398 | UNUSED(hwwdg); |
398 | UNUSED(hwwdg); |
| 399 | 399 | ||
| 400 | /* NOTE: This function should not be modified, when the callback is needed, |
400 | /* NOTE: This function should not be modified, when the callback is needed, |
| 401 | the HAL_WWDG_EarlyWakeupCallback could be implemented in the user file |
401 | the HAL_WWDG_EarlyWakeupCallback could be implemented in the user file |
| 402 | */ |
402 | */ |
| 403 | } |
403 | } |
| 404 | 404 | ||
| 405 | /** |
405 | /** |
| 406 | * @} |
406 | * @} |
| 407 | */ |
407 | */ |
| 408 | 408 | ||
| 409 | /** |
409 | /** |
| 410 | * @} |
410 | * @} |
| 411 | */ |
411 | */ |
| 412 | 412 | ||
| 413 | #endif /* HAL_WWDG_MODULE_ENABLED */ |
413 | #endif /* HAL_WWDG_MODULE_ENABLED */ |
| 414 | /** |
414 | /** |
| 415 | * @} |
415 | * @} |
| 416 | */ |
416 | */ |
| 417 | 417 | ||
| 418 | /** |
418 | /** |
| 419 | * @} |
419 | * @} |
| 420 | */ |
420 | */ |
| 421 | - | ||
| 422 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
- | |