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:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Parent:
573:ad23fe03a082
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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