mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed May 07 13:15:08 2014 +0100
Revision:
181:a4cbdfbbd2f4
Synchronized with git revision 7751e759576c6fd68deccb81ea82bac19ed41745

Full URL: https://github.com/mbedmicro/mbed/commit/7751e759576c6fd68deccb81ea82bac19ed41745/

Who changed what in which revision?

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