mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
bogdanm
Date:
Thu Oct 01 15:25:22 2015 +0300
Revision:
0:9b334a45a8ff
Child:
144:ef7eb2e8f9f7
Initial commit on mbed-dev

Replaces mbed-src (now inactive)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 0:9b334a45a8ff 1 /**
bogdanm 0:9b334a45a8ff 2 ******************************************************************************
bogdanm 0:9b334a45a8ff 3 * @file stm32f0xx_hal_wwdg.c
bogdanm 0:9b334a45a8ff 4 * @author MCD Application Team
bogdanm 0:9b334a45a8ff 5 * @version V1.3.0
bogdanm 0:9b334a45a8ff 6 * @date 26-June-2015
bogdanm 0:9b334a45a8ff 7 * @brief WWDG HAL module driver.
bogdanm 0:9b334a45a8ff 8 * This file provides firmware functions to manage the following
bogdanm 0:9b334a45a8ff 9 * functionalities of the Window Watchdog (WWDG) peripheral:
bogdanm 0:9b334a45a8ff 10 * + Initialization and de-initialization functions
bogdanm 0:9b334a45a8ff 11 * + IO operation functions
bogdanm 0:9b334a45a8ff 12 * + Peripheral State functions
bogdanm 0:9b334a45a8ff 13 @verbatim
bogdanm 0:9b334a45a8ff 14 ==============================================================================
bogdanm 0:9b334a45a8ff 15 ##### WWDG specific features #####
bogdanm 0:9b334a45a8ff 16 ==============================================================================
bogdanm 0:9b334a45a8ff 17 [..]
bogdanm 0:9b334a45a8ff 18 Once enabled the WWDG generates a system reset on expiry of a programmed
bogdanm 0:9b334a45a8ff 19 time period, unless the program refreshes the counter (T[6;0] downcounter)
bogdanm 0:9b334a45a8ff 20 before reaching 0x3F value (i.e. a reset is generated when the counter
bogdanm 0:9b334a45a8ff 21 value rolls over from 0x40 to 0x3F).
bogdanm 0:9b334a45a8ff 22
bogdanm 0:9b334a45a8ff 23 (+) An MCU reset is also generated if the counter value is refreshed
bogdanm 0:9b334a45a8ff 24 before the counter has reached the refresh window value. This
bogdanm 0:9b334a45a8ff 25 implies that the counter must be refreshed in a limited window.
bogdanm 0:9b334a45a8ff 26 (+) Once enabled the WWDG cannot be disabled except by a system reset.
bogdanm 0:9b334a45a8ff 27 (+) WWDGRST flag in RCC_CSR register informs when a WWDG reset has
bogdanm 0:9b334a45a8ff 28 occurred (check available with __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)).
bogdanm 0:9b334a45a8ff 29 (+) The WWDG counter input clock is derived from the APB clock divided
bogdanm 0:9b334a45a8ff 30 by a programmable prescaler.
bogdanm 0:9b334a45a8ff 31 (+) WWDG clock (Hz) = PCLK / (4096 * Prescaler)
bogdanm 0:9b334a45a8ff 32 (+) WWDG timeout (mS) = 1000 * (T[5;0] + 1) / WWDG clock
bogdanm 0:9b334a45a8ff 33 where T[5;0] are the lowest 6 bits of Counter.
bogdanm 0:9b334a45a8ff 34 (+) WWDG Counter refresh is allowed between the following limits :
bogdanm 0:9b334a45a8ff 35 (++) min time (mS) = 1000 * (Counter-Window) / WWDG clock
bogdanm 0:9b334a45a8ff 36 (++) max time (mS) = 1000 * (Counter-0x40) / WWDG clock
bogdanm 0:9b334a45a8ff 37 (+) Min-max timeout value @48 MHz(PCLK): ~85,3us / ~5,46 ms
bogdanm 0:9b334a45a8ff 38
bogdanm 0:9b334a45a8ff 39 ##### How to use this driver #####
bogdanm 0:9b334a45a8ff 40 ===============================================================================
bogdanm 0:9b334a45a8ff 41 [..]
bogdanm 0:9b334a45a8ff 42 (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE().
bogdanm 0:9b334a45a8ff 43 (+) Set the WWDG prescaler, refresh window and counter value
bogdanm 0:9b334a45a8ff 44 using HAL_WWDG_Init() function.
bogdanm 0:9b334a45a8ff 45 (+) Start the WWDG using HAL_WWDG_Start() function.
bogdanm 0:9b334a45a8ff 46 When the WWDG is enabled the counter value should be configured to
bogdanm 0:9b334a45a8ff 47 a value greater than 0x40 to prevent generating an immediate reset.
bogdanm 0:9b334a45a8ff 48 (+) Optionally you can enable the Early Wakeup Interrupt (EWI) which is
bogdanm 0:9b334a45a8ff 49 generated when the counter reaches 0x40, and then start the WWDG using
bogdanm 0:9b334a45a8ff 50 HAL_WWDG_Start_IT(). At EWI HAL_WWDG_WakeupCallback() is executed and user can
bogdanm 0:9b334a45a8ff 51 add his own code by customization of function pointer HAL_WWDG_WakeupCallback().
bogdanm 0:9b334a45a8ff 52 Once enabled, EWI interrupt cannot be disabled except by a system reset.
bogdanm 0:9b334a45a8ff 53 (+) The application program must refresh the WWDG counter at regular
bogdanm 0:9b334a45a8ff 54 intervals during normal operation to prevent an MCU reset using
bogdanm 0:9b334a45a8ff 55 HAL_WWDG_Refresh() function. This operation must occur only when
bogdanm 0:9b334a45a8ff 56 the counter is lower than the refresh window value already programmed.
bogdanm 0:9b334a45a8ff 57
bogdanm 0:9b334a45a8ff 58 *** WWDG HAL driver macros list ***
bogdanm 0:9b334a45a8ff 59 ==================================
bogdanm 0:9b334a45a8ff 60 [..]
bogdanm 0:9b334a45a8ff 61 Below the list of most used macros in WWDG HAL driver.
bogdanm 0:9b334a45a8ff 62
bogdanm 0:9b334a45a8ff 63 (+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral
bogdanm 0:9b334a45a8ff 64 (+) __HAL_WWDG_ENABLE_IT: Enable the WWDG early wakeup interrupt
bogdanm 0:9b334a45a8ff 65 (+) __HAL_WWDG_GET_IT_SOURCE: Check the selected WWDG's interrupt source
bogdanm 0:9b334a45a8ff 66 (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status
bogdanm 0:9b334a45a8ff 67 (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags
bogdanm 0:9b334a45a8ff 68
bogdanm 0:9b334a45a8ff 69 @endverbatim
bogdanm 0:9b334a45a8ff 70 ******************************************************************************
bogdanm 0:9b334a45a8ff 71 * @attention
bogdanm 0:9b334a45a8ff 72 *
bogdanm 0:9b334a45a8ff 73 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
bogdanm 0:9b334a45a8ff 74 *
bogdanm 0:9b334a45a8ff 75 * Redistribution and use in source and binary forms, with or without modification,
bogdanm 0:9b334a45a8ff 76 * are permitted provided that the following conditions are met:
bogdanm 0:9b334a45a8ff 77 * 1. Redistributions of source code must retain the above copyright notice,
bogdanm 0:9b334a45a8ff 78 * this list of conditions and the following disclaimer.
bogdanm 0:9b334a45a8ff 79 * 2. Redistributions in binary form must reproduce the above copyright notice,
bogdanm 0:9b334a45a8ff 80 * this list of conditions and the following disclaimer in the documentation
bogdanm 0:9b334a45a8ff 81 * and/or other materials provided with the distribution.
bogdanm 0:9b334a45a8ff 82 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bogdanm 0:9b334a45a8ff 83 * may be used to endorse or promote products derived from this software
bogdanm 0:9b334a45a8ff 84 * without specific prior written permission.
bogdanm 0:9b334a45a8ff 85 *
bogdanm 0:9b334a45a8ff 86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bogdanm 0:9b334a45a8ff 87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bogdanm 0:9b334a45a8ff 88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bogdanm 0:9b334a45a8ff 89 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bogdanm 0:9b334a45a8ff 90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bogdanm 0:9b334a45a8ff 91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bogdanm 0:9b334a45a8ff 92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bogdanm 0:9b334a45a8ff 93 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bogdanm 0:9b334a45a8ff 94 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bogdanm 0:9b334a45a8ff 95 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bogdanm 0:9b334a45a8ff 96 *
bogdanm 0:9b334a45a8ff 97 ******************************************************************************
bogdanm 0:9b334a45a8ff 98 */
bogdanm 0:9b334a45a8ff 99
bogdanm 0:9b334a45a8ff 100 /* Includes ------------------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 101 #include "stm32f0xx_hal.h"
bogdanm 0:9b334a45a8ff 102
bogdanm 0:9b334a45a8ff 103 /** @addtogroup STM32F0xx_HAL_Driver
bogdanm 0:9b334a45a8ff 104 * @{
bogdanm 0:9b334a45a8ff 105 */
bogdanm 0:9b334a45a8ff 106
bogdanm 0:9b334a45a8ff 107 /** @defgroup WWDG WWDG
bogdanm 0:9b334a45a8ff 108 * @brief WWDG HAL module driver.
bogdanm 0:9b334a45a8ff 109 * @{
bogdanm 0:9b334a45a8ff 110 */
bogdanm 0:9b334a45a8ff 111
bogdanm 0:9b334a45a8ff 112 #ifdef HAL_WWDG_MODULE_ENABLED
bogdanm 0:9b334a45a8ff 113
bogdanm 0:9b334a45a8ff 114 /* Private typedef -----------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 115 /* Private define ------------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 116 /* Private macro -------------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 117 /* Private variables ---------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 118 /* Private function prototypes -----------------------------------------------*/
bogdanm 0:9b334a45a8ff 119 /* Exported functions --------------------------------------------------------*/
bogdanm 0:9b334a45a8ff 120
bogdanm 0:9b334a45a8ff 121 /** @defgroup WWDG_Exported_Functions WWDG Exported Functions
bogdanm 0:9b334a45a8ff 122 * @{
bogdanm 0:9b334a45a8ff 123 */
bogdanm 0:9b334a45a8ff 124
bogdanm 0:9b334a45a8ff 125 /** @defgroup WWDG_Exported_Functions_Group1 Initialization and de-initialization functions
bogdanm 0:9b334a45a8ff 126 * @brief Initialization and Configuration functions.
bogdanm 0:9b334a45a8ff 127 *
bogdanm 0:9b334a45a8ff 128 @verbatim
bogdanm 0:9b334a45a8ff 129 ==============================================================================
bogdanm 0:9b334a45a8ff 130 ##### Initialization and de-initialization functions #####
bogdanm 0:9b334a45a8ff 131 ==============================================================================
bogdanm 0:9b334a45a8ff 132 [..]
bogdanm 0:9b334a45a8ff 133 This section provides functions allowing to:
bogdanm 0:9b334a45a8ff 134 (+) Initialize the WWDG according to the specified parameters
bogdanm 0:9b334a45a8ff 135 in the WWDG_InitTypeDef and initialize the associated handle.
bogdanm 0:9b334a45a8ff 136 (+) DeInitialize the WWDG peripheral.
bogdanm 0:9b334a45a8ff 137 (+) Initialize the WWDG MSP.
bogdanm 0:9b334a45a8ff 138 (+) DeInitialize the WWDG MSP.
bogdanm 0:9b334a45a8ff 139
bogdanm 0:9b334a45a8ff 140 @endverbatim
bogdanm 0:9b334a45a8ff 141 * @{
bogdanm 0:9b334a45a8ff 142 */
bogdanm 0:9b334a45a8ff 143
bogdanm 0:9b334a45a8ff 144 /**
bogdanm 0:9b334a45a8ff 145 * @brief Initialize the WWDG according to the specified
bogdanm 0:9b334a45a8ff 146 * parameters in the WWDG_InitTypeDef and initialize the associated handle.
bogdanm 0:9b334a45a8ff 147 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 148 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 149 * @retval HAL status
bogdanm 0:9b334a45a8ff 150 */
bogdanm 0:9b334a45a8ff 151 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 152 {
bogdanm 0:9b334a45a8ff 153 /* Check the WWDG handle allocation */
bogdanm 0:9b334a45a8ff 154 if(hwwdg == NULL)
bogdanm 0:9b334a45a8ff 155 {
bogdanm 0:9b334a45a8ff 156 return HAL_ERROR;
bogdanm 0:9b334a45a8ff 157 }
bogdanm 0:9b334a45a8ff 158
bogdanm 0:9b334a45a8ff 159 /* Check the parameters */
bogdanm 0:9b334a45a8ff 160 assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
bogdanm 0:9b334a45a8ff 161 assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
bogdanm 0:9b334a45a8ff 162 assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
bogdanm 0:9b334a45a8ff 163 assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
bogdanm 0:9b334a45a8ff 164
bogdanm 0:9b334a45a8ff 165 if(hwwdg->State == HAL_WWDG_STATE_RESET)
bogdanm 0:9b334a45a8ff 166 {
bogdanm 0:9b334a45a8ff 167 /* Allocate lock resource and initialize it */
bogdanm 0:9b334a45a8ff 168 hwwdg->Lock = HAL_UNLOCKED;
bogdanm 0:9b334a45a8ff 169
bogdanm 0:9b334a45a8ff 170 /* Init the low level hardware */
bogdanm 0:9b334a45a8ff 171 HAL_WWDG_MspInit(hwwdg);
bogdanm 0:9b334a45a8ff 172 }
bogdanm 0:9b334a45a8ff 173
bogdanm 0:9b334a45a8ff 174 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 175 hwwdg->State = HAL_WWDG_STATE_BUSY;
bogdanm 0:9b334a45a8ff 176
bogdanm 0:9b334a45a8ff 177 /* Set WWDG Prescaler and Window */
bogdanm 0:9b334a45a8ff 178 MODIFY_REG(hwwdg->Instance->CFR, (WWDG_CFR_WDGTB | WWDG_CFR_W), (hwwdg->Init.Prescaler | hwwdg->Init.Window));
bogdanm 0:9b334a45a8ff 179
bogdanm 0:9b334a45a8ff 180 /* Set WWDG Counter */
bogdanm 0:9b334a45a8ff 181 MODIFY_REG(hwwdg->Instance->CR, WWDG_CR_T, hwwdg->Init.Counter);
bogdanm 0:9b334a45a8ff 182
bogdanm 0:9b334a45a8ff 183 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 184 hwwdg->State = HAL_WWDG_STATE_READY;
bogdanm 0:9b334a45a8ff 185
bogdanm 0:9b334a45a8ff 186 /* Return function status */
bogdanm 0:9b334a45a8ff 187 return HAL_OK;
bogdanm 0:9b334a45a8ff 188 }
bogdanm 0:9b334a45a8ff 189
bogdanm 0:9b334a45a8ff 190 /**
bogdanm 0:9b334a45a8ff 191 * @brief DeInitialize the WWDG peripheral.
bogdanm 0:9b334a45a8ff 192 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 193 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 194 * @retval HAL status
bogdanm 0:9b334a45a8ff 195 */
bogdanm 0:9b334a45a8ff 196 HAL_StatusTypeDef HAL_WWDG_DeInit(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 197 {
bogdanm 0:9b334a45a8ff 198 /* Check the WWDG handle allocation */
bogdanm 0:9b334a45a8ff 199 if(hwwdg == NULL)
bogdanm 0:9b334a45a8ff 200 {
bogdanm 0:9b334a45a8ff 201 return HAL_ERROR;
bogdanm 0:9b334a45a8ff 202 }
bogdanm 0:9b334a45a8ff 203
bogdanm 0:9b334a45a8ff 204 /* Check the parameters */
bogdanm 0:9b334a45a8ff 205 assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
bogdanm 0:9b334a45a8ff 206
bogdanm 0:9b334a45a8ff 207 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 208 hwwdg->State = HAL_WWDG_STATE_BUSY;
bogdanm 0:9b334a45a8ff 209
bogdanm 0:9b334a45a8ff 210 /* DeInit the low level hardware */
bogdanm 0:9b334a45a8ff 211 HAL_WWDG_MspDeInit(hwwdg);
bogdanm 0:9b334a45a8ff 212
bogdanm 0:9b334a45a8ff 213 /* Reset WWDG Control register */
bogdanm 0:9b334a45a8ff 214 hwwdg->Instance->CR = (uint32_t)0x0000007F;
bogdanm 0:9b334a45a8ff 215
bogdanm 0:9b334a45a8ff 216 /* Reset WWDG Configuration register */
bogdanm 0:9b334a45a8ff 217 hwwdg->Instance->CFR = (uint32_t)0x0000007F;
bogdanm 0:9b334a45a8ff 218
bogdanm 0:9b334a45a8ff 219 /* Reset WWDG Status register */
bogdanm 0:9b334a45a8ff 220 hwwdg->Instance->SR = 0;
bogdanm 0:9b334a45a8ff 221
bogdanm 0:9b334a45a8ff 222 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 223 hwwdg->State = HAL_WWDG_STATE_RESET;
bogdanm 0:9b334a45a8ff 224
bogdanm 0:9b334a45a8ff 225 /* Release Lock */
bogdanm 0:9b334a45a8ff 226 __HAL_UNLOCK(hwwdg);
bogdanm 0:9b334a45a8ff 227
bogdanm 0:9b334a45a8ff 228 /* Return function status */
bogdanm 0:9b334a45a8ff 229 return HAL_OK;
bogdanm 0:9b334a45a8ff 230 }
bogdanm 0:9b334a45a8ff 231
bogdanm 0:9b334a45a8ff 232 /**
bogdanm 0:9b334a45a8ff 233 * @brief Initialize the WWDG MSP.
bogdanm 0:9b334a45a8ff 234 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 235 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 236 * @retval None
bogdanm 0:9b334a45a8ff 237 */
bogdanm 0:9b334a45a8ff 238 __weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 239 {
bogdanm 0:9b334a45a8ff 240 /* NOTE: This function should not be modified, when the callback is needed,
bogdanm 0:9b334a45a8ff 241 the HAL_WWDG_MspInit could be implemented in the user file
bogdanm 0:9b334a45a8ff 242 */
bogdanm 0:9b334a45a8ff 243 }
bogdanm 0:9b334a45a8ff 244
bogdanm 0:9b334a45a8ff 245 /**
bogdanm 0:9b334a45a8ff 246 * @brief DeInitialize the WWDG MSP.
bogdanm 0:9b334a45a8ff 247 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 248 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 249 * @retval None
bogdanm 0:9b334a45a8ff 250 */
bogdanm 0:9b334a45a8ff 251 __weak void HAL_WWDG_MspDeInit(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 252 {
bogdanm 0:9b334a45a8ff 253 /* NOTE: This function should not be modified, when the callback is needed,
bogdanm 0:9b334a45a8ff 254 the HAL_WWDG_MspDeInit could be implemented in the user file
bogdanm 0:9b334a45a8ff 255 */
bogdanm 0:9b334a45a8ff 256 }
bogdanm 0:9b334a45a8ff 257
bogdanm 0:9b334a45a8ff 258 /**
bogdanm 0:9b334a45a8ff 259 * @}
bogdanm 0:9b334a45a8ff 260 */
bogdanm 0:9b334a45a8ff 261
bogdanm 0:9b334a45a8ff 262 /** @defgroup WWDG_Exported_Functions_Group2 IO operation functions
bogdanm 0:9b334a45a8ff 263 * @brief IO operation functions
bogdanm 0:9b334a45a8ff 264 *
bogdanm 0:9b334a45a8ff 265 @verbatim
bogdanm 0:9b334a45a8ff 266 ==============================================================================
bogdanm 0:9b334a45a8ff 267 ##### IO operation functions #####
bogdanm 0:9b334a45a8ff 268 ==============================================================================
bogdanm 0:9b334a45a8ff 269 [..]
bogdanm 0:9b334a45a8ff 270 This section provides functions allowing to:
bogdanm 0:9b334a45a8ff 271 (+) Start the WWDG.
bogdanm 0:9b334a45a8ff 272 (+) Refresh the WWDG.
bogdanm 0:9b334a45a8ff 273 (+) Handle WWDG interrupt request and associated function callback.
bogdanm 0:9b334a45a8ff 274
bogdanm 0:9b334a45a8ff 275 @endverbatim
bogdanm 0:9b334a45a8ff 276 * @{
bogdanm 0:9b334a45a8ff 277 */
bogdanm 0:9b334a45a8ff 278
bogdanm 0:9b334a45a8ff 279 /**
bogdanm 0:9b334a45a8ff 280 * @brief Start the WWDG.
bogdanm 0:9b334a45a8ff 281 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 282 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 283 * @retval HAL status
bogdanm 0:9b334a45a8ff 284 */
bogdanm 0:9b334a45a8ff 285 HAL_StatusTypeDef HAL_WWDG_Start(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 286 {
bogdanm 0:9b334a45a8ff 287 /* Process Locked */
bogdanm 0:9b334a45a8ff 288 __HAL_LOCK(hwwdg);
bogdanm 0:9b334a45a8ff 289
bogdanm 0:9b334a45a8ff 290 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 291 hwwdg->State = HAL_WWDG_STATE_BUSY;
bogdanm 0:9b334a45a8ff 292
bogdanm 0:9b334a45a8ff 293 /* Enable the peripheral */
bogdanm 0:9b334a45a8ff 294 __HAL_WWDG_ENABLE(hwwdg);
bogdanm 0:9b334a45a8ff 295
bogdanm 0:9b334a45a8ff 296 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 297 hwwdg->State = HAL_WWDG_STATE_READY;
bogdanm 0:9b334a45a8ff 298
bogdanm 0:9b334a45a8ff 299 /* Process Unlocked */
bogdanm 0:9b334a45a8ff 300 __HAL_UNLOCK(hwwdg);
bogdanm 0:9b334a45a8ff 301
bogdanm 0:9b334a45a8ff 302 /* Return function status */
bogdanm 0:9b334a45a8ff 303 return HAL_OK;
bogdanm 0:9b334a45a8ff 304 }
bogdanm 0:9b334a45a8ff 305
bogdanm 0:9b334a45a8ff 306 /**
bogdanm 0:9b334a45a8ff 307 * @brief Start the WWDG with interrupt enabled.
bogdanm 0:9b334a45a8ff 308 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 309 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 310 * @retval HAL status
bogdanm 0:9b334a45a8ff 311 */
bogdanm 0:9b334a45a8ff 312 HAL_StatusTypeDef HAL_WWDG_Start_IT(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 313 {
bogdanm 0:9b334a45a8ff 314 /* Process Locked */
bogdanm 0:9b334a45a8ff 315 __HAL_LOCK(hwwdg);
bogdanm 0:9b334a45a8ff 316
bogdanm 0:9b334a45a8ff 317 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 318 hwwdg->State = HAL_WWDG_STATE_BUSY;
bogdanm 0:9b334a45a8ff 319
bogdanm 0:9b334a45a8ff 320 /* Enable the Early Wakeup Interrupt */
bogdanm 0:9b334a45a8ff 321 __HAL_WWDG_ENABLE_IT(hwwdg, WWDG_IT_EWI);
bogdanm 0:9b334a45a8ff 322
bogdanm 0:9b334a45a8ff 323 /* Enable the peripheral */
bogdanm 0:9b334a45a8ff 324 __HAL_WWDG_ENABLE(hwwdg);
bogdanm 0:9b334a45a8ff 325
bogdanm 0:9b334a45a8ff 326 /* Return function status */
bogdanm 0:9b334a45a8ff 327 return HAL_OK;
bogdanm 0:9b334a45a8ff 328 }
bogdanm 0:9b334a45a8ff 329
bogdanm 0:9b334a45a8ff 330 /**
bogdanm 0:9b334a45a8ff 331 * @brief Refresh the WWDG.
bogdanm 0:9b334a45a8ff 332 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 333 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 334 * @param Counter: value of counter to put in WWDG counter
bogdanm 0:9b334a45a8ff 335 * @retval HAL status
bogdanm 0:9b334a45a8ff 336 */
bogdanm 0:9b334a45a8ff 337 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg, uint32_t Counter)
bogdanm 0:9b334a45a8ff 338 {
bogdanm 0:9b334a45a8ff 339 /* Process Locked */
bogdanm 0:9b334a45a8ff 340 __HAL_LOCK(hwwdg);
bogdanm 0:9b334a45a8ff 341
bogdanm 0:9b334a45a8ff 342 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 343 hwwdg->State = HAL_WWDG_STATE_BUSY;
bogdanm 0:9b334a45a8ff 344
bogdanm 0:9b334a45a8ff 345 /* Check the parameters */
bogdanm 0:9b334a45a8ff 346 assert_param(IS_WWDG_COUNTER(Counter));
bogdanm 0:9b334a45a8ff 347
bogdanm 0:9b334a45a8ff 348 /* Write to WWDG CR the WWDG Counter value to refresh with */
bogdanm 0:9b334a45a8ff 349 MODIFY_REG(hwwdg->Instance->CR, (uint32_t)WWDG_CR_T, Counter);
bogdanm 0:9b334a45a8ff 350
bogdanm 0:9b334a45a8ff 351 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 352 hwwdg->State = HAL_WWDG_STATE_READY;
bogdanm 0:9b334a45a8ff 353
bogdanm 0:9b334a45a8ff 354 /* Process Unlocked */
bogdanm 0:9b334a45a8ff 355 __HAL_UNLOCK(hwwdg);
bogdanm 0:9b334a45a8ff 356
bogdanm 0:9b334a45a8ff 357 /* Return function status */
bogdanm 0:9b334a45a8ff 358 return HAL_OK;
bogdanm 0:9b334a45a8ff 359 }
bogdanm 0:9b334a45a8ff 360
bogdanm 0:9b334a45a8ff 361 /**
bogdanm 0:9b334a45a8ff 362 * @brief Handle WWDG interrupt request.
bogdanm 0:9b334a45a8ff 363 * @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations
bogdanm 0:9b334a45a8ff 364 * or data logging must be performed before the actual reset is generated.
bogdanm 0:9b334a45a8ff 365 * The EWI interrupt is enabled when calling HAL_WWDG_Start_IT function.
bogdanm 0:9b334a45a8ff 366 * When the downcounter reaches the value 0x40, and EWI interrupt is
bogdanm 0:9b334a45a8ff 367 * generated and the corresponding Interrupt Service Routine (ISR) can
bogdanm 0:9b334a45a8ff 368 * be used to trigger specific actions (such as communications or data
bogdanm 0:9b334a45a8ff 369 * logging), before resetting the device.
bogdanm 0:9b334a45a8ff 370 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 371 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 372 * @retval None
bogdanm 0:9b334a45a8ff 373 */
bogdanm 0:9b334a45a8ff 374 void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 375 {
bogdanm 0:9b334a45a8ff 376 /* Check if Early Wakeup Interrupt is enable */
bogdanm 0:9b334a45a8ff 377 if(__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET)
bogdanm 0:9b334a45a8ff 378 {
bogdanm 0:9b334a45a8ff 379 /* Check if WWDG Early Wakeup Interrupt occurred */
bogdanm 0:9b334a45a8ff 380 if(__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET)
bogdanm 0:9b334a45a8ff 381 {
bogdanm 0:9b334a45a8ff 382 /* Early Wakeup callback */
bogdanm 0:9b334a45a8ff 383 HAL_WWDG_WakeupCallback(hwwdg);
bogdanm 0:9b334a45a8ff 384
bogdanm 0:9b334a45a8ff 385 /* Change WWDG peripheral state */
bogdanm 0:9b334a45a8ff 386 hwwdg->State = HAL_WWDG_STATE_READY;
bogdanm 0:9b334a45a8ff 387
bogdanm 0:9b334a45a8ff 388 /* Clear the WWDG Early Wakeup flag */
bogdanm 0:9b334a45a8ff 389 __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);
bogdanm 0:9b334a45a8ff 390
bogdanm 0:9b334a45a8ff 391 /* Process Unlocked */
bogdanm 0:9b334a45a8ff 392 __HAL_UNLOCK(hwwdg);
bogdanm 0:9b334a45a8ff 393 }
bogdanm 0:9b334a45a8ff 394 }
bogdanm 0:9b334a45a8ff 395 }
bogdanm 0:9b334a45a8ff 396
bogdanm 0:9b334a45a8ff 397 /**
bogdanm 0:9b334a45a8ff 398 * @brief Early Wakeup WWDG callback.
bogdanm 0:9b334a45a8ff 399 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 400 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 401 * @retval None
bogdanm 0:9b334a45a8ff 402 */
bogdanm 0:9b334a45a8ff 403 __weak void HAL_WWDG_WakeupCallback(WWDG_HandleTypeDef* hwwdg)
bogdanm 0:9b334a45a8ff 404 {
bogdanm 0:9b334a45a8ff 405 /* NOTE: This function should not be modified, when the callback is needed,
bogdanm 0:9b334a45a8ff 406 the HAL_WWDG_WakeupCallback could be implemented in the user file
bogdanm 0:9b334a45a8ff 407 */
bogdanm 0:9b334a45a8ff 408 }
bogdanm 0:9b334a45a8ff 409
bogdanm 0:9b334a45a8ff 410 /**
bogdanm 0:9b334a45a8ff 411 * @}
bogdanm 0:9b334a45a8ff 412 */
bogdanm 0:9b334a45a8ff 413
bogdanm 0:9b334a45a8ff 414 /** @defgroup WWDG_Exported_Functions_Group3 Peripheral State functions
bogdanm 0:9b334a45a8ff 415 * @brief Peripheral State functions.
bogdanm 0:9b334a45a8ff 416 *
bogdanm 0:9b334a45a8ff 417 @verbatim
bogdanm 0:9b334a45a8ff 418 ==============================================================================
bogdanm 0:9b334a45a8ff 419 ##### Peripheral State functions #####
bogdanm 0:9b334a45a8ff 420 ==============================================================================
bogdanm 0:9b334a45a8ff 421 [..]
bogdanm 0:9b334a45a8ff 422 This subsection permits to get in run-time the status of the peripheral
bogdanm 0:9b334a45a8ff 423 and the data flow.
bogdanm 0:9b334a45a8ff 424
bogdanm 0:9b334a45a8ff 425 @endverbatim
bogdanm 0:9b334a45a8ff 426 * @{
bogdanm 0:9b334a45a8ff 427 */
bogdanm 0:9b334a45a8ff 428
bogdanm 0:9b334a45a8ff 429 /**
bogdanm 0:9b334a45a8ff 430 * @brief Return the WWDG handle state.
bogdanm 0:9b334a45a8ff 431 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
bogdanm 0:9b334a45a8ff 432 * the configuration information for the specified WWDG module.
bogdanm 0:9b334a45a8ff 433 * @retval HAL state
bogdanm 0:9b334a45a8ff 434 */
bogdanm 0:9b334a45a8ff 435 HAL_WWDG_StateTypeDef HAL_WWDG_GetState(WWDG_HandleTypeDef *hwwdg)
bogdanm 0:9b334a45a8ff 436 {
bogdanm 0:9b334a45a8ff 437 return hwwdg->State;
bogdanm 0:9b334a45a8ff 438 }
bogdanm 0:9b334a45a8ff 439
bogdanm 0:9b334a45a8ff 440 /**
bogdanm 0:9b334a45a8ff 441 * @}
bogdanm 0:9b334a45a8ff 442 */
bogdanm 0:9b334a45a8ff 443
bogdanm 0:9b334a45a8ff 444 /**
bogdanm 0:9b334a45a8ff 445 * @}
bogdanm 0:9b334a45a8ff 446 */
bogdanm 0:9b334a45a8ff 447
bogdanm 0:9b334a45a8ff 448 #endif /* HAL_WWDG_MODULE_ENABLED */
bogdanm 0:9b334a45a8ff 449 /**
bogdanm 0:9b334a45a8ff 450 * @}
bogdanm 0:9b334a45a8ff 451 */
bogdanm 0:9b334a45a8ff 452
bogdanm 0:9b334a45a8ff 453 /**
bogdanm 0:9b334a45a8ff 454 * @}
bogdanm 0:9b334a45a8ff 455 */
bogdanm 0:9b334a45a8ff 456
bogdanm 0:9b334a45a8ff 457 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/