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