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.
Fork of TUKS-COURSE-TIMER by
stm32l4xx_hal_wwdg.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_wwdg.c 00004 * @author MCD Application Team 00005 * @version V1.5.1 00006 * @date 31-May-2016 00007 * @brief WWDG HAL module driver. 00008 * This file provides firmware functions to manage the following 00009 * functionalities of the Window Watchdog (WWDG) peripheral: 00010 * + Initialization and Configuration function 00011 * + IO operation functions 00012 @verbatim 00013 ============================================================================== 00014 ##### WWDG specific features ##### 00015 ============================================================================== 00016 [..] 00017 Once enabled the WWDG generates a system reset on expiry of a programmed 00018 time period, unless the program refreshes the counter (T[6;0] downcounter) 00019 before reaching 0x3F value (i.e. a reset is generated when the counter 00020 value rolls over from 0x40 to 0x3F). 00021 00022 (+) An MCU reset is also generated if the counter value is refreshed 00023 before the counter has reached the refresh window value. This 00024 implies that the counter must be refreshed in a limited window. 00025 00026 (+) Once enabled the WWDG cannot be disabled except by a system reset. 00027 00028 (+) WWDGRST flag in RCC_CSR register informs when a WWDG reset has 00029 occurred (check available with __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)). 00030 00031 (+) The WWDG downcounter input clock is derived from the APB clock divided 00032 by a programmable prescaler. 00033 00034 (+) WWDG downcounter clock (Hz) = PCLK1 / (4096 * Prescaler) 00035 00036 (+) WWDG timeout (ms) = (1000 * (T[5;0] + 1)) / (WWDG downcounter clock) 00037 where T[5;0] are the lowest 6 bits of downcounter. 00038 00039 (+) WWDG Counter refresh is allowed between the following limits : 00040 (++) min time (ms) = (1000 * (T[5;0] - Window)) / (WWDG downcounter clock) 00041 (++) max time (ms) = (1000 * (T[5;0] - 0x40)) / (WWDG downcounter clock) 00042 00043 (+) Min-max timeout value @80 MHz(PCLK1): ~51.2 us / ~26.22 ms 00044 00045 (+) The Early Wakeup Interrupt (EWI) can be used if specific safety 00046 operations or data logging must be performed before the actual reset is 00047 generated. When the downcounter reaches the value 0x40, an EWI interrupt 00048 is generated and the corresponding interrupt service routine (ISR) can 00049 be used to trigger specific actions (such as communications or data 00050 logging), before resetting the device. 00051 In some applications, the EWI interrupt can be used to manage a software 00052 system check and/or system recovery/graceful degradation, without 00053 generating a WWDG reset. In this case, the corresponding interrupt 00054 service routine (ISR) should reload the WWDG counter to avoid the WWDG 00055 reset, then trigger the required actions. 00056 Note:When the EWI interrupt cannot be served, e.g. due to a system lock 00057 in a higher priority task, the WWDG reset will eventually be generated. 00058 00059 (+) Debug mode : When the microcontroller enters debug mode (core halted), 00060 the WWDG counter either continues to work normally or stops, depending 00061 on DBG_WWDG_STOP configuration bit in DBG module, accessible through 00062 __HAL_DBGMCU_FREEZE_WWDG() and __HAL_DBGMCU_UNFREEZE_WWDG() macros 00063 00064 ##### How to use this driver ##### 00065 ============================================================================== 00066 [..] 00067 (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE(). 00068 00069 (+) Set the WWDG prescaler, refresh window, counter value and Early Wakeup 00070 Interrupt mode using using HAL_WWDG_Init() function. 00071 This enables WWDG peripheral and the downcounter starts downcounting 00072 from given counter value. 00073 Init function can be called again to modify all watchdog parameters, 00074 however if EWI mode has been set once, it can't be clear until next 00075 reset. 00076 00077 (+) The application program must refresh the WWDG counter at regular 00078 intervals during normal operation to prevent an MCU reset using 00079 HAL_WWDG_Refresh() function. This operation must occur only when 00080 the counter is lower than the window value already programmed. 00081 00082 (+) if Early Wakeup Interrupt mode is enable an interrupt is generated when 00083 the counter reaches 0x40. User can add his own code in weak function 00084 HAL_WWDG_EarlyWakeupCallback(). 00085 00086 *** WWDG HAL driver macros list *** 00087 ================================== 00088 [..] 00089 Below the list of most used macros in WWDG HAL driver. 00090 00091 (+) __HAL_WWDG_GET_IT_SOURCE: Check the selected WWDG's interrupt source. 00092 (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status. 00093 (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags. 00094 00095 @endverbatim 00096 ****************************************************************************** 00097 * @attention 00098 * 00099 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00100 * 00101 * Redistribution and use in source and binary forms, with or without modification, 00102 * are permitted provided that the following conditions are met: 00103 * 1. Redistributions of source code must retain the above copyright notice, 00104 * this list of conditions and the following disclaimer. 00105 * 2. Redistributions in binary form must reproduce the above copyright notice, 00106 * this list of conditions and the following disclaimer in the documentation 00107 * and/or other materials provided with the distribution. 00108 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00109 * may be used to endorse or promote products derived from this software 00110 * without specific prior written permission. 00111 * 00112 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00113 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00114 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00115 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00116 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00117 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00118 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00119 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00120 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00121 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00122 * 00123 ****************************************************************************** 00124 */ 00125 00126 /* Includes ------------------------------------------------------------------*/ 00127 #include "stm32l4xx_hal.h" 00128 00129 /** @addtogroup STM32L4xx_HAL_Driver 00130 * @{ 00131 */ 00132 00133 #ifdef HAL_WWDG_MODULE_ENABLED 00134 /** @defgroup WWDG WWDG 00135 * @brief WWDG HAL module driver. 00136 * @{ 00137 */ 00138 00139 /* Private typedef -----------------------------------------------------------*/ 00140 /* Private define ------------------------------------------------------------*/ 00141 /* Private macro -------------------------------------------------------------*/ 00142 /* Private variables ---------------------------------------------------------*/ 00143 /* Private function prototypes -----------------------------------------------*/ 00144 /* Exported functions --------------------------------------------------------*/ 00145 00146 /** @defgroup WWDG_Exported_Functions WWDG Exported Functions 00147 * @{ 00148 */ 00149 00150 /** @defgroup WWDG_Exported_Functions_Group1 Initialization and Configuration functions 00151 * @brief Initialization and Configuration functions. 00152 * 00153 @verbatim 00154 ============================================================================== 00155 ##### Initialization and Configuration functions ##### 00156 ============================================================================== 00157 [..] 00158 This section provides functions allowing to: 00159 (+) Initialize and start the WWDG according to the specified parameters 00160 in the WWDG_InitTypeDef of associated handle. 00161 (+) Initialize the WWDG MSP. 00162 00163 @endverbatim 00164 * @{ 00165 */ 00166 00167 /** 00168 * @brief Initialize the WWDG according to the specified. 00169 * parameters in the WWDG_InitTypeDef of associated handle. 00170 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains 00171 * the configuration information for the specified WWDG module. 00172 * @retval HAL status 00173 */ 00174 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg) 00175 { 00176 /* Check the WWDG handle allocation */ 00177 if(hwwdg == NULL) 00178 { 00179 return HAL_ERROR; 00180 } 00181 00182 /* Check the parameters */ 00183 assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance)); 00184 assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler)); 00185 assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window)); 00186 assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter)); 00187 assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode)); 00188 00189 /* Init the low level hardware */ 00190 HAL_WWDG_MspInit(hwwdg); 00191 00192 /* Set WWDG Counter */ 00193 WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter)); 00194 00195 /* Set WWDG Prescaler and Window */ 00196 WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window)); 00197 00198 /* Return function status */ 00199 return HAL_OK; 00200 } 00201 00202 00203 /** 00204 * @brief Initialize the WWDG MSP. 00205 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains 00206 * the configuration information for the specified WWDG module. 00207 * @note When rewriting this function in user file, mechanism may be added 00208 * to avoid multiple initialize when HAL_WWDG_Init function is called 00209 * again to change parameters. 00210 * @retval None 00211 */ 00212 __weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg) 00213 { 00214 /* Prevent unused argument(s) compilation warning */ 00215 UNUSED(hwwdg); 00216 00217 /* NOTE: This function should not be modified, when the callback is needed, 00218 the HAL_WWDG_MspInit could be implemented in the user file 00219 */ 00220 } 00221 00222 /** 00223 * @} 00224 */ 00225 00226 /** @defgroup WWDG_Exported_Functions_Group2 IO operation functions 00227 * @brief IO operation functions 00228 * 00229 @verbatim 00230 ============================================================================== 00231 ##### IO operation functions ##### 00232 ============================================================================== 00233 [..] 00234 This section provides functions allowing to: 00235 (+) Refresh the WWDG. 00236 (+) Handle WWDG interrupt request and associated function callback. 00237 00238 @endverbatim 00239 * @{ 00240 */ 00241 00242 /** 00243 * @brief Refresh the WWDG. 00244 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains 00245 * the configuration information for the specified WWDG module. 00246 * @retval HAL status 00247 */ 00248 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg) 00249 { 00250 /* Write to WWDG CR the WWDG Counter value to refresh with */ 00251 WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter)); 00252 00253 /* Return function status */ 00254 return HAL_OK; 00255 } 00256 00257 /** 00258 * @brief Handle WWDG interrupt request. 00259 * @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations 00260 * or data logging must be performed before the actual reset is generated. 00261 * The EWI interrupt is enabled by calling HAL_WWDG_Init function with 00262 * EWIMode set to WWDG_EWI_ENABLE. 00263 * When the downcounter reaches the value 0x40, and EWI interrupt is 00264 * generated and the corresponding Interrupt Service Routine (ISR) can 00265 * be used to trigger specific actions (such as communications or data 00266 * logging), before resetting the device. 00267 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains 00268 * the configuration information for the specified WWDG module. 00269 * @retval None 00270 */ 00271 void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg) 00272 { 00273 /* Check if Early Wakeup Interrupt is enable */ 00274 if(__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET) 00275 { 00276 /* Check if WWDG Early Wakeup Interrupt occurred */ 00277 if(__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET) 00278 { 00279 /* Clear the WWDG Early Wakeup flag */ 00280 __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF); 00281 00282 /* Early Wakeup callback */ 00283 HAL_WWDG_EarlyWakeupCallback(hwwdg); 00284 } 00285 } 00286 } 00287 00288 00289 /** 00290 * @brief WWDG Early Wakeup callback. 00291 * @param hwwdg pointer to a WWDG_HandleTypeDef structure that contains 00292 * the configuration information for the specified WWDG module. 00293 * @retval None 00294 */ 00295 __weak void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef* hwwdg) 00296 { 00297 /* Prevent unused argument(s) compilation warning */ 00298 UNUSED(hwwdg); 00299 00300 /* NOTE: This function should not be modified, when the callback is needed, 00301 the HAL_WWDG_EarlyWakeupCallback could be implemented in the user file 00302 */ 00303 } 00304 00305 /** 00306 * @} 00307 */ 00308 00309 /** 00310 * @} 00311 */ 00312 00313 #endif /* HAL_WWDG_MODULE_ENABLED */ 00314 /** 00315 * @} 00316 */ 00317 00318 /** 00319 * @} 00320 */ 00321 00322 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:38:50 by
