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