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:
296:ec1b66a3d094
test with CLOCK_SETUP = 0

Who changed what in which revision?

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