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