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