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