mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Sep 28 14:00:11 2015 +0100
Revision:
632:7687fb9c4f91
Parent:
385:be64abf45658
Child:
634:ac7d6880524d
Synchronized with git revision f7ce4ed029cc611121464252ff28d5e8beb895b0

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

NUCLEO_F303K8 - add support of the STM32F303K8

Who changed what in which revision?

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