mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
184:08ed48f1de7f
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**
<> 149:156823d33999 2 ******************************************************************************
<> 149:156823d33999 3 * @file stm32l1xx_hal_wwdg.c
<> 149:156823d33999 4 * @author MCD Application Team
<> 149:156823d33999 5 * @brief WWDG HAL module driver.
<> 149:156823d33999 6 * This file provides firmware functions to manage the following
<> 149:156823d33999 7 * functionalities of the Window Watchdog (WWDG) peripheral:
<> 149:156823d33999 8 * + Initialization and Configuration function
<> 149:156823d33999 9 * + IO operation functions
<> 149:156823d33999 10 @verbatim
<> 149:156823d33999 11 ==============================================================================
<> 149:156823d33999 12 ##### WWDG specific features #####
<> 149:156823d33999 13 ==============================================================================
<> 149:156823d33999 14 [..]
<> 149:156823d33999 15 Once enabled the WWDG generates a system reset on expiry of a programmed
<> 149:156823d33999 16 time period, unless the program refreshes the counter (T[6;0] downcounter)
<> 149:156823d33999 17 before reaching 0x3F value (i.e. a reset is generated when the counter
<> 149:156823d33999 18 value rolls over from 0x40 to 0x3F).
<> 149:156823d33999 19
<> 149:156823d33999 20 (+) An MCU reset is also generated if the counter value is refreshed
<> 149:156823d33999 21 before the counter has reached the refresh window value. This
<> 149:156823d33999 22 implies that the counter must be refreshed in a limited window.
<> 149:156823d33999 23
<> 149:156823d33999 24 (+) Once enabled the WWDG cannot be disabled except by a system reset.
<> 149:156823d33999 25
<> 149:156823d33999 26 (+) WWDGRST flag in RCC_CSR register informs when a WWDG reset has
<> 149:156823d33999 27 occurred (check available with __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)).
<> 149:156823d33999 28
<> 149:156823d33999 29 (+) The WWDG downcounter input clock is derived from the APB clock divided
<> 149:156823d33999 30 by a programmable prescaler.
<> 149:156823d33999 31
<> 149:156823d33999 32 (+) WWDG downcounter clock (Hz) = PCLK1 / (4096 * Prescaler)
<> 149:156823d33999 33
<> 149:156823d33999 34 (+) WWDG timeout (ms) = (1000 * (T[5;0] + 1)) / (WWDG downcounter clock)
<> 149:156823d33999 35 where T[5;0] are the lowest 6 bits of downcounter.
<> 149:156823d33999 36
<> 149:156823d33999 37 (+) WWDG Counter refresh is allowed between the following limits :
<> 149:156823d33999 38 (++) min time (ms) = (1000 * (T[5;0] - Window)) / (WWDG downcounter clock)
<> 149:156823d33999 39 (++) max time (ms) = (1000 * (T[5;0] - 0x40)) / (WWDG downcounter clock)
<> 149:156823d33999 40
<> 149:156823d33999 41 (+) Min-max timeout value @80 MHz(PCLK1): ~51.2 us / ~26.22 ms
<> 149:156823d33999 42
<> 149:156823d33999 43 (+) The Early Wakeup Interrupt (EWI) can be used if specific safety
<> 149:156823d33999 44 operations or data logging must be performed before the actual reset is
<> 149:156823d33999 45 generated. When the downcounter reaches the value 0x40, an EWI interrupt
<> 149:156823d33999 46 is generated and the corresponding interrupt service routine (ISR) can
<> 149:156823d33999 47 be used to trigger specific actions (such as communications or data
<> 149:156823d33999 48 logging), before resetting the device.
<> 149:156823d33999 49 In some applications, the EWI interrupt can be used to manage a software
<> 149:156823d33999 50 system check and/or system recovery/graceful degradation, without
<> 149:156823d33999 51 generating a WWDG reset. In this case, the corresponding interrupt
<> 149:156823d33999 52 service routine (ISR) should reload the WWDG counter to avoid the WWDG
<> 149:156823d33999 53 reset, then trigger the required actions.
<> 149:156823d33999 54 Note:When the EWI interrupt cannot be served, e.g. due to a system lock
<> 149:156823d33999 55 in a higher priority task, the WWDG reset will eventually be generated.
<> 149:156823d33999 56
<> 149:156823d33999 57 (+) Debug mode : When the microcontroller enters debug mode (core halted),
<> 149:156823d33999 58 the WWDG counter either continues to work normally or stops, depending
<> 149:156823d33999 59 on DBG_WWDG_STOP configuration bit in DBG module, accessible through
<> 149:156823d33999 60 __HAL_DBGMCU_FREEZE_WWDG() and __HAL_DBGMCU_UNFREEZE_WWDG() macros
<> 149:156823d33999 61
<> 149:156823d33999 62 ##### How to use this driver #####
<> 149:156823d33999 63 ==============================================================================
<> 149:156823d33999 64 [..]
<> 149:156823d33999 65 (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE().
<> 149:156823d33999 66
<> 149:156823d33999 67 (+) Set the WWDG prescaler, refresh window, counter value and Early Wakeup
<> 149:156823d33999 68 Interrupt mode using using HAL_WWDG_Init() function.
<> 149:156823d33999 69 This enables WWDG peripheral and the downcounter starts downcounting
<> 149:156823d33999 70 from given counter value.
<> 149:156823d33999 71 Init function can be called again to modify all watchdog parameters,
<> 149:156823d33999 72 however if EWI mode has been set once, it can't be clear until next
<> 149:156823d33999 73 reset.
<> 149:156823d33999 74
<> 149:156823d33999 75 (+) The application program must refresh the WWDG counter at regular
<> 149:156823d33999 76 intervals during normal operation to prevent an MCU reset using
<> 149:156823d33999 77 HAL_WWDG_Refresh() function. This operation must occur only when
<> 149:156823d33999 78 the counter is lower than the window value already programmed.
<> 149:156823d33999 79
<> 149:156823d33999 80 (+) if Early Wakeup Interrupt mode is enable an interrupt is generated when
<> 149:156823d33999 81 the counter reaches 0x40. User can add his own code in weak function
<> 149:156823d33999 82 HAL_WWDG_EarlyWakeupCallback().
<> 149:156823d33999 83
<> 149:156823d33999 84 *** WWDG HAL driver macros list ***
<> 149:156823d33999 85 ==================================
<> 149:156823d33999 86 [..]
<> 149:156823d33999 87 Below the list of most used macros in WWDG HAL driver.
<> 149:156823d33999 88
<> 149:156823d33999 89 (+) __HAL_WWDG_GET_IT_SOURCE: Check the selected WWDG's interrupt source.
<> 149:156823d33999 90 (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status.
<> 149:156823d33999 91 (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags.
<> 149:156823d33999 92
<> 149:156823d33999 93 @endverbatim
<> 149:156823d33999 94 ******************************************************************************
<> 149:156823d33999 95 * @attention
<> 149:156823d33999 96 *
AnnaBridge 184:08ed48f1de7f 97 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
<> 149:156823d33999 98 *
<> 149:156823d33999 99 * Redistribution and use in source and binary forms, with or without modification,
<> 149:156823d33999 100 * are permitted provided that the following conditions are met:
<> 149:156823d33999 101 * 1. Redistributions of source code must retain the above copyright notice,
<> 149:156823d33999 102 * this list of conditions and the following disclaimer.
<> 149:156823d33999 103 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 149:156823d33999 104 * this list of conditions and the following disclaimer in the documentation
<> 149:156823d33999 105 * and/or other materials provided with the distribution.
<> 149:156823d33999 106 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 149:156823d33999 107 * may be used to endorse or promote products derived from this software
<> 149:156823d33999 108 * without specific prior written permission.
<> 149:156823d33999 109 *
<> 149:156823d33999 110 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 149:156823d33999 111 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 149:156823d33999 112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 149:156823d33999 113 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 149:156823d33999 114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 149:156823d33999 115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 149:156823d33999 116 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 149:156823d33999 117 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 149:156823d33999 118 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 149:156823d33999 119 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 149:156823d33999 120 *
<> 149:156823d33999 121 ******************************************************************************
<> 149:156823d33999 122 */
<> 149:156823d33999 123
<> 149:156823d33999 124 /* Includes ------------------------------------------------------------------*/
<> 149:156823d33999 125 #include "stm32l1xx_hal.h"
<> 149:156823d33999 126
<> 149:156823d33999 127 /** @addtogroup STM32L1xx_HAL_Driver
<> 149:156823d33999 128 * @{
<> 149:156823d33999 129 */
<> 149:156823d33999 130
<> 149:156823d33999 131 #ifdef HAL_WWDG_MODULE_ENABLED
<> 149:156823d33999 132 /** @defgroup WWDG WWDG
<> 149:156823d33999 133 * @brief WWDG HAL module driver.
<> 149:156823d33999 134 * @{
<> 149:156823d33999 135 */
<> 149:156823d33999 136
<> 149:156823d33999 137 /* Private typedef -----------------------------------------------------------*/
<> 149:156823d33999 138 /* Private define ------------------------------------------------------------*/
<> 149:156823d33999 139 /* Private macro -------------------------------------------------------------*/
<> 149:156823d33999 140 /* Private variables ---------------------------------------------------------*/
<> 149:156823d33999 141 /* Private function prototypes -----------------------------------------------*/
<> 149:156823d33999 142 /* Exported functions --------------------------------------------------------*/
<> 149:156823d33999 143
<> 149:156823d33999 144 /** @defgroup WWDG_Exported_Functions WWDG Exported Functions
<> 149:156823d33999 145 * @{
<> 149:156823d33999 146 */
<> 149:156823d33999 147
<> 149:156823d33999 148 /** @defgroup WWDG_Exported_Functions_Group1 Initialization and Configuration functions
<> 149:156823d33999 149 * @brief Initialization and Configuration functions.
<> 149:156823d33999 150 *
<> 149:156823d33999 151 @verbatim
<> 149:156823d33999 152 ==============================================================================
<> 149:156823d33999 153 ##### Initialization and Configuration functions #####
<> 149:156823d33999 154 ==============================================================================
<> 149:156823d33999 155 [..]
<> 149:156823d33999 156 This section provides functions allowing to:
<> 149:156823d33999 157 (+) Initialize and start the WWDG according to the specified parameters
<> 149:156823d33999 158 in the WWDG_InitTypeDef of associated handle.
<> 149:156823d33999 159 (+) Initialize the WWDG MSP.
<> 149:156823d33999 160
<> 149:156823d33999 161 @endverbatim
<> 149:156823d33999 162 * @{
<> 149:156823d33999 163 */
<> 149:156823d33999 164
<> 149:156823d33999 165 /**
<> 149:156823d33999 166 * @brief Initialize the WWDG according to the specified.
<> 149:156823d33999 167 * parameters in the WWDG_InitTypeDef of associated handle.
<> 149:156823d33999 168 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
<> 149:156823d33999 169 * the configuration information for the specified WWDG module.
<> 149:156823d33999 170 * @retval HAL status
<> 149:156823d33999 171 */
<> 149:156823d33999 172 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
<> 149:156823d33999 173 {
<> 149:156823d33999 174 /* Check the WWDG handle allocation */
<> 149:156823d33999 175 if(hwwdg == NULL)
<> 149:156823d33999 176 {
<> 149:156823d33999 177 return HAL_ERROR;
<> 149:156823d33999 178 }
<> 149:156823d33999 179
<> 149:156823d33999 180 /* Check the parameters */
<> 149:156823d33999 181 assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
<> 149:156823d33999 182 assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
<> 149:156823d33999 183 assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
<> 149:156823d33999 184 assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
<> 149:156823d33999 185 assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode));
<> 149:156823d33999 186
<> 149:156823d33999 187 /* Init the low level hardware */
<> 149:156823d33999 188 HAL_WWDG_MspInit(hwwdg);
<> 149:156823d33999 189
<> 149:156823d33999 190 /* Set WWDG Counter */
<> 149:156823d33999 191 WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter));
<> 149:156823d33999 192
<> 149:156823d33999 193 /* Set WWDG Prescaler and Window */
<> 149:156823d33999 194 WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window));
<> 149:156823d33999 195
<> 149:156823d33999 196 /* Return function status */
<> 149:156823d33999 197 return HAL_OK;
<> 149:156823d33999 198 }
<> 149:156823d33999 199
<> 149:156823d33999 200
<> 149:156823d33999 201 /**
<> 149:156823d33999 202 * @brief Initialize the WWDG MSP.
<> 149:156823d33999 203 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
<> 149:156823d33999 204 * the configuration information for the specified WWDG module.
<> 149:156823d33999 205 * @note When rewriting this function in user file, mechanism may be added
<> 149:156823d33999 206 * to avoid multiple initialize when HAL_WWDG_Init function is called
<> 149:156823d33999 207 * again to change parameters.
<> 149:156823d33999 208 * @retval None
<> 149:156823d33999 209 */
<> 149:156823d33999 210 __weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg)
<> 149:156823d33999 211 {
<> 149:156823d33999 212 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 213 UNUSED(hwwdg);
<> 149:156823d33999 214
<> 149:156823d33999 215 /* NOTE: This function should not be modified, when the callback is needed,
<> 149:156823d33999 216 the HAL_WWDG_MspInit could be implemented in the user file
<> 149:156823d33999 217 */
<> 149:156823d33999 218 }
<> 149:156823d33999 219
<> 149:156823d33999 220 /**
<> 149:156823d33999 221 * @}
<> 149:156823d33999 222 */
<> 149:156823d33999 223
<> 149:156823d33999 224 /** @defgroup WWDG_Exported_Functions_Group2 IO operation functions
<> 149:156823d33999 225 * @brief IO operation functions
<> 149:156823d33999 226 *
<> 149:156823d33999 227 @verbatim
<> 149:156823d33999 228 ==============================================================================
<> 149:156823d33999 229 ##### IO operation functions #####
<> 149:156823d33999 230 ==============================================================================
<> 149:156823d33999 231 [..]
<> 149:156823d33999 232 This section provides functions allowing to:
<> 149:156823d33999 233 (+) Refresh the WWDG.
<> 149:156823d33999 234 (+) Handle WWDG interrupt request and associated function callback.
<> 149:156823d33999 235
<> 149:156823d33999 236 @endverbatim
<> 149:156823d33999 237 * @{
<> 149:156823d33999 238 */
<> 149:156823d33999 239
<> 149:156823d33999 240 /**
<> 149:156823d33999 241 * @brief Refresh the WWDG.
<> 149:156823d33999 242 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
<> 149:156823d33999 243 * the configuration information for the specified WWDG module.
<> 149:156823d33999 244 * @retval HAL status
<> 149:156823d33999 245 */
<> 149:156823d33999 246 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
<> 149:156823d33999 247 {
<> 149:156823d33999 248 /* Write to WWDG CR the WWDG Counter value to refresh with */
<> 149:156823d33999 249 WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter));
<> 149:156823d33999 250
<> 149:156823d33999 251 /* Return function status */
<> 149:156823d33999 252 return HAL_OK;
<> 149:156823d33999 253 }
<> 149:156823d33999 254
<> 149:156823d33999 255 /**
<> 149:156823d33999 256 * @brief Handle WWDG interrupt request.
<> 149:156823d33999 257 * @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations
<> 149:156823d33999 258 * or data logging must be performed before the actual reset is generated.
<> 149:156823d33999 259 * The EWI interrupt is enabled by calling HAL_WWDG_Init function with
<> 149:156823d33999 260 * EWIMode set to WWDG_EWI_ENABLE.
<> 149:156823d33999 261 * When the downcounter reaches the value 0x40, and EWI interrupt is
<> 149:156823d33999 262 * generated and the corresponding Interrupt Service Routine (ISR) can
<> 149:156823d33999 263 * be used to trigger specific actions (such as communications or data
<> 149:156823d33999 264 * logging), before resetting the device.
<> 149:156823d33999 265 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
<> 149:156823d33999 266 * the configuration information for the specified WWDG module.
<> 149:156823d33999 267 * @retval None
<> 149:156823d33999 268 */
<> 149:156823d33999 269 void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
<> 149:156823d33999 270 {
<> 149:156823d33999 271 /* Check if Early Wakeup Interrupt is enable */
<> 149:156823d33999 272 if(__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET)
<> 149:156823d33999 273 {
<> 149:156823d33999 274 /* Check if WWDG Early Wakeup Interrupt occurred */
<> 149:156823d33999 275 if(__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET)
<> 149:156823d33999 276 {
<> 149:156823d33999 277 /* Clear the WWDG Early Wakeup flag */
<> 149:156823d33999 278 __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);
<> 149:156823d33999 279
<> 149:156823d33999 280 /* Early Wakeup callback */
<> 149:156823d33999 281 HAL_WWDG_EarlyWakeupCallback(hwwdg);
<> 149:156823d33999 282 }
<> 149:156823d33999 283 }
<> 149:156823d33999 284 }
<> 149:156823d33999 285
<> 149:156823d33999 286
<> 149:156823d33999 287 /**
<> 149:156823d33999 288 * @brief WWDG Early Wakeup callback.
<> 149:156823d33999 289 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains
<> 149:156823d33999 290 * the configuration information for the specified WWDG module.
<> 149:156823d33999 291 * @retval None
<> 149:156823d33999 292 */
<> 149:156823d33999 293 __weak void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef* hwwdg)
<> 149:156823d33999 294 {
<> 149:156823d33999 295 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 296 UNUSED(hwwdg);
<> 149:156823d33999 297
<> 149:156823d33999 298 /* NOTE: This function should not be modified, when the callback is needed,
<> 149:156823d33999 299 the HAL_WWDG_EarlyWakeupCallback could be implemented in the user file
<> 149:156823d33999 300 */
<> 149:156823d33999 301 }
<> 149:156823d33999 302
<> 149:156823d33999 303 /**
<> 149:156823d33999 304 * @}
<> 149:156823d33999 305 */
<> 149:156823d33999 306
<> 149:156823d33999 307 /**
<> 149:156823d33999 308 * @}
<> 149:156823d33999 309 */
<> 149:156823d33999 310
<> 149:156823d33999 311 #endif /* HAL_WWDG_MODULE_ENABLED */
<> 149:156823d33999 312 /**
<> 149:156823d33999 313 * @}
<> 149:156823d33999 314 */
<> 149:156823d33999 315
<> 149:156823d33999 316 /**
<> 149:156823d33999 317 * @}
<> 149:156823d33999 318 */
<> 149:156823d33999 319
<> 149:156823d33999 320 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/