STM32F4xx_HAL_Driver  1.8.3
stm32f4xx_hal_wwdg.c
Go to the documentation of this file.
1 
128 /* Includes ------------------------------------------------------------------*/
129 #include "stm32f4xx_hal.h"
130 
135 #ifdef HAL_WWDG_MODULE_ENABLED
141 /* Private typedef -----------------------------------------------------------*/
142 /* Private define ------------------------------------------------------------*/
143 /* Private macro -------------------------------------------------------------*/
144 /* Private variables ---------------------------------------------------------*/
145 /* Private function prototypes -----------------------------------------------*/
146 /* Exported functions --------------------------------------------------------*/
147 
176 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
177 {
178  /* Check the WWDG handle allocation */
179  if (hwwdg == NULL)
180  {
181  return HAL_ERROR;
182  }
183 
184  /* Check the parameters */
185  assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
186  assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
187  assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
188  assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
189  assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode));
190 
191 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
192  /* Reset Callback pointers */
193  if (hwwdg->EwiCallback == NULL)
194  {
195  hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback;
196  }
197 
198  if (hwwdg->MspInitCallback == NULL)
199  {
200  hwwdg->MspInitCallback = HAL_WWDG_MspInit;
201  }
202 
203  /* Init the low level hardware */
204  hwwdg->MspInitCallback(hwwdg);
205 #else
206  /* Init the low level hardware */
207  HAL_WWDG_MspInit(hwwdg);
208 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
209 
210  /* Set WWDG Counter */
211  WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter));
212 
213  /* Set WWDG Prescaler and Window */
214  WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window));
215 
216  /* Return function status */
217  return HAL_OK;
218 }
219 
220 
231 {
232  /* Prevent unused argument(s) compilation warning */
233  UNUSED(hwwdg);
234 
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
237  */
238 }
239 
240 
241 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
254  pWWDG_CallbackTypeDef pCallback)
255 {
256  HAL_StatusTypeDef status = HAL_OK;
257 
258  if (pCallback == NULL)
259  {
260  status = HAL_ERROR;
261  }
262  else
263  {
264  switch (CallbackID)
265  {
266  case HAL_WWDG_EWI_CB_ID:
267  hwwdg->EwiCallback = pCallback;
268  break;
269 
271  hwwdg->MspInitCallback = pCallback;
272  break;
273 
274  default:
275  status = HAL_ERROR;
276  break;
277  }
278  }
279 
280  return status;
281 }
282 
283 
295 {
296  HAL_StatusTypeDef status = HAL_OK;
297 
298  switch (CallbackID)
299  {
300  case HAL_WWDG_EWI_CB_ID:
301  hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback;
302  break;
303 
305  hwwdg->MspInitCallback = HAL_WWDG_MspInit;
306  break;
307 
308  default:
309  status = HAL_ERROR;
310  break;
311  }
312 
313  return status;
314 }
315 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
316 
343 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
344 {
345  /* Write to WWDG CR the WWDG Counter value to refresh with */
346  WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter));
347 
348  /* Return function status */
349  return HAL_OK;
350 }
351 
367 {
368  /* Check if Early Wakeup Interrupt is enable */
369  if (__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET)
370  {
371  /* Check if WWDG Early Wakeup Interrupt occurred */
372  if (__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET)
373  {
374  /* Clear the WWDG Early Wakeup flag */
375  __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);
376 
377 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
378  /* Early Wakeup registered callback */
379  hwwdg->EwiCallback(hwwdg);
380 #else
381  /* Early Wakeup callback */
383 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
384  }
385  }
386 }
387 
388 
396 {
397  /* Prevent unused argument(s) compilation warning */
398  UNUSED(hwwdg);
399 
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
402  */
403 }
404 
413 #endif /* HAL_WWDG_MODULE_ENABLED */
void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg)
Initialize the WWDG MSP.
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
Initialize the WWDG according to the specified. parameters in the WWDG_InitTypeDef of associated hand...
HAL_StatusTypeDef HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID)
Unregister a WWDG Callback WWDG Callback is redirected to the weak (surcharged) predefined callback.
HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, pWWDG_CallbackTypeDef pCallback)
Register a User WWDG Callback To be used instead of the weak (surcharged) predefined callback.
void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
Handle WWDG interrupt request.
void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg)
WWDG Early Wakeup callback.
HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
Refresh the WWDG.
void(* pWWDG_CallbackTypeDef)(WWDG_HandleTypeDef *hppp)
HAL WWDG Callback pointer definition.
HAL_WWDG_CallbackIDTypeDef
HAL WWDG common Callback ID enumeration definition.
struct __WWDG_HandleTypeDef else typedef struct endif WWDG_HandleTypeDef
WWDG handle Structure definition.
@ HAL_WWDG_EWI_CB_ID
@ HAL_WWDG_MSPINIT_CB_ID
This file contains all the functions prototypes for the HAL module driver.