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