mbed library sources

Fork of mbed-src by mbed official

Committer:
moirans2
Date:
Wed Jan 14 20:53:08 2015 +0000
Revision:
445:9a3ffe6cfa19
Parent:
441:d2c15dda23c1
internal clock stm32L051

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 340:28d1f895c6fe 1 /**
mbed_official 340:28d1f895c6fe 2 ******************************************************************************
mbed_official 340:28d1f895c6fe 3 * @file stm32f0xx_hal_iwdg.c
mbed_official 340:28d1f895c6fe 4 * @author MCD Application Team
mbed_official 441:d2c15dda23c1 5 * @version V1.2.0
mbed_official 441:d2c15dda23c1 6 * @date 11-December-2014
mbed_official 340:28d1f895c6fe 7 * @brief IWDG HAL module driver.
mbed_official 340:28d1f895c6fe 8 * This file provides firmware functions to manage the following
mbed_official 441:d2c15dda23c1 9 * functionalities of the Independent Watchdog (IWDG) peripheral:
mbed_official 340:28d1f895c6fe 10 * + Initialization and Configuration functions
mbed_official 340:28d1f895c6fe 11 * + IO operation functions
mbed_official 340:28d1f895c6fe 12 * + Peripheral State functions
mbed_official 340:28d1f895c6fe 13 *
mbed_official 340:28d1f895c6fe 14 @verbatim
mbed_official 340:28d1f895c6fe 15 ===============================================================================
mbed_official 340:28d1f895c6fe 16 ##### IWDG Specific features #####
mbed_official 340:28d1f895c6fe 17 ===============================================================================
mbed_official 340:28d1f895c6fe 18 [..]
mbed_official 340:28d1f895c6fe 19 (+) The IWDG can be started by either software or hardware (configurable
mbed_official 340:28d1f895c6fe 20 through option byte).
mbed_official 340:28d1f895c6fe 21 (+) The IWDG is clocked by its own dedicated Low-Speed clock (LSI) and
mbed_official 340:28d1f895c6fe 22 thus stays active even if the main clock fails.
mbed_official 340:28d1f895c6fe 23 (+) Once the IWDG is started, the LSI is forced ON and cannot be disabled
mbed_official 340:28d1f895c6fe 24 (LSI cannot be disabled too), and the counter starts counting down from
mbed_official 340:28d1f895c6fe 25 the reset value of 0xFFF. When it reaches the end of count value (0x000)
mbed_official 340:28d1f895c6fe 26 a system reset is generated.
mbed_official 340:28d1f895c6fe 27 (+) The IWDG counter should be refreshed at regular intervals, otherwise the
mbed_official 340:28d1f895c6fe 28 watchdog generates an MCU reset when the counter reaches 0.
mbed_official 340:28d1f895c6fe 29 (+) The IWDG is implemented in the VDD voltage domain that is still functional
mbed_official 340:28d1f895c6fe 30 in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
mbed_official 340:28d1f895c6fe 31 (+) IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
mbed_official 340:28d1f895c6fe 32 reset occurs.
mbed_official 340:28d1f895c6fe 33 (+) Min-max timeout value @41KHz (LSI): ~0.1ms / ~25.5s
mbed_official 340:28d1f895c6fe 34 The IWDG timeout may vary due to LSI frequency dispersion. STM32F0x
mbed_official 340:28d1f895c6fe 35 devices provide the capability to measure the LSI frequency (LSI clock
mbed_official 340:28d1f895c6fe 36 connected internally to TIM16 CH1 input capture). The measured value
mbed_official 340:28d1f895c6fe 37 can be used to have an IWDG timeout with an acceptable accuracy.
mbed_official 340:28d1f895c6fe 38 For more information, please refer to the STM32F0x Reference manual.
mbed_official 340:28d1f895c6fe 39
mbed_official 340:28d1f895c6fe 40 ##### How to use this driver #####
mbed_official 340:28d1f895c6fe 41 ===============================================================================
mbed_official 340:28d1f895c6fe 42 [..]
mbed_official 340:28d1f895c6fe 43 (#) if Window option is disabled
mbed_official 340:28d1f895c6fe 44 (++) Use IWDG using HAL_IWDG_Init() function to :
mbed_official 340:28d1f895c6fe 45 (+++) Enable write access to IWDG_PR, IWDG_RLR.
mbed_official 340:28d1f895c6fe 46 (+++) Configure the IWDG prescaler, counter reload value.
mbed_official 340:28d1f895c6fe 47 This reload value will be loaded in the IWDG counter each time the counter
mbed_official 340:28d1f895c6fe 48 is reloaded, then the IWDG will start counting down from this value.
mbed_official 340:28d1f895c6fe 49 (++) Use IWDG using HAL_IWDG_Start() function to :
mbed_official 340:28d1f895c6fe 50 (+++) Reload IWDG counter with value defined in the IWDG_RLR register.
mbed_official 340:28d1f895c6fe 51 (+++) Start the IWDG, when the IWDG is used in software mode (no need
mbed_official 340:28d1f895c6fe 52 to enable the LSI, it will be enabled by hardware).
mbed_official 340:28d1f895c6fe 53 (++) Then the application program must refresh the IWDG counter at regular
mbed_official 340:28d1f895c6fe 54 intervals during normal operation to prevent an MCU reset, using
mbed_official 340:28d1f895c6fe 55 HAL_IWDG_Refresh() function.
mbed_official 340:28d1f895c6fe 56 (#) if Window option is enabled:
mbed_official 340:28d1f895c6fe 57 (++) Use IWDG using HAL_IWDG_Start() function to enable IWDG downcounter
mbed_official 340:28d1f895c6fe 58 (++) Use IWDG using HAL_IWDG_Init() function to :
mbed_official 340:28d1f895c6fe 59 (+++) Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
mbed_official 340:28d1f895c6fe 60 (+++) Configure the IWDG prescaler, reload value and window value.
mbed_official 340:28d1f895c6fe 61 (++) Then the application program must refresh the IWDG counter at regular
mbed_official 340:28d1f895c6fe 62 intervals during normal operation to prevent an MCU reset, using
mbed_official 340:28d1f895c6fe 63 HAL_IWDG_Refresh() function.
mbed_official 340:28d1f895c6fe 64
mbed_official 340:28d1f895c6fe 65 *** IWDG HAL driver macros list ***
mbed_official 340:28d1f895c6fe 66 ====================================
mbed_official 340:28d1f895c6fe 67 [..]
mbed_official 340:28d1f895c6fe 68 Below the list of most used macros in IWDG HAL driver.
mbed_official 340:28d1f895c6fe 69
mbed_official 340:28d1f895c6fe 70 (+) __HAL_IWDG_START: Enable the IWDG peripheral
mbed_official 340:28d1f895c6fe 71 (+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in the reload register
mbed_official 340:28d1f895c6fe 72 (+) __HAL_IWDG_ENABLE_WRITE_ACCESS : Enable write access to IWDG_PR and IWDG_RLR registers
mbed_official 340:28d1f895c6fe 73 (+) __HAL_IWDG_DISABLE_WRITE_ACCESS : Disable write access to IWDG_PR and IWDG_RLR registers
mbed_official 340:28d1f895c6fe 74 (+) __HAL_IWDG_GET_FLAG: Get the selected IWDG's flag status
mbed_official 340:28d1f895c6fe 75
mbed_official 340:28d1f895c6fe 76 @endverbatim
mbed_official 340:28d1f895c6fe 77 ******************************************************************************
mbed_official 340:28d1f895c6fe 78 * @attention
mbed_official 340:28d1f895c6fe 79 *
mbed_official 340:28d1f895c6fe 80 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 340:28d1f895c6fe 81 *
mbed_official 340:28d1f895c6fe 82 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 340:28d1f895c6fe 83 * are permitted provided that the following conditions are met:
mbed_official 340:28d1f895c6fe 84 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 340:28d1f895c6fe 85 * this list of conditions and the following disclaimer.
mbed_official 340:28d1f895c6fe 86 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 340:28d1f895c6fe 87 * this list of conditions and the following disclaimer in the documentation
mbed_official 340:28d1f895c6fe 88 * and/or other materials provided with the distribution.
mbed_official 340:28d1f895c6fe 89 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 340:28d1f895c6fe 90 * may be used to endorse or promote products derived from this software
mbed_official 340:28d1f895c6fe 91 * without specific prior written permission.
mbed_official 340:28d1f895c6fe 92 *
mbed_official 340:28d1f895c6fe 93 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 340:28d1f895c6fe 94 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 340:28d1f895c6fe 95 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 340:28d1f895c6fe 96 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 340:28d1f895c6fe 97 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 340:28d1f895c6fe 98 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 340:28d1f895c6fe 99 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 340:28d1f895c6fe 100 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 340:28d1f895c6fe 101 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 340:28d1f895c6fe 102 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 340:28d1f895c6fe 103 *
mbed_official 340:28d1f895c6fe 104 ******************************************************************************
mbed_official 340:28d1f895c6fe 105 */
mbed_official 340:28d1f895c6fe 106
mbed_official 340:28d1f895c6fe 107 /* Includes ------------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 108 #include "stm32f0xx_hal.h"
mbed_official 340:28d1f895c6fe 109
mbed_official 340:28d1f895c6fe 110 /** @addtogroup STM32F0xx_HAL_Driver
mbed_official 340:28d1f895c6fe 111 * @{
mbed_official 340:28d1f895c6fe 112 */
mbed_official 340:28d1f895c6fe 113
mbed_official 340:28d1f895c6fe 114 /** @defgroup IWDG IWDG HAL module driver
mbed_official 340:28d1f895c6fe 115 * @brief IWDG HAL module driver.
mbed_official 340:28d1f895c6fe 116 * @{
mbed_official 340:28d1f895c6fe 117 */
mbed_official 340:28d1f895c6fe 118
mbed_official 340:28d1f895c6fe 119 #ifdef HAL_IWDG_MODULE_ENABLED
mbed_official 340:28d1f895c6fe 120
mbed_official 340:28d1f895c6fe 121 /* Private typedef -----------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 122 /* Private define ------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 123
mbed_official 340:28d1f895c6fe 124 /** @defgroup IWDG_Private_Defines IWDG Private Defines
mbed_official 340:28d1f895c6fe 125 * @{
mbed_official 340:28d1f895c6fe 126 */
mbed_official 340:28d1f895c6fe 127
mbed_official 340:28d1f895c6fe 128 #define HAL_IWDG_DEFAULT_TIMEOUT (uint32_t)1000
mbed_official 340:28d1f895c6fe 129
mbed_official 340:28d1f895c6fe 130 /**
mbed_official 340:28d1f895c6fe 131 * @}
mbed_official 340:28d1f895c6fe 132 */
mbed_official 340:28d1f895c6fe 133
mbed_official 340:28d1f895c6fe 134 /* Private macro -------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 135 /* Private variables ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 136 /* Private function prototypes -----------------------------------------------*/
mbed_official 340:28d1f895c6fe 137 /* Private functions ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 138
mbed_official 340:28d1f895c6fe 139 /** @defgroup IWDG_Exported_Functions IWDG Exported Functions
mbed_official 340:28d1f895c6fe 140 * @{
mbed_official 340:28d1f895c6fe 141 */
mbed_official 340:28d1f895c6fe 142
mbed_official 340:28d1f895c6fe 143 /** @defgroup IWDG_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 340:28d1f895c6fe 144 * @brief Initialization and Configuration functions.
mbed_official 340:28d1f895c6fe 145 *
mbed_official 340:28d1f895c6fe 146 @verbatim
mbed_official 340:28d1f895c6fe 147 ===============================================================================
mbed_official 340:28d1f895c6fe 148 ##### Initialization functions #####
mbed_official 340:28d1f895c6fe 149 ===============================================================================
mbed_official 340:28d1f895c6fe 150 [..] This section provides functions allowing to:
mbed_official 340:28d1f895c6fe 151 (+) Initialize the IWDG according to the specified parameters
mbed_official 340:28d1f895c6fe 152 in the IWDG_InitTypeDef and create the associated handle
mbed_official 340:28d1f895c6fe 153 (+) Manage Window option
mbed_official 340:28d1f895c6fe 154 (+) Initialize the IWDG MSP
mbed_official 340:28d1f895c6fe 155 (+) DeInitialize IWDG MSP
mbed_official 340:28d1f895c6fe 156
mbed_official 340:28d1f895c6fe 157 @endverbatim
mbed_official 340:28d1f895c6fe 158 * @{
mbed_official 340:28d1f895c6fe 159 */
mbed_official 340:28d1f895c6fe 160
mbed_official 340:28d1f895c6fe 161 /**
mbed_official 340:28d1f895c6fe 162 * @brief Initializes the IWDG according to the specified
mbed_official 340:28d1f895c6fe 163 * parameters in the IWDG_InitTypeDef and creates the associated handle.
mbed_official 340:28d1f895c6fe 164 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 165 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 166 * @retval HAL status
mbed_official 340:28d1f895c6fe 167 */
mbed_official 340:28d1f895c6fe 168 HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 169 {
mbed_official 340:28d1f895c6fe 170 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 171
mbed_official 340:28d1f895c6fe 172 /* Check the IWDG handle allocation */
mbed_official 441:d2c15dda23c1 173 if(hiwdg == NULL)
mbed_official 340:28d1f895c6fe 174 {
mbed_official 340:28d1f895c6fe 175 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 176 }
mbed_official 340:28d1f895c6fe 177
mbed_official 340:28d1f895c6fe 178 /* Check the parameters */
mbed_official 340:28d1f895c6fe 179 assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
mbed_official 340:28d1f895c6fe 180 assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
mbed_official 340:28d1f895c6fe 181 assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
mbed_official 340:28d1f895c6fe 182 assert_param(IS_IWDG_WINDOW(hiwdg->Init.Window));
mbed_official 340:28d1f895c6fe 183
mbed_official 340:28d1f895c6fe 184 /* Check pending flag, if previous update not done, return error */
mbed_official 340:28d1f895c6fe 185 if((__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_PVU) != RESET)
mbed_official 340:28d1f895c6fe 186 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET)
mbed_official 340:28d1f895c6fe 187 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_WVU) != RESET))
mbed_official 340:28d1f895c6fe 188 {
mbed_official 340:28d1f895c6fe 189 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 190 }
mbed_official 340:28d1f895c6fe 191
mbed_official 340:28d1f895c6fe 192 if(hiwdg->State == HAL_IWDG_STATE_RESET)
mbed_official 340:28d1f895c6fe 193 {
mbed_official 340:28d1f895c6fe 194 /* Init the low level hardware */
mbed_official 340:28d1f895c6fe 195 HAL_IWDG_MspInit(hiwdg);
mbed_official 340:28d1f895c6fe 196 }
mbed_official 340:28d1f895c6fe 197
mbed_official 340:28d1f895c6fe 198 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 199 hiwdg->State = HAL_IWDG_STATE_BUSY;
mbed_official 340:28d1f895c6fe 200
mbed_official 340:28d1f895c6fe 201 /* Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers */
mbed_official 340:28d1f895c6fe 202 /* by writing 0x5555 in KR */
mbed_official 340:28d1f895c6fe 203 __HAL_IWDG_ENABLE_WRITE_ACCESS(hiwdg);
mbed_official 340:28d1f895c6fe 204
mbed_official 340:28d1f895c6fe 205 /* Write to IWDG registers the IWDG_Prescaler & IWDG_Reload values to work with */
mbed_official 340:28d1f895c6fe 206 MODIFY_REG(hiwdg->Instance->PR, IWDG_PR_PR, hiwdg->Init.Prescaler);
mbed_official 340:28d1f895c6fe 207 MODIFY_REG(hiwdg->Instance->RLR, IWDG_RLR_RL, hiwdg->Init.Reload);
mbed_official 340:28d1f895c6fe 208
mbed_official 340:28d1f895c6fe 209 /* check if window option is enabled */
mbed_official 340:28d1f895c6fe 210 if (((hiwdg->Init.Window) != IWDG_WINDOW_DISABLE) || ((hiwdg->Instance->WINR) != IWDG_WINDOW_DISABLE))
mbed_official 340:28d1f895c6fe 211 {
mbed_official 340:28d1f895c6fe 212 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 213
mbed_official 340:28d1f895c6fe 214 /* Wait for register to be updated */
mbed_official 340:28d1f895c6fe 215 while((uint32_t)(hiwdg->Instance->SR) != RESET)
mbed_official 340:28d1f895c6fe 216 {
mbed_official 340:28d1f895c6fe 217 if((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
mbed_official 340:28d1f895c6fe 218 {
mbed_official 340:28d1f895c6fe 219 /* Set IWDG state */
mbed_official 340:28d1f895c6fe 220 hiwdg->State = HAL_IWDG_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 221 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 222 }
mbed_official 340:28d1f895c6fe 223 }
mbed_official 340:28d1f895c6fe 224
mbed_official 340:28d1f895c6fe 225 /* Write to IWDG WINR the IWDG_Window value to compare with */
mbed_official 340:28d1f895c6fe 226 MODIFY_REG(hiwdg->Instance->WINR, IWDG_WINR_WIN, hiwdg->Init.Window);
mbed_official 340:28d1f895c6fe 227
mbed_official 340:28d1f895c6fe 228 }
mbed_official 340:28d1f895c6fe 229 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 230 hiwdg->State = HAL_IWDG_STATE_READY;
mbed_official 340:28d1f895c6fe 231
mbed_official 340:28d1f895c6fe 232 /* Return function status */
mbed_official 340:28d1f895c6fe 233 return HAL_OK;
mbed_official 340:28d1f895c6fe 234 }
mbed_official 340:28d1f895c6fe 235
mbed_official 340:28d1f895c6fe 236 /**
mbed_official 340:28d1f895c6fe 237 * @brief Initializes the IWDG MSP.
mbed_official 340:28d1f895c6fe 238 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 239 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 240 * @retval None
mbed_official 340:28d1f895c6fe 241 */
mbed_official 340:28d1f895c6fe 242 __weak void HAL_IWDG_MspInit(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 243 {
mbed_official 340:28d1f895c6fe 244 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 245 the HAL_IWDG_MspInit could be implemented in the user file
mbed_official 340:28d1f895c6fe 246 */
mbed_official 340:28d1f895c6fe 247 }
mbed_official 340:28d1f895c6fe 248
mbed_official 340:28d1f895c6fe 249 /**
mbed_official 340:28d1f895c6fe 250 * @}
mbed_official 340:28d1f895c6fe 251 */
mbed_official 340:28d1f895c6fe 252
mbed_official 340:28d1f895c6fe 253 /** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
mbed_official 340:28d1f895c6fe 254 * @brief IO operation functions
mbed_official 340:28d1f895c6fe 255 *
mbed_official 340:28d1f895c6fe 256 @verbatim
mbed_official 340:28d1f895c6fe 257 ===============================================================================
mbed_official 340:28d1f895c6fe 258 ##### IO operation functions #####
mbed_official 340:28d1f895c6fe 259 ===============================================================================
mbed_official 340:28d1f895c6fe 260 [..] This section provides functions allowing to:
mbed_official 340:28d1f895c6fe 261 (+) Start the IWDG.
mbed_official 340:28d1f895c6fe 262 (+) Refresh the IWDG.
mbed_official 340:28d1f895c6fe 263
mbed_official 340:28d1f895c6fe 264 @endverbatim
mbed_official 340:28d1f895c6fe 265 * @{
mbed_official 340:28d1f895c6fe 266 */
mbed_official 340:28d1f895c6fe 267
mbed_official 340:28d1f895c6fe 268 /**
mbed_official 340:28d1f895c6fe 269 * @brief Starts the IWDG.
mbed_official 340:28d1f895c6fe 270 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 271 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 272 * @retval HAL status
mbed_official 340:28d1f895c6fe 273 */
mbed_official 340:28d1f895c6fe 274 HAL_StatusTypeDef HAL_IWDG_Start(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 275 {
mbed_official 340:28d1f895c6fe 276 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 277
mbed_official 340:28d1f895c6fe 278 /* Process Locked */
mbed_official 340:28d1f895c6fe 279 __HAL_LOCK(hiwdg);
mbed_official 340:28d1f895c6fe 280
mbed_official 340:28d1f895c6fe 281 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 282 hiwdg->State = HAL_IWDG_STATE_BUSY;
mbed_official 340:28d1f895c6fe 283
mbed_official 340:28d1f895c6fe 284 /* Reload IWDG counter with value defined in the RLR register */
mbed_official 340:28d1f895c6fe 285 if ((hiwdg->Init.Window) == IWDG_WINDOW_DISABLE)
mbed_official 340:28d1f895c6fe 286 {
mbed_official 340:28d1f895c6fe 287 __HAL_IWDG_RELOAD_COUNTER(hiwdg);
mbed_official 340:28d1f895c6fe 288 }
mbed_official 340:28d1f895c6fe 289
mbed_official 340:28d1f895c6fe 290 /* Enable the IWDG peripheral */
mbed_official 340:28d1f895c6fe 291 __HAL_IWDG_START(hiwdg);
mbed_official 340:28d1f895c6fe 292
mbed_official 340:28d1f895c6fe 293 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 294
mbed_official 340:28d1f895c6fe 295 /* Wait until PVU, RVU, WVU flag are RESET */
mbed_official 340:28d1f895c6fe 296 while( (__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_PVU) != RESET)
mbed_official 340:28d1f895c6fe 297 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET)
mbed_official 340:28d1f895c6fe 298 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_WVU) != RESET) )
mbed_official 340:28d1f895c6fe 299 {
mbed_official 340:28d1f895c6fe 300 if((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
mbed_official 340:28d1f895c6fe 301 {
mbed_official 340:28d1f895c6fe 302 /* Set IWDG state */
mbed_official 340:28d1f895c6fe 303 hiwdg->State = HAL_IWDG_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 304
mbed_official 340:28d1f895c6fe 305 /* Process unlocked */
mbed_official 340:28d1f895c6fe 306 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 307
mbed_official 340:28d1f895c6fe 308 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 309 }
mbed_official 340:28d1f895c6fe 310 }
mbed_official 340:28d1f895c6fe 311
mbed_official 340:28d1f895c6fe 312 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 313 hiwdg->State = HAL_IWDG_STATE_READY;
mbed_official 340:28d1f895c6fe 314
mbed_official 340:28d1f895c6fe 315 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 316 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 317
mbed_official 340:28d1f895c6fe 318 /* Return function status */
mbed_official 340:28d1f895c6fe 319 return HAL_OK;
mbed_official 340:28d1f895c6fe 320 }
mbed_official 340:28d1f895c6fe 321
mbed_official 340:28d1f895c6fe 322 /**
mbed_official 340:28d1f895c6fe 323 * @brief Refreshes the IWDG.
mbed_official 340:28d1f895c6fe 324 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 325 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 326 * @retval HAL status
mbed_official 340:28d1f895c6fe 327 */
mbed_official 340:28d1f895c6fe 328 HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 329 {
mbed_official 340:28d1f895c6fe 330 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 331
mbed_official 340:28d1f895c6fe 332 /* Process Locked */
mbed_official 340:28d1f895c6fe 333 __HAL_LOCK(hiwdg);
mbed_official 340:28d1f895c6fe 334
mbed_official 340:28d1f895c6fe 335 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 336 hiwdg->State = HAL_IWDG_STATE_BUSY;
mbed_official 340:28d1f895c6fe 337
mbed_official 340:28d1f895c6fe 338 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 339
mbed_official 340:28d1f895c6fe 340 /* Wait until RVU flag is RESET */
mbed_official 340:28d1f895c6fe 341 while(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET)
mbed_official 340:28d1f895c6fe 342 {
mbed_official 340:28d1f895c6fe 343 if((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
mbed_official 340:28d1f895c6fe 344 {
mbed_official 340:28d1f895c6fe 345 /* Set IWDG state */
mbed_official 340:28d1f895c6fe 346 hiwdg->State = HAL_IWDG_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 347
mbed_official 340:28d1f895c6fe 348 /* Process unlocked */
mbed_official 340:28d1f895c6fe 349 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 350
mbed_official 340:28d1f895c6fe 351 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 352 }
mbed_official 340:28d1f895c6fe 353 }
mbed_official 340:28d1f895c6fe 354
mbed_official 340:28d1f895c6fe 355 /* Reload IWDG counter with value defined in the reload register */
mbed_official 340:28d1f895c6fe 356 __HAL_IWDG_RELOAD_COUNTER(hiwdg);
mbed_official 340:28d1f895c6fe 357
mbed_official 340:28d1f895c6fe 358 /* Change IWDG peripheral state */
mbed_official 340:28d1f895c6fe 359 hiwdg->State = HAL_IWDG_STATE_READY;
mbed_official 340:28d1f895c6fe 360
mbed_official 340:28d1f895c6fe 361 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 362 __HAL_UNLOCK(hiwdg);
mbed_official 340:28d1f895c6fe 363
mbed_official 340:28d1f895c6fe 364 /* Return function status */
mbed_official 340:28d1f895c6fe 365 return HAL_OK;
mbed_official 340:28d1f895c6fe 366 }
mbed_official 340:28d1f895c6fe 367
mbed_official 340:28d1f895c6fe 368 /**
mbed_official 340:28d1f895c6fe 369 * @}
mbed_official 340:28d1f895c6fe 370 */
mbed_official 340:28d1f895c6fe 371
mbed_official 340:28d1f895c6fe 372 /** @defgroup IWDG_Exported_Functions_Group3 Peripheral State functions
mbed_official 340:28d1f895c6fe 373 * @brief Peripheral State functions.
mbed_official 340:28d1f895c6fe 374 *
mbed_official 340:28d1f895c6fe 375 @verbatim
mbed_official 340:28d1f895c6fe 376 ===============================================================================
mbed_official 340:28d1f895c6fe 377 ##### Peripheral State functions #####
mbed_official 340:28d1f895c6fe 378 ===============================================================================
mbed_official 340:28d1f895c6fe 379 [..]
mbed_official 340:28d1f895c6fe 380 This subsection permits to get in run-time the status of the peripheral
mbed_official 340:28d1f895c6fe 381 and the data flow.
mbed_official 340:28d1f895c6fe 382
mbed_official 340:28d1f895c6fe 383 @endverbatim
mbed_official 340:28d1f895c6fe 384 * @{
mbed_official 340:28d1f895c6fe 385 */
mbed_official 340:28d1f895c6fe 386
mbed_official 340:28d1f895c6fe 387 /**
mbed_official 340:28d1f895c6fe 388 * @brief Returns the IWDG state.
mbed_official 340:28d1f895c6fe 389 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 390 * the configuration information for the specified IWDG module.
mbed_official 340:28d1f895c6fe 391 * @retval HAL state
mbed_official 340:28d1f895c6fe 392 */
mbed_official 340:28d1f895c6fe 393 HAL_IWDG_StateTypeDef HAL_IWDG_GetState(IWDG_HandleTypeDef *hiwdg)
mbed_official 340:28d1f895c6fe 394 {
mbed_official 340:28d1f895c6fe 395 return hiwdg->State;
mbed_official 340:28d1f895c6fe 396 }
mbed_official 340:28d1f895c6fe 397
mbed_official 340:28d1f895c6fe 398 /**
mbed_official 340:28d1f895c6fe 399 * @}
mbed_official 340:28d1f895c6fe 400 */
mbed_official 340:28d1f895c6fe 401
mbed_official 340:28d1f895c6fe 402 /**
mbed_official 340:28d1f895c6fe 403 * @}
mbed_official 340:28d1f895c6fe 404 */
mbed_official 340:28d1f895c6fe 405
mbed_official 340:28d1f895c6fe 406 #endif /* HAL_IWDG_MODULE_ENABLED */
mbed_official 340:28d1f895c6fe 407 /**
mbed_official 340:28d1f895c6fe 408 * @}
mbed_official 340:28d1f895c6fe 409 */
mbed_official 340:28d1f895c6fe 410
mbed_official 340:28d1f895c6fe 411 /**
mbed_official 340:28d1f895c6fe 412 * @}
mbed_official 340:28d1f895c6fe 413 */
mbed_official 340:28d1f895c6fe 414
mbed_official 340:28d1f895c6fe 415 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/