Eric Lewiston / STM32L4xx_HAL_Driver

Dependents:   BSP OneHopeOnePrayer FINAL_AUDIO_RECORD AudioDemo

Fork of STM32L4xx_HAL_Driver by Senior Design: Sound Monitor

Committer:
EricLew
Date:
Mon Nov 02 19:37:23 2015 +0000
Revision:
0:80ee8f3b695e
Errors are with definitions of LCD and QSPI functions. I believe all .h and .c files are  uploaded, but there may need to be certain functions called.

Who changed what in which revision?

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