mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
218:44081b78fdc2
test with CLOCK_SETUP = 0

Who changed what in which revision?

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