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