STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_wwdg.h 00004 * @author MCD Application Team 00005 * @brief Header file of WWDG LL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32L4xx_LL_WWDG_H 00021 #define STM32L4xx_LL_WWDG_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32l4xx.h" 00029 00030 /** @addtogroup STM32L4xx_LL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (WWDG) 00035 00036 /** @defgroup WWDG_LL WWDG 00037 * @{ 00038 */ 00039 00040 /* Private types -------------------------------------------------------------*/ 00041 /* Private variables ---------------------------------------------------------*/ 00042 /* Private constants ---------------------------------------------------------*/ 00043 /* Private macros ------------------------------------------------------------*/ 00044 /* Exported types ------------------------------------------------------------*/ 00045 /* Exported constants --------------------------------------------------------*/ 00046 /** @defgroup WWDG_LL_Exported_Constants WWDG Exported Constants 00047 * @{ 00048 */ 00049 00050 /** @defgroup WWDG_LL_EC_IT IT Defines 00051 * @brief IT defines which can be used with LL_WWDG_ReadReg and LL_WWDG_WriteReg functions 00052 * @{ 00053 */ 00054 #define LL_WWDG_CFR_EWI WWDG_CFR_EWI 00055 /** 00056 * @} 00057 */ 00058 00059 /** @defgroup WWDG_LL_EC_PRESCALER PRESCALER 00060 * @{ 00061 */ 00062 #define LL_WWDG_PRESCALER_1 0x00000000u /*!< WWDG counter clock = (PCLK1/4096)/1 */ 00063 #define LL_WWDG_PRESCALER_2 WWDG_CFR_WDGTB_0 /*!< WWDG counter clock = (PCLK1/4096)/2 */ 00064 #define LL_WWDG_PRESCALER_4 WWDG_CFR_WDGTB_1 /*!< WWDG counter clock = (PCLK1/4096)/4 */ 00065 #define LL_WWDG_PRESCALER_8 (WWDG_CFR_WDGTB_0 | WWDG_CFR_WDGTB_1) /*!< WWDG counter clock = (PCLK1/4096)/8 */ 00066 /** 00067 * @} 00068 */ 00069 00070 /** 00071 * @} 00072 */ 00073 00074 /* Exported macro ------------------------------------------------------------*/ 00075 /** @defgroup WWDG_LL_Exported_Macros WWDG Exported Macros 00076 * @{ 00077 */ 00078 /** @defgroup WWDG_LL_EM_WRITE_READ Common Write and read registers macros 00079 * @{ 00080 */ 00081 /** 00082 * @brief Write a value in WWDG register 00083 * @param __INSTANCE__ WWDG Instance 00084 * @param __REG__ Register to be written 00085 * @param __VALUE__ Value to be written in the register 00086 * @retval None 00087 */ 00088 #define LL_WWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__)) 00089 00090 /** 00091 * @brief Read a value in WWDG register 00092 * @param __INSTANCE__ WWDG Instance 00093 * @param __REG__ Register to be read 00094 * @retval Register value 00095 */ 00096 #define LL_WWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__) 00097 /** 00098 * @} 00099 */ 00100 00101 /** 00102 * @} 00103 */ 00104 00105 /* Exported functions --------------------------------------------------------*/ 00106 /** @defgroup WWDG_LL_Exported_Functions WWDG Exported Functions 00107 * @{ 00108 */ 00109 00110 /** @defgroup WWDG_LL_EF_Configuration Configuration 00111 * @{ 00112 */ 00113 /** 00114 * @brief Enable Window Watchdog. The watchdog is always disabled after a reset. 00115 * @note It is enabled by setting the WDGA bit in the WWDG_CR register, 00116 * then it cannot be disabled again except by a reset. 00117 * This bit is set by software and only cleared by hardware after a reset. 00118 * When WDGA = 1, the watchdog can generate a reset. 00119 * @rmtoll CR WDGA LL_WWDG_Enable 00120 * @param WWDGx WWDG Instance 00121 * @retval None 00122 */ 00123 __STATIC_INLINE void LL_WWDG_Enable(WWDG_TypeDef *WWDGx) 00124 { 00125 SET_BIT(WWDGx->CR, WWDG_CR_WDGA); 00126 } 00127 00128 /** 00129 * @brief Checks if Window Watchdog is enabled 00130 * @rmtoll CR WDGA LL_WWDG_IsEnabled 00131 * @param WWDGx WWDG Instance 00132 * @retval State of bit (1 or 0). 00133 */ 00134 __STATIC_INLINE uint32_t LL_WWDG_IsEnabled(WWDG_TypeDef *WWDGx) 00135 { 00136 return ((READ_BIT(WWDGx->CR, WWDG_CR_WDGA) == (WWDG_CR_WDGA)) ? 1UL : 0UL); 00137 } 00138 00139 /** 00140 * @brief Set the Watchdog counter value to provided value (7-bits T[6:0]) 00141 * @note When writing to the WWDG_CR register, always write 1 in the MSB b6 to avoid generating an immediate reset 00142 * This counter is decremented every (4096 x 2expWDGTB) PCLK cycles 00143 * A reset is produced when it rolls over from 0x40 to 0x3F (bit T6 becomes cleared) 00144 * Setting the counter lower then 0x40 causes an immediate reset (if WWDG enabled) 00145 * @rmtoll CR T LL_WWDG_SetCounter 00146 * @param WWDGx WWDG Instance 00147 * @param Counter 0..0x7F (7 bit counter value) 00148 * @retval None 00149 */ 00150 __STATIC_INLINE void LL_WWDG_SetCounter(WWDG_TypeDef *WWDGx, uint32_t Counter) 00151 { 00152 MODIFY_REG(WWDGx->CR, WWDG_CR_T, Counter); 00153 } 00154 00155 /** 00156 * @brief Return current Watchdog Counter Value (7 bits counter value) 00157 * @rmtoll CR T LL_WWDG_GetCounter 00158 * @param WWDGx WWDG Instance 00159 * @retval 7 bit Watchdog Counter value 00160 */ 00161 __STATIC_INLINE uint32_t LL_WWDG_GetCounter(WWDG_TypeDef *WWDGx) 00162 { 00163 return (READ_BIT(WWDGx->CR, WWDG_CR_T)); 00164 } 00165 00166 /** 00167 * @brief Set the time base of the prescaler (WDGTB). 00168 * @note Prescaler is used to apply ratio on PCLK clock, so that Watchdog counter 00169 * is decremented every (4096 x 2expWDGTB) PCLK cycles 00170 * @rmtoll CFR WDGTB LL_WWDG_SetPrescaler 00171 * @param WWDGx WWDG Instance 00172 * @param Prescaler This parameter can be one of the following values: 00173 * @arg @ref LL_WWDG_PRESCALER_1 00174 * @arg @ref LL_WWDG_PRESCALER_2 00175 * @arg @ref LL_WWDG_PRESCALER_4 00176 * @arg @ref LL_WWDG_PRESCALER_8 00177 * @retval None 00178 */ 00179 __STATIC_INLINE void LL_WWDG_SetPrescaler(WWDG_TypeDef *WWDGx, uint32_t Prescaler) 00180 { 00181 MODIFY_REG(WWDGx->CFR, WWDG_CFR_WDGTB, Prescaler); 00182 } 00183 00184 /** 00185 * @brief Return current Watchdog Prescaler Value 00186 * @rmtoll CFR WDGTB LL_WWDG_GetPrescaler 00187 * @param WWDGx WWDG Instance 00188 * @retval Returned value can be one of the following values: 00189 * @arg @ref LL_WWDG_PRESCALER_1 00190 * @arg @ref LL_WWDG_PRESCALER_2 00191 * @arg @ref LL_WWDG_PRESCALER_4 00192 * @arg @ref LL_WWDG_PRESCALER_8 00193 */ 00194 __STATIC_INLINE uint32_t LL_WWDG_GetPrescaler(WWDG_TypeDef *WWDGx) 00195 { 00196 return (READ_BIT(WWDGx->CFR, WWDG_CFR_WDGTB)); 00197 } 00198 00199 /** 00200 * @brief Set the Watchdog Window value to be compared to the downcounter (7-bits W[6:0]). 00201 * @note This window value defines when write in the WWDG_CR register 00202 * to program Watchdog counter is allowed. 00203 * Watchdog counter value update must occur only when the counter value 00204 * is lower than the Watchdog window register value. 00205 * Otherwise, a MCU reset is generated if the 7-bit Watchdog counter value 00206 * (in the control register) is refreshed before the downcounter has reached 00207 * the watchdog window register value. 00208 * Physically is possible to set the Window lower then 0x40 but it is not recommended. 00209 * To generate an immediate reset, it is possible to set the Counter lower than 0x40. 00210 * @rmtoll CFR W LL_WWDG_SetWindow 00211 * @param WWDGx WWDG Instance 00212 * @param Window 0x00..0x7F (7 bit Window value) 00213 * @retval None 00214 */ 00215 __STATIC_INLINE void LL_WWDG_SetWindow(WWDG_TypeDef *WWDGx, uint32_t Window) 00216 { 00217 MODIFY_REG(WWDGx->CFR, WWDG_CFR_W, Window); 00218 } 00219 00220 /** 00221 * @brief Return current Watchdog Window Value (7 bits value) 00222 * @rmtoll CFR W LL_WWDG_GetWindow 00223 * @param WWDGx WWDG Instance 00224 * @retval 7 bit Watchdog Window value 00225 */ 00226 __STATIC_INLINE uint32_t LL_WWDG_GetWindow(WWDG_TypeDef *WWDGx) 00227 { 00228 return (READ_BIT(WWDGx->CFR, WWDG_CFR_W)); 00229 } 00230 00231 /** 00232 * @} 00233 */ 00234 00235 /** @defgroup WWDG_LL_EF_FLAG_Management FLAG_Management 00236 * @{ 00237 */ 00238 /** 00239 * @brief Indicates if the WWDG Early Wakeup Interrupt Flag is set or not. 00240 * @note This bit is set by hardware when the counter has reached the value 0x40. 00241 * It must be cleared by software by writing 0. 00242 * A write of 1 has no effect. This bit is also set if the interrupt is not enabled. 00243 * @rmtoll SR EWIF LL_WWDG_IsActiveFlag_EWKUP 00244 * @param WWDGx WWDG Instance 00245 * @retval State of bit (1 or 0). 00246 */ 00247 __STATIC_INLINE uint32_t LL_WWDG_IsActiveFlag_EWKUP(WWDG_TypeDef *WWDGx) 00248 { 00249 return ((READ_BIT(WWDGx->SR, WWDG_SR_EWIF) == (WWDG_SR_EWIF)) ? 1UL : 0UL); 00250 } 00251 00252 /** 00253 * @brief Clear WWDG Early Wakeup Interrupt Flag (EWIF) 00254 * @rmtoll SR EWIF LL_WWDG_ClearFlag_EWKUP 00255 * @param WWDGx WWDG Instance 00256 * @retval None 00257 */ 00258 __STATIC_INLINE void LL_WWDG_ClearFlag_EWKUP(WWDG_TypeDef *WWDGx) 00259 { 00260 WRITE_REG(WWDGx->SR, ~WWDG_SR_EWIF); 00261 } 00262 00263 /** 00264 * @} 00265 */ 00266 00267 /** @defgroup WWDG_LL_EF_IT_Management IT_Management 00268 * @{ 00269 */ 00270 /** 00271 * @brief Enable the Early Wakeup Interrupt. 00272 * @note When set, an interrupt occurs whenever the counter reaches value 0x40. 00273 * This interrupt is only cleared by hardware after a reset 00274 * @rmtoll CFR EWI LL_WWDG_EnableIT_EWKUP 00275 * @param WWDGx WWDG Instance 00276 * @retval None 00277 */ 00278 __STATIC_INLINE void LL_WWDG_EnableIT_EWKUP(WWDG_TypeDef *WWDGx) 00279 { 00280 SET_BIT(WWDGx->CFR, WWDG_CFR_EWI); 00281 } 00282 00283 /** 00284 * @brief Check if Early Wakeup Interrupt is enabled 00285 * @rmtoll CFR EWI LL_WWDG_IsEnabledIT_EWKUP 00286 * @param WWDGx WWDG Instance 00287 * @retval State of bit (1 or 0). 00288 */ 00289 __STATIC_INLINE uint32_t LL_WWDG_IsEnabledIT_EWKUP(WWDG_TypeDef *WWDGx) 00290 { 00291 return ((READ_BIT(WWDGx->CFR, WWDG_CFR_EWI) == (WWDG_CFR_EWI)) ? 1UL : 0UL); 00292 } 00293 00294 /** 00295 * @} 00296 */ 00297 00298 /** 00299 * @} 00300 */ 00301 00302 /** 00303 * @} 00304 */ 00305 00306 #endif /* WWDG */ 00307 00308 /** 00309 * @} 00310 */ 00311 00312 #ifdef __cplusplus 00313 } 00314 #endif 00315 00316 #endif /* STM32L4xx_LL_WWDG_H */