2018-03-31 16:34:59 +03:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @file stm32f1xx_hal_wwdg.c
|
|
|
|
* @author MCD Application Team
|
|
|
|
* @brief WWDG HAL module driver.
|
2019-07-22 03:29:14 +03:00
|
|
|
* This file provides firmware functions to manage the following
|
2018-03-31 16:34:59 +03:00
|
|
|
* functionalities of the Window Watchdog (WWDG) peripheral:
|
|
|
|
* + Initialization and de-initialization functions
|
|
|
|
* + IO operation functions
|
|
|
|
* + Peripheral State functions
|
|
|
|
@verbatim
|
|
|
|
==============================================================================
|
|
|
|
##### WWDG specific features #####
|
|
|
|
==============================================================================
|
2019-07-22 03:29:14 +03:00
|
|
|
[..]
|
2018-03-31 16:34:59 +03:00
|
|
|
Once enabled the WWDG generates a system reset on expiry of a programmed
|
2019-07-22 03:29:14 +03:00
|
|
|
time period, unless the program refreshes the counter (downcounter)
|
2018-03-31 16:34:59 +03:00
|
|
|
before reaching 0x3F value (i.e. a reset is generated when the counter
|
2019-07-22 03:29:14 +03:00
|
|
|
value rolls over from 0x40 to 0x3F).
|
|
|
|
|
2018-03-31 16:34:59 +03:00
|
|
|
(+) An MCU reset is also generated if the counter value is refreshed
|
2019-07-22 03:29:14 +03:00
|
|
|
before the counter has reached the refresh window value. This
|
2018-03-31 16:34:59 +03:00
|
|
|
implies that the counter must be refreshed in a limited window.
|
|
|
|
(+) Once enabled the WWDG cannot be disabled except by a system reset.
|
|
|
|
(+) WWDGRST flag in RCC_CSR register can be used to inform when a WWDG
|
2019-07-22 03:29:14 +03:00
|
|
|
reset occurs.
|
|
|
|
(+) The WWDG counter input clock is derived from the APB clock divided
|
2018-03-31 16:34:59 +03:00
|
|
|
by a programmable prescaler.
|
|
|
|
(+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler)
|
|
|
|
(+) WWDG timeout (mS) = 1000 * Counter / WWDG clock
|
|
|
|
(+) WWDG Counter refresh is allowed between the following limits :
|
|
|
|
(++) min time (mS) = 1000 * (Counter _ Window) / WWDG clock
|
|
|
|
(++) max time (mS) = 1000 * (Counter _ 0x40) / WWDG clock
|
|
|
|
|
2019-07-22 03:29:14 +03:00
|
|
|
(+) Min-max timeout value at 36 MHz(PCLK1): 910 us / 58.25 ms
|
|
|
|
|
|
|
|
(+) The Early Wakeup Interrupt (EWI) can be used if specific safety
|
2018-03-31 16:34:59 +03:00
|
|
|
operations or data logging must be performed before the actual reset is
|
|
|
|
generated. When the downcounter reaches the value 0x40, an EWI interrupt
|
2019-07-22 03:29:14 +03:00
|
|
|
is generated and the corresponding interrupt service routine (ISR) can
|
|
|
|
be used to trigger specific actions (such as communications or data
|
2018-03-31 16:34:59 +03:00
|
|
|
logging), before resetting the device.
|
|
|
|
In some applications, the EWI interrupt can be used to manage a software
|
2019-07-22 03:29:14 +03:00
|
|
|
system check and/or system recovery/graceful degradation, without
|
|
|
|
generating a WWDG reset. In this case, the corresponding interrupt
|
|
|
|
service routine (ISR) should reload the WWDG counter to avoid the WWDG
|
2018-03-31 16:34:59 +03:00
|
|
|
reset, then trigger the required actions.
|
2019-07-22 03:29:14 +03:00
|
|
|
Note:When the EWI interrupt cannot be served, e.g. due to a system lock
|
2018-03-31 16:34:59 +03:00
|
|
|
in a higher priority task, the WWDG reset will eventually be generated.
|
|
|
|
|
|
|
|
(+) Debug mode : When the microcontroller enters debug mode (core halted),
|
2019-07-22 03:29:14 +03:00
|
|
|
the WWDG counter either continues to work normally or stops, depending
|
2018-03-31 16:34:59 +03:00
|
|
|
on DBG_WWDG_STOP configuration bit in DBG module, accessible through
|
|
|
|
__HAL_DBGMCU_FREEZE_WWDG() and __HAL_DBGMCU_UNFREEZE_WWDG() macros
|
|
|
|
|
|
|
|
##### How to use this driver #####
|
|
|
|
==============================================================================
|
|
|
|
[..]
|
|
|
|
(+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE().
|
|
|
|
|
2019-07-22 03:29:14 +03:00
|
|
|
(+) Set the WWDG prescaler, refresh window, counter value and Early Wakeup
|
2018-03-31 16:34:59 +03:00
|
|
|
Interrupt mode using using HAL_WWDG_Init() function.
|
2019-07-22 03:29:14 +03:00
|
|
|
This enables WWDG peripheral and the downcounter starts downcounting
|
2018-03-31 16:34:59 +03:00
|
|
|
from given counter value.
|
2019-07-22 03:29:14 +03:00
|
|
|
Init function can be called again to modify all watchdog parameters,
|
|
|
|
however if EWI mode has been set once, it can't be clear until next
|
2018-03-31 16:34:59 +03:00
|
|
|
reset.
|
|
|
|
|
|
|
|
(+) The application program must refresh the WWDG counter at regular
|
|
|
|
intervals during normal operation to prevent an MCU reset using
|
|
|
|
HAL_WWDG_Refresh() function. This operation must occur only when
|
|
|
|
the counter is lower than the window value already programmed.
|
|
|
|
|
2019-07-22 03:29:14 +03:00
|
|
|
(+) if Early Wakeup Interrupt mode is enable an interrupt is generated when
|
|
|
|
the counter reaches 0x40. User can add his own code in weak function
|
2018-03-31 16:34:59 +03:00
|
|
|
HAL_WWDG_EarlyWakeupCallback().
|
|
|
|
|
|
|
|
*** WWDG HAL driver macros list ***
|
|
|
|
==================================
|
|
|
|
[..]
|
|
|
|
Below the list of most used macros in WWDG HAL driver.
|
|
|
|
|
|
|
|
(+) __HAL_WWDG_GET_IT_SOURCE: Check the selected WWDG's interrupt source.
|
|
|
|
(+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status.
|
|
|
|
(+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags.
|
|
|
|
|
|
|
|
@endverbatim
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
2019-07-22 03:29:14 +03:00
|
|
|
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
|
|
|
* All rights reserved.</center></h2>
|
2018-03-31 16:34:59 +03:00
|
|
|
*
|
2019-07-22 03:29:14 +03:00
|
|
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|
|
|
* the "License"; You may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at:
|
|
|
|
* opensource.org/licenses/BSD-3-Clause
|
2018-03-31 16:34:59 +03:00
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "stm32f1xx_hal.h"
|
|
|
|
|
|
|
|
/** @addtogroup STM32F1xx_HAL_Driver
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAL_WWDG_MODULE_ENABLED
|
|
|
|
/** @defgroup WWDG WWDG
|
|
|
|
* @brief WWDG HAL module driver.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* Exported functions --------------------------------------------------------*/
|
|
|
|
|
|
|
|
/** @defgroup WWDG_Exported_Functions WWDG Exported Functions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @defgroup WWDG_Exported_Functions_Group1 Initialization and Configuration functions
|
|
|
|
* @brief Initialization and Configuration functions.
|
|
|
|
*
|
|
|
|
@verbatim
|
|
|
|
==============================================================================
|
|
|
|
##### Initialization and Configuration functions #####
|
|
|
|
==============================================================================
|
2019-07-22 03:29:14 +03:00
|
|
|
[..]
|
2018-03-31 16:34:59 +03:00
|
|
|
This section provides functions allowing to:
|
|
|
|
(+) Initialize and start the WWDG according to the specified parameters
|
|
|
|
in the WWDG_InitTypeDef of associated handle.
|
|
|
|
(+) Initialize the WWDG MSP.
|
|
|
|
|
|
|
|
@endverbatim
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the WWDG according to the specified.
|
|
|
|
* parameters in the WWDG_InitTypeDef of associated handle.
|
|
|
|
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
|
|
|
* the configuration information for the specified WWDG module.
|
|
|
|
* @retval HAL status
|
|
|
|
*/
|
|
|
|
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
|
|
|
|
{
|
|
|
|
/* Check the WWDG handle allocation */
|
2019-07-22 03:29:14 +03:00
|
|
|
if (hwwdg == NULL)
|
2018-03-31 16:34:59 +03:00
|
|
|
{
|
|
|
|
return HAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the parameters */
|
|
|
|
assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
|
|
|
|
assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
|
|
|
|
assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
|
|
|
|
assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
|
|
|
|
assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode));
|
|
|
|
|
2019-07-22 03:29:14 +03:00
|
|
|
#if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
|
|
|
|
/* Reset Callback pointers */
|
|
|
|
if(hwwdg->EwiCallback == NULL)
|
|
|
|
{
|
|
|
|
hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hwwdg->MspInitCallback == NULL)
|
|
|
|
{
|
|
|
|
hwwdg->MspInitCallback = HAL_WWDG_MspInit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init the low level hardware */
|
|
|
|
hwwdg->MspInitCallback(hwwdg);
|
|
|
|
#else
|
2018-03-31 16:34:59 +03:00
|
|
|
/* Init the low level hardware */
|
|
|
|
HAL_WWDG_MspInit(hwwdg);
|
2019-07-22 03:29:14 +03:00
|
|
|
#endif
|
2018-03-31 16:34:59 +03:00
|
|
|
|
|
|
|
/* Set WWDG Counter */
|
|
|
|
WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter));
|
|
|
|
|
|
|
|
/* Set WWDG Prescaler and Window */
|
|
|
|
WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window));
|
|
|
|
|
|
|
|
/* Return function status */
|
|
|
|
return HAL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the WWDG MSP.
|
|
|
|
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
|
|
|
* the configuration information for the specified WWDG module.
|
|
|
|
* @note When rewriting this function in user file, mechanism may be added
|
|
|
|
* to avoid multiple initialize when HAL_WWDG_Init function is called
|
|
|
|
* again to change parameters.
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
__weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg)
|
|
|
|
{
|
|
|
|
/* Prevent unused argument(s) compilation warning */
|
|
|
|
UNUSED(hwwdg);
|
|
|
|
|
|
|
|
/* NOTE: This function should not be modified, when the callback is needed,
|
|
|
|
the HAL_WWDG_MspInit could be implemented in the user file
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2019-07-22 03:29:14 +03:00
|
|
|
|
|
|
|
#if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
|
|
|
|
/**
|
|
|
|
* @brief Register a User WWDG Callback
|
|
|
|
* To be used instead of the weak (surcharged) predefined callback
|
|
|
|
* @param hwwdg WWDG handle
|
|
|
|
* @param CallbackID ID of the callback to be registered
|
|
|
|
* This parameter can be one of the following values:
|
|
|
|
* @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID
|
|
|
|
* @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID
|
|
|
|
* @param pCallback pointer to the Callback function
|
|
|
|
* @retval status
|
|
|
|
*/
|
|
|
|
HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, pWWDG_CallbackTypeDef pCallback)
|
|
|
|
{
|
|
|
|
HAL_StatusTypeDef status = HAL_OK;
|
|
|
|
|
|
|
|
if(pCallback == NULL)
|
|
|
|
{
|
|
|
|
status = HAL_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(CallbackID)
|
|
|
|
{
|
|
|
|
case HAL_WWDG_EWI_CB_ID:
|
|
|
|
hwwdg->EwiCallback = pCallback;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HAL_WWDG_MSPINIT_CB_ID:
|
|
|
|
hwwdg->MspInitCallback = pCallback;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
status = HAL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unregister a WWDG Callback
|
|
|
|
* WWDG Callback is redirected to the weak (surcharged) predefined callback
|
|
|
|
* @param hwwdg WWDG handle
|
|
|
|
* @param CallbackID ID of the callback to be registered
|
|
|
|
* This parameter can be one of the following values:
|
|
|
|
* @arg @ref HAL_WWDG_EWI_CB_ID Early WakeUp Interrupt Callback ID
|
|
|
|
* @arg @ref HAL_WWDG_MSPINIT_CB_ID MspInit callback ID
|
|
|
|
* @retval status
|
|
|
|
*/
|
|
|
|
HAL_StatusTypeDef HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID)
|
|
|
|
{
|
|
|
|
HAL_StatusTypeDef status = HAL_OK;
|
|
|
|
|
|
|
|
switch(CallbackID)
|
|
|
|
{
|
|
|
|
case HAL_WWDG_EWI_CB_ID:
|
|
|
|
hwwdg->EwiCallback = HAL_WWDG_EarlyWakeupCallback;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HAL_WWDG_MSPINIT_CB_ID:
|
|
|
|
hwwdg->MspInitCallback = HAL_WWDG_MspInit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
status = HAL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-31 16:34:59 +03:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @defgroup WWDG_Exported_Functions_Group2 IO operation functions
|
2019-07-22 03:29:14 +03:00
|
|
|
* @brief IO operation functions
|
2018-03-31 16:34:59 +03:00
|
|
|
*
|
|
|
|
@verbatim
|
|
|
|
==============================================================================
|
|
|
|
##### IO operation functions #####
|
2019-07-22 03:29:14 +03:00
|
|
|
==============================================================================
|
2018-03-31 16:34:59 +03:00
|
|
|
[..]
|
|
|
|
This section provides functions allowing to:
|
|
|
|
(+) Refresh the WWDG.
|
|
|
|
(+) Handle WWDG interrupt request and associated function callback.
|
|
|
|
|
|
|
|
@endverbatim
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Refresh the WWDG.
|
|
|
|
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
|
|
|
* the configuration information for the specified WWDG module.
|
|
|
|
* @retval HAL status
|
|
|
|
*/
|
|
|
|
HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
|
|
|
|
{
|
|
|
|
/* Write to WWDG CR the WWDG Counter value to refresh with */
|
|
|
|
WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter));
|
|
|
|
|
|
|
|
/* Return function status */
|
|
|
|
return HAL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Handle WWDG interrupt request.
|
|
|
|
* @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations
|
|
|
|
* or data logging must be performed before the actual reset is generated.
|
2019-07-22 03:29:14 +03:00
|
|
|
* The EWI interrupt is enabled by calling HAL_WWDG_Init function with
|
2018-03-31 16:34:59 +03:00
|
|
|
* EWIMode set to WWDG_EWI_ENABLE.
|
|
|
|
* When the downcounter reaches the value 0x40, and EWI interrupt is
|
|
|
|
* generated and the corresponding Interrupt Service Routine (ISR) can
|
|
|
|
* be used to trigger specific actions (such as communications or data
|
|
|
|
* logging), before resetting the device.
|
|
|
|
* @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
|
|
|
|
* the configuration information for the specified WWDG module.
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
|
|
|
|
{
|
|
|
|
/* Check if Early Wakeup Interrupt is enable */
|
2019-07-22 03:29:14 +03:00
|
|
|
if (__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET)
|
2018-03-31 16:34:59 +03:00
|
|
|
{
|
|
|
|
/* Check if WWDG Early Wakeup Interrupt occurred */
|
2019-07-22 03:29:14 +03:00
|
|
|
if (__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET)
|
2018-03-31 16:34:59 +03:00
|
|
|
{
|
|
|
|
/* Clear the WWDG Early Wakeup flag */
|
|
|
|
__HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);
|
|
|
|
|
2019-07-22 03:29:14 +03:00
|
|
|
#if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
|
|
|
|
/* Early Wakeup registered callback */
|
|
|
|
hwwdg->EwiCallback(hwwdg);
|
|
|
|
#else
|
|
|
|
/* Early Wakeup callback */
|
2018-03-31 16:34:59 +03:00
|
|
|
HAL_WWDG_EarlyWakeupCallback(hwwdg);
|
2019-07-22 03:29:14 +03:00
|
|
|
#endif
|
2018-03-31 16:34:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief WWDG Early Wakeup callback.
|
|
|
|
* @param hwwdg : pointer to a WWDG_HandleTypeDef structure that contains
|
|
|
|
* the configuration information for the specified WWDG module.
|
|
|
|
* @retval None
|
|
|
|
*/
|
2019-07-22 03:29:14 +03:00
|
|
|
__weak void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg)
|
2018-03-31 16:34:59 +03:00
|
|
|
{
|
|
|
|
/* Prevent unused argument(s) compilation warning */
|
|
|
|
UNUSED(hwwdg);
|
|
|
|
|
|
|
|
/* NOTE: This function should not be modified, when the callback is needed,
|
|
|
|
the HAL_WWDG_EarlyWakeupCallback could be implemented in the user file
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif /* HAL_WWDG_MODULE_ENABLED */
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|