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