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