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.
targets/cmsis/TARGET_STM/TARGET_STM32L1/stm32l1xx_hal_wwdg.c@1:71204b8406f2, 2015-07-24 (annotated)
- Committer:
- modtronix
- Date:
- Fri Jul 24 21:01:44 2015 +1000
- Revision:
- 1:71204b8406f2
- Child:
- 10:6444e6c798ce
Current mbed v103 (594)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| modtronix | 1:71204b8406f2 | 1 | /** |
| modtronix | 1:71204b8406f2 | 2 | ****************************************************************************** |
| modtronix | 1:71204b8406f2 | 3 | * @file stm32l1xx_hal_wwdg.c |
| modtronix | 1:71204b8406f2 | 4 | * @author MCD Application Team |
| modtronix | 1:71204b8406f2 | 5 | * @version V1.0.0 |
| modtronix | 1:71204b8406f2 | 6 | * @date 5-September-2014 |
| modtronix | 1:71204b8406f2 | 7 | * @brief WWDG HAL module driver. |
| modtronix | 1:71204b8406f2 | 8 | * This file provides firmware functions to manage the following |
| modtronix | 1:71204b8406f2 | 9 | * functionalities of the Window Watchdog (WWDG) peripheral: |
| modtronix | 1:71204b8406f2 | 10 | * + Initialization and de-initialization functions |
| modtronix | 1:71204b8406f2 | 11 | * + IO operation functions |
| modtronix | 1:71204b8406f2 | 12 | * + Peripheral State functions |
| modtronix | 1:71204b8406f2 | 13 | @verbatim |
| modtronix | 1:71204b8406f2 | 14 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 15 | ##### WWDG specific features ##### |
| modtronix | 1:71204b8406f2 | 16 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 17 | [..] |
| modtronix | 1:71204b8406f2 | 18 | Once enabled the WWDG generates a system reset on expiry of a programmed |
| modtronix | 1:71204b8406f2 | 19 | time period, unless the program refreshes the counter (downcounter) |
| modtronix | 1:71204b8406f2 | 20 | before reaching 0x3F value (i.e. a reset is generated when the counter |
| modtronix | 1:71204b8406f2 | 21 | value rolls over from 0x40 to 0x3F). |
| modtronix | 1:71204b8406f2 | 22 | |
| modtronix | 1:71204b8406f2 | 23 | (+) An MCU reset is also generated if the counter value is refreshed |
| modtronix | 1:71204b8406f2 | 24 | before the counter has reached the refresh window value. This |
| modtronix | 1:71204b8406f2 | 25 | implies that the counter must be refreshed in a limited window. |
| modtronix | 1:71204b8406f2 | 26 | (+) Once enabled the WWDG cannot be disabled except by a system reset. |
| modtronix | 1:71204b8406f2 | 27 | (+) WWDGRST flag in RCC_CSR register can be used to inform when a WWDG |
| modtronix | 1:71204b8406f2 | 28 | reset occurs. |
| modtronix | 1:71204b8406f2 | 29 | (+) The WWDG counter input clock is derived from the APB clock divided |
| modtronix | 1:71204b8406f2 | 30 | by a programmable prescaler. |
| modtronix | 1:71204b8406f2 | 31 | (+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler) |
| modtronix | 1:71204b8406f2 | 32 | (+) WWDG timeout (mS) = 1000 * Counter / WWDG clock |
| modtronix | 1:71204b8406f2 | 33 | (+) WWDG Counter refresh is allowed between the following limits : |
| modtronix | 1:71204b8406f2 | 34 | (++) min time (mS) = 1000 * (Counter Window) / WWDG clock |
| modtronix | 1:71204b8406f2 | 35 | (++) max time (mS) = 1000 * (Counter 0x40) / WWDG clock |
| modtronix | 1:71204b8406f2 | 36 | |
| modtronix | 1:71204b8406f2 | 37 | (+) Min-max timeout value at @32MHz (PCLK1): ~128us / ~65.6ms. |
| modtronix | 1:71204b8406f2 | 38 | |
| modtronix | 1:71204b8406f2 | 39 | |
| modtronix | 1:71204b8406f2 | 40 | ##### How to use this driver ##### |
| modtronix | 1:71204b8406f2 | 41 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 42 | [..] |
| modtronix | 1:71204b8406f2 | 43 | (+) Enable WWDG APB1 clock using __WWDG_CLK_ENABLE(). |
| modtronix | 1:71204b8406f2 | 44 | (+) Set the WWDG prescaler, refresh window and counter value |
| modtronix | 1:71204b8406f2 | 45 | using HAL_WWDG_Init() function. |
| modtronix | 1:71204b8406f2 | 46 | (+) Start the WWDG using HAL_WWDG_Start() function. |
| modtronix | 1:71204b8406f2 | 47 | When the WWDG is enabled the counter value should be configured to |
| modtronix | 1:71204b8406f2 | 48 | a value greater than 0x40 to prevent generating an immediate reset. |
| modtronix | 1:71204b8406f2 | 49 | (+) Optionally you can enable the Early Wakeup Interrupt (EWI) which is |
| modtronix | 1:71204b8406f2 | 50 | generated when the counter reaches 0x40, and then start the WWDG using |
| modtronix | 1:71204b8406f2 | 51 | HAL_WWDG_Start_IT(). At EWI HAL_WWDG_WakeupCallback is executed and user can |
| modtronix | 1:71204b8406f2 | 52 | add his own code by customization of function pointer HAL_WWDG_WakeupCallback |
| modtronix | 1:71204b8406f2 | 53 | Once enabled, EWI interrupt cannot be disabled except by a system reset. |
| modtronix | 1:71204b8406f2 | 54 | (+) Then the application program must refresh the WWDG counter at regular |
| modtronix | 1:71204b8406f2 | 55 | intervals during normal operation to prevent an MCU reset, using |
| modtronix | 1:71204b8406f2 | 56 | HAL_WWDG_Refresh() function. This operation must occur only when |
| modtronix | 1:71204b8406f2 | 57 | the counter is lower than the refresh window value already programmed. |
| modtronix | 1:71204b8406f2 | 58 | |
| modtronix | 1:71204b8406f2 | 59 | *** WWDG HAL driver macros list *** |
| modtronix | 1:71204b8406f2 | 60 | ================================== |
| modtronix | 1:71204b8406f2 | 61 | [..] |
| modtronix | 1:71204b8406f2 | 62 | Below the list of most used macros in WWDG HAL driver. |
| modtronix | 1:71204b8406f2 | 63 | |
| modtronix | 1:71204b8406f2 | 64 | (+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral |
| modtronix | 1:71204b8406f2 | 65 | (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status |
| modtronix | 1:71204b8406f2 | 66 | (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags |
| modtronix | 1:71204b8406f2 | 67 | (+) __HAL_WWDG_ENABLE_IT: Enables the WWDG early wakeup interrupt |
| modtronix | 1:71204b8406f2 | 68 | |
| modtronix | 1:71204b8406f2 | 69 | @endverbatim |
| modtronix | 1:71204b8406f2 | 70 | ****************************************************************************** |
| modtronix | 1:71204b8406f2 | 71 | * @attention |
| modtronix | 1:71204b8406f2 | 72 | * |
| modtronix | 1:71204b8406f2 | 73 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
| modtronix | 1:71204b8406f2 | 74 | * |
| modtronix | 1:71204b8406f2 | 75 | * Redistribution and use in source and binary forms, with or without modification, |
| modtronix | 1:71204b8406f2 | 76 | * are permitted provided that the following conditions are met: |
| modtronix | 1:71204b8406f2 | 77 | * 1. Redistributions of source code must retain the above copyright notice, |
| modtronix | 1:71204b8406f2 | 78 | * this list of conditions and the following disclaimer. |
| modtronix | 1:71204b8406f2 | 79 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| modtronix | 1:71204b8406f2 | 80 | * this list of conditions and the following disclaimer in the documentation |
| modtronix | 1:71204b8406f2 | 81 | * and/or other materials provided with the distribution. |
| modtronix | 1:71204b8406f2 | 82 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| modtronix | 1:71204b8406f2 | 83 | * may be used to endorse or promote products derived from this software |
| modtronix | 1:71204b8406f2 | 84 | * without specific prior written permission. |
| modtronix | 1:71204b8406f2 | 85 | * |
| modtronix | 1:71204b8406f2 | 86 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| modtronix | 1:71204b8406f2 | 87 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| modtronix | 1:71204b8406f2 | 88 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| modtronix | 1:71204b8406f2 | 89 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| modtronix | 1:71204b8406f2 | 90 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| modtronix | 1:71204b8406f2 | 91 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| modtronix | 1:71204b8406f2 | 92 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| modtronix | 1:71204b8406f2 | 93 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| modtronix | 1:71204b8406f2 | 94 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| modtronix | 1:71204b8406f2 | 95 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| modtronix | 1:71204b8406f2 | 96 | * |
| modtronix | 1:71204b8406f2 | 97 | ****************************************************************************** |
| modtronix | 1:71204b8406f2 | 98 | */ |
| modtronix | 1:71204b8406f2 | 99 | |
| modtronix | 1:71204b8406f2 | 100 | /* Includes ------------------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 101 | #include "stm32l1xx_hal.h" |
| modtronix | 1:71204b8406f2 | 102 | |
| modtronix | 1:71204b8406f2 | 103 | /** @addtogroup STM32L1xx_HAL_Driver |
| modtronix | 1:71204b8406f2 | 104 | * @{ |
| modtronix | 1:71204b8406f2 | 105 | */ |
| modtronix | 1:71204b8406f2 | 106 | |
| modtronix | 1:71204b8406f2 | 107 | /** @defgroup WWDG WWDG |
| modtronix | 1:71204b8406f2 | 108 | * @brief WWDG HAL module driver. |
| modtronix | 1:71204b8406f2 | 109 | * @{ |
| modtronix | 1:71204b8406f2 | 110 | */ |
| modtronix | 1:71204b8406f2 | 111 | |
| modtronix | 1:71204b8406f2 | 112 | #ifdef HAL_WWDG_MODULE_ENABLED |
| modtronix | 1:71204b8406f2 | 113 | |
| modtronix | 1:71204b8406f2 | 114 | /* Private typedef -----------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 115 | /* Private define ------------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 116 | /* Private macro -------------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 117 | /* Private variables ---------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 118 | /* Private function prototypes -----------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 119 | /* Private functions ---------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 120 | |
| modtronix | 1:71204b8406f2 | 121 | /** @defgroup WWDG_Exported_Functions WWDG Exported Functions |
| modtronix | 1:71204b8406f2 | 122 | * @{ |
| modtronix | 1:71204b8406f2 | 123 | */ |
| modtronix | 1:71204b8406f2 | 124 | |
| modtronix | 1:71204b8406f2 | 125 | /** @defgroup WWDG_Exported_Functions_Group1 Initialization and de-initialization functions |
| modtronix | 1:71204b8406f2 | 126 | * @brief Initialization and Configuration functions. |
| modtronix | 1:71204b8406f2 | 127 | * |
| modtronix | 1:71204b8406f2 | 128 | @verbatim |
| modtronix | 1:71204b8406f2 | 129 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 130 | ##### Initialization and de-initialization functions ##### |
| modtronix | 1:71204b8406f2 | 131 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 132 | [..] |
| modtronix | 1:71204b8406f2 | 133 | This section provides functions allowing to: |
| modtronix | 1:71204b8406f2 | 134 | (+) Initialize the WWDG according to the specified parameters |
| modtronix | 1:71204b8406f2 | 135 | in the WWDG_InitTypeDef and create the associated handle |
| modtronix | 1:71204b8406f2 | 136 | (+) DeInitialize the WWDG peripheral |
| modtronix | 1:71204b8406f2 | 137 | (+) Initialize the WWDG MSP |
| modtronix | 1:71204b8406f2 | 138 | (+) DeInitialize the WWDG MSP |
| modtronix | 1:71204b8406f2 | 139 | |
| modtronix | 1:71204b8406f2 | 140 | @endverbatim |
| modtronix | 1:71204b8406f2 | 141 | * @{ |
| modtronix | 1:71204b8406f2 | 142 | */ |
| modtronix | 1:71204b8406f2 | 143 | |
| modtronix | 1:71204b8406f2 | 144 | /** |
| modtronix | 1:71204b8406f2 | 145 | * @brief Initializes the WWDG according to the specified |
| modtronix | 1:71204b8406f2 | 146 | * parameters in the WWDG_InitTypeDef and creates the associated handle. |
| modtronix | 1:71204b8406f2 | 147 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 148 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 149 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 150 | */ |
| modtronix | 1:71204b8406f2 | 151 | HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 152 | { |
| modtronix | 1:71204b8406f2 | 153 | /* Check the WWDG handle allocation */ |
| modtronix | 1:71204b8406f2 | 154 | if(hwwdg == HAL_NULL) |
| modtronix | 1:71204b8406f2 | 155 | { |
| modtronix | 1:71204b8406f2 | 156 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 157 | } |
| modtronix | 1:71204b8406f2 | 158 | |
| modtronix | 1:71204b8406f2 | 159 | /* Check the parameters */ |
| modtronix | 1:71204b8406f2 | 160 | assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance)); |
| modtronix | 1:71204b8406f2 | 161 | assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler)); |
| modtronix | 1:71204b8406f2 | 162 | assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window)); |
| modtronix | 1:71204b8406f2 | 163 | assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter)); |
| modtronix | 1:71204b8406f2 | 164 | |
| modtronix | 1:71204b8406f2 | 165 | if(hwwdg->State == HAL_WWDG_STATE_RESET) |
| modtronix | 1:71204b8406f2 | 166 | { |
| modtronix | 1:71204b8406f2 | 167 | /* Init the low level hardware */ |
| modtronix | 1:71204b8406f2 | 168 | HAL_WWDG_MspInit(hwwdg); |
| modtronix | 1:71204b8406f2 | 169 | } |
| modtronix | 1:71204b8406f2 | 170 | |
| modtronix | 1:71204b8406f2 | 171 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 172 | hwwdg->State = HAL_WWDG_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 173 | |
| modtronix | 1:71204b8406f2 | 174 | /* Set WWDG Prescaler and Window */ |
| modtronix | 1:71204b8406f2 | 175 | MODIFY_REG(hwwdg->Instance->CFR, (WWDG_CFR_WDGTB | WWDG_CFR_W), (hwwdg->Init.Prescaler | hwwdg->Init.Window)); |
| modtronix | 1:71204b8406f2 | 176 | |
| modtronix | 1:71204b8406f2 | 177 | /* Set WWDG Counter */ |
| modtronix | 1:71204b8406f2 | 178 | MODIFY_REG(hwwdg->Instance->CR, WWDG_CR_T, hwwdg->Init.Counter); |
| modtronix | 1:71204b8406f2 | 179 | |
| modtronix | 1:71204b8406f2 | 180 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 181 | hwwdg->State = HAL_WWDG_STATE_READY; |
| modtronix | 1:71204b8406f2 | 182 | |
| modtronix | 1:71204b8406f2 | 183 | /* Return function status */ |
| modtronix | 1:71204b8406f2 | 184 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 185 | } |
| modtronix | 1:71204b8406f2 | 186 | |
| modtronix | 1:71204b8406f2 | 187 | /** |
| modtronix | 1:71204b8406f2 | 188 | * @brief DeInitializes the WWDG peripheral. |
| modtronix | 1:71204b8406f2 | 189 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 190 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 191 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 192 | */ |
| modtronix | 1:71204b8406f2 | 193 | HAL_StatusTypeDef HAL_WWDG_DeInit(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 194 | { |
| modtronix | 1:71204b8406f2 | 195 | /* Check the parameters */ |
| modtronix | 1:71204b8406f2 | 196 | assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance)); |
| modtronix | 1:71204b8406f2 | 197 | |
| modtronix | 1:71204b8406f2 | 198 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 199 | hwwdg->State = HAL_WWDG_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 200 | |
| modtronix | 1:71204b8406f2 | 201 | /* DeInit the low level hardware */ |
| modtronix | 1:71204b8406f2 | 202 | HAL_WWDG_MspDeInit(hwwdg); |
| modtronix | 1:71204b8406f2 | 203 | |
| modtronix | 1:71204b8406f2 | 204 | /* Reset WWDG Control register */ |
| modtronix | 1:71204b8406f2 | 205 | hwwdg->Instance->CR = (uint32_t)0x0000007F; |
| modtronix | 1:71204b8406f2 | 206 | |
| modtronix | 1:71204b8406f2 | 207 | /* Reset WWDG Configuration register */ |
| modtronix | 1:71204b8406f2 | 208 | hwwdg->Instance->CFR = (uint32_t)0x0000007F; |
| modtronix | 1:71204b8406f2 | 209 | |
| modtronix | 1:71204b8406f2 | 210 | /* Reset WWDG Status register */ |
| modtronix | 1:71204b8406f2 | 211 | hwwdg->Instance->SR = 0; |
| modtronix | 1:71204b8406f2 | 212 | |
| modtronix | 1:71204b8406f2 | 213 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 214 | hwwdg->State = HAL_WWDG_STATE_RESET; |
| modtronix | 1:71204b8406f2 | 215 | |
| modtronix | 1:71204b8406f2 | 216 | /* Release Lock */ |
| modtronix | 1:71204b8406f2 | 217 | __HAL_UNLOCK(hwwdg); |
| modtronix | 1:71204b8406f2 | 218 | |
| modtronix | 1:71204b8406f2 | 219 | /* Return function status */ |
| modtronix | 1:71204b8406f2 | 220 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 221 | } |
| modtronix | 1:71204b8406f2 | 222 | |
| modtronix | 1:71204b8406f2 | 223 | /** |
| modtronix | 1:71204b8406f2 | 224 | * @brief Initializes the WWDG MSP. |
| modtronix | 1:71204b8406f2 | 225 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 226 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 227 | * @retval None |
| modtronix | 1:71204b8406f2 | 228 | */ |
| modtronix | 1:71204b8406f2 | 229 | __weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 230 | { |
| modtronix | 1:71204b8406f2 | 231 | /* NOTE: This function Should not be modified, when the callback is needed, |
| modtronix | 1:71204b8406f2 | 232 | the HAL_WWDG_MspInit could be implemented in the user file |
| modtronix | 1:71204b8406f2 | 233 | */ |
| modtronix | 1:71204b8406f2 | 234 | } |
| modtronix | 1:71204b8406f2 | 235 | |
| modtronix | 1:71204b8406f2 | 236 | /** |
| modtronix | 1:71204b8406f2 | 237 | * @brief DeInitializes the WWDG MSP. |
| modtronix | 1:71204b8406f2 | 238 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 239 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 240 | * @retval None |
| modtronix | 1:71204b8406f2 | 241 | */ |
| modtronix | 1:71204b8406f2 | 242 | __weak void HAL_WWDG_MspDeInit(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 243 | { |
| modtronix | 1:71204b8406f2 | 244 | /* NOTE: This function Should not be modified, when the callback is needed, |
| modtronix | 1:71204b8406f2 | 245 | the HAL_WWDG_MspDeInit could be implemented in the user file |
| modtronix | 1:71204b8406f2 | 246 | */ |
| modtronix | 1:71204b8406f2 | 247 | } |
| modtronix | 1:71204b8406f2 | 248 | |
| modtronix | 1:71204b8406f2 | 249 | /** |
| modtronix | 1:71204b8406f2 | 250 | * @} |
| modtronix | 1:71204b8406f2 | 251 | */ |
| modtronix | 1:71204b8406f2 | 252 | |
| modtronix | 1:71204b8406f2 | 253 | /** @defgroup WWDG_Exported_Functions_Group2 IO operation functions |
| modtronix | 1:71204b8406f2 | 254 | * @brief IO operation functions |
| modtronix | 1:71204b8406f2 | 255 | * |
| modtronix | 1:71204b8406f2 | 256 | @verbatim |
| modtronix | 1:71204b8406f2 | 257 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 258 | ##### IO operation functions ##### |
| modtronix | 1:71204b8406f2 | 259 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 260 | [..] |
| modtronix | 1:71204b8406f2 | 261 | This section provides functions allowing to: |
| modtronix | 1:71204b8406f2 | 262 | (+) Start the WWDG. |
| modtronix | 1:71204b8406f2 | 263 | (+) Refresh the WWDG. |
| modtronix | 1:71204b8406f2 | 264 | (+) Handle WWDG interrupt request. |
| modtronix | 1:71204b8406f2 | 265 | |
| modtronix | 1:71204b8406f2 | 266 | @endverbatim |
| modtronix | 1:71204b8406f2 | 267 | * @{ |
| modtronix | 1:71204b8406f2 | 268 | */ |
| modtronix | 1:71204b8406f2 | 269 | |
| modtronix | 1:71204b8406f2 | 270 | /** |
| modtronix | 1:71204b8406f2 | 271 | * @brief Starts the WWDG. |
| modtronix | 1:71204b8406f2 | 272 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 273 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 274 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 275 | */ |
| modtronix | 1:71204b8406f2 | 276 | HAL_StatusTypeDef HAL_WWDG_Start(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 277 | { |
| modtronix | 1:71204b8406f2 | 278 | /* Process Locked */ |
| modtronix | 1:71204b8406f2 | 279 | __HAL_LOCK(hwwdg); |
| modtronix | 1:71204b8406f2 | 280 | |
| modtronix | 1:71204b8406f2 | 281 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 282 | hwwdg->State = HAL_WWDG_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 283 | |
| modtronix | 1:71204b8406f2 | 284 | /* Enable the peripheral */ |
| modtronix | 1:71204b8406f2 | 285 | __HAL_WWDG_ENABLE(hwwdg); |
| modtronix | 1:71204b8406f2 | 286 | |
| modtronix | 1:71204b8406f2 | 287 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 288 | hwwdg->State = HAL_WWDG_STATE_READY; |
| modtronix | 1:71204b8406f2 | 289 | |
| modtronix | 1:71204b8406f2 | 290 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 291 | __HAL_UNLOCK(hwwdg); |
| modtronix | 1:71204b8406f2 | 292 | |
| modtronix | 1:71204b8406f2 | 293 | /* Return function status */ |
| modtronix | 1:71204b8406f2 | 294 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 295 | } |
| modtronix | 1:71204b8406f2 | 296 | |
| modtronix | 1:71204b8406f2 | 297 | /** |
| modtronix | 1:71204b8406f2 | 298 | * @brief Starts the WWDG with interrupt enabled. |
| modtronix | 1:71204b8406f2 | 299 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 300 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 301 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 302 | */ |
| modtronix | 1:71204b8406f2 | 303 | HAL_StatusTypeDef HAL_WWDG_Start_IT(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 304 | { |
| modtronix | 1:71204b8406f2 | 305 | /* Process Locked */ |
| modtronix | 1:71204b8406f2 | 306 | __HAL_LOCK(hwwdg); |
| modtronix | 1:71204b8406f2 | 307 | |
| modtronix | 1:71204b8406f2 | 308 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 309 | hwwdg->State = HAL_WWDG_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 310 | |
| modtronix | 1:71204b8406f2 | 311 | /* Enable the Early Wakeup Interrupt */ |
| modtronix | 1:71204b8406f2 | 312 | __HAL_WWDG_ENABLE_IT(WWDG_IT_EWI); |
| modtronix | 1:71204b8406f2 | 313 | |
| modtronix | 1:71204b8406f2 | 314 | /* Enable the peripheral */ |
| modtronix | 1:71204b8406f2 | 315 | __HAL_WWDG_ENABLE(hwwdg); |
| modtronix | 1:71204b8406f2 | 316 | |
| modtronix | 1:71204b8406f2 | 317 | /* Return function status */ |
| modtronix | 1:71204b8406f2 | 318 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 319 | } |
| modtronix | 1:71204b8406f2 | 320 | |
| modtronix | 1:71204b8406f2 | 321 | /** |
| modtronix | 1:71204b8406f2 | 322 | * @brief Refreshes the WWDG. |
| modtronix | 1:71204b8406f2 | 323 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 324 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 325 | * @param Counter: value of counter to put in WWDG counter |
| modtronix | 1:71204b8406f2 | 326 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 327 | */ |
| modtronix | 1:71204b8406f2 | 328 | HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg, uint32_t Counter) |
| modtronix | 1:71204b8406f2 | 329 | { |
| modtronix | 1:71204b8406f2 | 330 | /* Process Locked */ |
| modtronix | 1:71204b8406f2 | 331 | __HAL_LOCK(hwwdg); |
| modtronix | 1:71204b8406f2 | 332 | |
| modtronix | 1:71204b8406f2 | 333 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 334 | hwwdg->State = HAL_WWDG_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 335 | |
| modtronix | 1:71204b8406f2 | 336 | /* Check the parameters */ |
| modtronix | 1:71204b8406f2 | 337 | assert_param(IS_WWDG_COUNTER(Counter)); |
| modtronix | 1:71204b8406f2 | 338 | |
| modtronix | 1:71204b8406f2 | 339 | /* Write to WWDG CR the WWDG Counter value to refresh with */ |
| modtronix | 1:71204b8406f2 | 340 | MODIFY_REG(hwwdg->Instance->CR, (uint32_t)WWDG_CR_T, Counter); |
| modtronix | 1:71204b8406f2 | 341 | |
| modtronix | 1:71204b8406f2 | 342 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 343 | hwwdg->State = HAL_WWDG_STATE_READY; |
| modtronix | 1:71204b8406f2 | 344 | |
| modtronix | 1:71204b8406f2 | 345 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 346 | __HAL_UNLOCK(hwwdg); |
| modtronix | 1:71204b8406f2 | 347 | |
| modtronix | 1:71204b8406f2 | 348 | /* Return function status */ |
| modtronix | 1:71204b8406f2 | 349 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 350 | } |
| modtronix | 1:71204b8406f2 | 351 | |
| modtronix | 1:71204b8406f2 | 352 | /** |
| modtronix | 1:71204b8406f2 | 353 | * @brief Handles WWDG interrupt request. |
| modtronix | 1:71204b8406f2 | 354 | * @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations |
| modtronix | 1:71204b8406f2 | 355 | * or data logging must be performed before the actual reset is generated. |
| modtronix | 1:71204b8406f2 | 356 | * The EWI interrupt is enabled using __HAL_WWDG_ENABLE_IT() macro. |
| modtronix | 1:71204b8406f2 | 357 | * When the downcounter reaches the value 0x40, and EWI interrupt is |
| modtronix | 1:71204b8406f2 | 358 | * generated and the corresponding Interrupt Service Routine (ISR) can |
| modtronix | 1:71204b8406f2 | 359 | * be used to trigger specific actions (such as communications or data |
| modtronix | 1:71204b8406f2 | 360 | * logging), before resetting the device. |
| modtronix | 1:71204b8406f2 | 361 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 362 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 363 | * @retval None |
| modtronix | 1:71204b8406f2 | 364 | */ |
| modtronix | 1:71204b8406f2 | 365 | void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 366 | { |
| modtronix | 1:71204b8406f2 | 367 | /* WWDG Early Wakeup Interrupt occurred */ |
| modtronix | 1:71204b8406f2 | 368 | if(__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET) |
| modtronix | 1:71204b8406f2 | 369 | { |
| modtronix | 1:71204b8406f2 | 370 | /* Early Wakeup callback */ |
| modtronix | 1:71204b8406f2 | 371 | HAL_WWDG_WakeupCallback(hwwdg); |
| modtronix | 1:71204b8406f2 | 372 | |
| modtronix | 1:71204b8406f2 | 373 | /* Change WWDG peripheral state */ |
| modtronix | 1:71204b8406f2 | 374 | hwwdg->State = HAL_WWDG_STATE_READY; |
| modtronix | 1:71204b8406f2 | 375 | |
| modtronix | 1:71204b8406f2 | 376 | /* Clear the WWDG Data Ready flag */ |
| modtronix | 1:71204b8406f2 | 377 | __HAL_WWDG_CLEAR_IT(hwwdg, WWDG_FLAG_EWIF); |
| modtronix | 1:71204b8406f2 | 378 | |
| modtronix | 1:71204b8406f2 | 379 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 380 | __HAL_UNLOCK(hwwdg); |
| modtronix | 1:71204b8406f2 | 381 | } |
| modtronix | 1:71204b8406f2 | 382 | } |
| modtronix | 1:71204b8406f2 | 383 | |
| modtronix | 1:71204b8406f2 | 384 | /** |
| modtronix | 1:71204b8406f2 | 385 | * @brief Early Wakeup WWDG callback. |
| modtronix | 1:71204b8406f2 | 386 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 387 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 388 | * @retval None |
| modtronix | 1:71204b8406f2 | 389 | */ |
| modtronix | 1:71204b8406f2 | 390 | __weak void HAL_WWDG_WakeupCallback(WWDG_HandleTypeDef* hwwdg) |
| modtronix | 1:71204b8406f2 | 391 | { |
| modtronix | 1:71204b8406f2 | 392 | /* NOTE: This function Should not be modified, when the callback is needed, |
| modtronix | 1:71204b8406f2 | 393 | the HAL_WWDG_WakeupCallback could be implemented in the user file |
| modtronix | 1:71204b8406f2 | 394 | */ |
| modtronix | 1:71204b8406f2 | 395 | } |
| modtronix | 1:71204b8406f2 | 396 | |
| modtronix | 1:71204b8406f2 | 397 | /** |
| modtronix | 1:71204b8406f2 | 398 | * @} |
| modtronix | 1:71204b8406f2 | 399 | */ |
| modtronix | 1:71204b8406f2 | 400 | |
| modtronix | 1:71204b8406f2 | 401 | /** @defgroup WWDG_Exported_Functions_Group3 Peripheral State functions |
| modtronix | 1:71204b8406f2 | 402 | * @brief Peripheral State functions. |
| modtronix | 1:71204b8406f2 | 403 | * |
| modtronix | 1:71204b8406f2 | 404 | @verbatim |
| modtronix | 1:71204b8406f2 | 405 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 406 | ##### Peripheral State functions ##### |
| modtronix | 1:71204b8406f2 | 407 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 408 | [..] |
| modtronix | 1:71204b8406f2 | 409 | This subsection permits to get in run-time the status of the peripheral |
| modtronix | 1:71204b8406f2 | 410 | and the data flow. |
| modtronix | 1:71204b8406f2 | 411 | |
| modtronix | 1:71204b8406f2 | 412 | @endverbatim |
| modtronix | 1:71204b8406f2 | 413 | * @{ |
| modtronix | 1:71204b8406f2 | 414 | */ |
| modtronix | 1:71204b8406f2 | 415 | |
| modtronix | 1:71204b8406f2 | 416 | /** |
| modtronix | 1:71204b8406f2 | 417 | * @brief Returns the WWDG state. |
| modtronix | 1:71204b8406f2 | 418 | * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 419 | * the configuration information for the specified WWDG module. |
| modtronix | 1:71204b8406f2 | 420 | * @retval HAL state |
| modtronix | 1:71204b8406f2 | 421 | */ |
| modtronix | 1:71204b8406f2 | 422 | HAL_WWDG_StateTypeDef HAL_WWDG_GetState(WWDG_HandleTypeDef *hwwdg) |
| modtronix | 1:71204b8406f2 | 423 | { |
| modtronix | 1:71204b8406f2 | 424 | return hwwdg->State; |
| modtronix | 1:71204b8406f2 | 425 | } |
| modtronix | 1:71204b8406f2 | 426 | |
| modtronix | 1:71204b8406f2 | 427 | /** |
| modtronix | 1:71204b8406f2 | 428 | * @} |
| modtronix | 1:71204b8406f2 | 429 | */ |
| modtronix | 1:71204b8406f2 | 430 | |
| modtronix | 1:71204b8406f2 | 431 | /** |
| modtronix | 1:71204b8406f2 | 432 | * @} |
| modtronix | 1:71204b8406f2 | 433 | */ |
| modtronix | 1:71204b8406f2 | 434 | |
| modtronix | 1:71204b8406f2 | 435 | #endif /* HAL_WWDG_MODULE_ENABLED */ |
| modtronix | 1:71204b8406f2 | 436 | /** |
| modtronix | 1:71204b8406f2 | 437 | * @} |
| modtronix | 1:71204b8406f2 | 438 | */ |
| modtronix | 1:71204b8406f2 | 439 | |
| modtronix | 1:71204b8406f2 | 440 | /** |
| modtronix | 1:71204b8406f2 | 441 | * @} |
| modtronix | 1:71204b8406f2 | 442 | */ |
| modtronix | 1:71204b8406f2 | 443 | |
| modtronix | 1:71204b8406f2 | 444 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |