mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu May 22 20:00:09 2014 +0100
Revision:
205:c41fc65bcfb4
Child:
218:44081b78fdc2
Synchronized with git revision ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb

Full URL: https://github.com/mbedmicro/mbed/commit/ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb/

[NUCLEO_F072RB] cmsis files

Who changed what in which revision?

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