fix LPC812 PWM

Dependents:   IR_LED_Send

Fork of mbed-dev by mbed official

Committer:
nameless129
Date:
Mon May 16 16:50:30 2016 +0000
Revision:
129:2e517c56bcfb
Parent:
0:9b334a45a8ff
PWM Fix:Duty 0%??H???????????????

Who changed what in which revision?

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