STM32H735xx HAL User Manual
stm32h7xx_ll_wwdg.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_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 STM32H7xx_LL_WWDG_H
00021 #define STM32H7xx_LL_WWDG_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm32h7xx.h"
00029 
00030 /** @addtogroup STM32H7xx_LL_Driver
00031   * @{
00032   */
00033 
00034 #if defined (WWDG1) || defined (WWDG2)
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 #define LL_WWDG_PRESCALER_16                WWDG_CFR_WDGTB_2                                          /*!< WWDG counter clock = (PCLK1/4096)/16 */
00067 #define LL_WWDG_PRESCALER_32                (WWDG_CFR_WDGTB_2 | WWDG_CFR_WDGTB_0)                     /*!< WWDG counter clock = (PCLK1/4096)/32 */
00068 #define LL_WWDG_PRESCALER_64                (WWDG_CFR_WDGTB_2 | WWDG_CFR_WDGTB_1)                     /*!< WWDG counter clock = (PCLK1/4096)/64 */
00069 #define LL_WWDG_PRESCALER_128               (WWDG_CFR_WDGTB_2 | WWDG_CFR_WDGTB_1 | WWDG_CFR_WDGTB_0)  /*!< WWDG counter clock = (PCLK1/4096)/128 */
00070 /**
00071   * @}
00072   */
00073 
00074 /**
00075   * @}
00076   */
00077 
00078 /* Exported macro ------------------------------------------------------------*/
00079 /** @defgroup WWDG_LL_Exported_Macros WWDG Exported Macros
00080   * @{
00081   */
00082 /** @defgroup WWDG_LL_EM_WRITE_READ Common Write and read registers macros
00083   * @{
00084   */
00085 /**
00086   * @brief  Write a value in WWDG register
00087   * @param  __INSTANCE__ WWDG Instance
00088   * @param  __REG__ Register to be written
00089   * @param  __VALUE__ Value to be written in the register
00090   * @retval None
00091   */
00092 #define LL_WWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
00093 
00094 /**
00095   * @brief  Read a value in WWDG register
00096   * @param  __INSTANCE__ WWDG Instance
00097   * @param  __REG__ Register to be read
00098   * @retval Register value
00099   */
00100 #define LL_WWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00101 /**
00102   * @}
00103   */
00104 
00105 /**
00106   * @}
00107   */
00108 
00109 /* Exported functions --------------------------------------------------------*/
00110 /** @defgroup WWDG_LL_Exported_Functions WWDG Exported Functions
00111   * @{
00112   */
00113 
00114 /** @defgroup WWDG_LL_EF_Configuration Configuration
00115   * @{
00116   */
00117 /**
00118   * @brief  Enable Window Watchdog. The watchdog is always disabled after a reset.
00119   * @note   It is enabled by setting the WDGA bit in the WWDG_CR register,
00120   *         then it cannot be disabled again except by a reset.
00121   *         This bit is set by software and only cleared by hardware after a reset.
00122   *         When WDGA = 1, the watchdog can generate a reset.
00123   * @rmtoll CR           WDGA          LL_WWDG_Enable
00124   * @param  WWDGx WWDG Instance
00125   * @retval None
00126   */
00127 __STATIC_INLINE void LL_WWDG_Enable(WWDG_TypeDef *WWDGx)
00128 {
00129   SET_BIT(WWDGx->CR, WWDG_CR_WDGA);
00130 }
00131 
00132 /**
00133   * @brief  Checks if Window Watchdog is enabled
00134   * @rmtoll CR           WDGA          LL_WWDG_IsEnabled
00135   * @param  WWDGx WWDG Instance
00136   * @retval State of bit (1 or 0).
00137   */
00138 __STATIC_INLINE uint32_t LL_WWDG_IsEnabled(WWDG_TypeDef *WWDGx)
00139 {
00140   return ((READ_BIT(WWDGx->CR, WWDG_CR_WDGA) == (WWDG_CR_WDGA)) ? 1UL : 0UL);
00141 }
00142 
00143 /**
00144   * @brief  Set the Watchdog counter value to provided value (7-bits T[6:0])
00145   * @note   When writing to the WWDG_CR register, always write 1 in the MSB b6 to avoid generating an immediate reset
00146   *         This counter is decremented every (4096 x 2expWDGTB) PCLK cycles
00147   *         A reset is produced when it rolls over from 0x40 to 0x3F (bit T6 becomes cleared)
00148   *         Setting the counter lower then 0x40 causes an immediate reset (if WWDG enabled)
00149   * @rmtoll CR           T             LL_WWDG_SetCounter
00150   * @param  WWDGx WWDG Instance
00151   * @param  Counter 0..0x7F (7 bit counter value)
00152   * @retval None
00153   */
00154 __STATIC_INLINE void LL_WWDG_SetCounter(WWDG_TypeDef *WWDGx, uint32_t Counter)
00155 {
00156   MODIFY_REG(WWDGx->CR, WWDG_CR_T, Counter);
00157 }
00158 
00159 /**
00160   * @brief  Return current Watchdog Counter Value (7 bits counter value)
00161   * @rmtoll CR           T             LL_WWDG_GetCounter
00162   * @param  WWDGx WWDG Instance
00163   * @retval 7 bit Watchdog Counter value
00164   */
00165 __STATIC_INLINE uint32_t LL_WWDG_GetCounter(WWDG_TypeDef *WWDGx)
00166 {
00167   return (READ_BIT(WWDGx->CR, WWDG_CR_T));
00168 }
00169 
00170 /**
00171   * @brief  Set the time base of the prescaler (WDGTB).
00172   * @note   Prescaler is used to apply ratio on PCLK clock, so that Watchdog counter
00173   *         is decremented every (4096 x 2expWDGTB) PCLK cycles
00174   * @rmtoll CFR          WDGTB         LL_WWDG_SetPrescaler
00175   * @param  WWDGx WWDG Instance
00176   * @param  Prescaler This parameter can be one of the following values:
00177   *         @arg @ref LL_WWDG_PRESCALER_1
00178   *         @arg @ref LL_WWDG_PRESCALER_2
00179   *         @arg @ref LL_WWDG_PRESCALER_4
00180   *         @arg @ref LL_WWDG_PRESCALER_8
00181   *         @arg @ref LL_WWDG_PRESCALER_16
00182   *         @arg @ref LL_WWDG_PRESCALER_32
00183   *         @arg @ref LL_WWDG_PRESCALER_64
00184   *         @arg @ref LL_WWDG_PRESCALER_128
00185   * @retval None
00186   */
00187 __STATIC_INLINE void LL_WWDG_SetPrescaler(WWDG_TypeDef *WWDGx, uint32_t Prescaler)
00188 {
00189   MODIFY_REG(WWDGx->CFR, WWDG_CFR_WDGTB, Prescaler);
00190 }
00191 
00192 /**
00193   * @brief  Return current Watchdog Prescaler Value
00194   * @rmtoll CFR          WDGTB         LL_WWDG_GetPrescaler
00195   * @param  WWDGx WWDG Instance
00196   * @retval Returned value can be one of the following values:
00197   *         @arg @ref LL_WWDG_PRESCALER_1
00198   *         @arg @ref LL_WWDG_PRESCALER_2
00199   *         @arg @ref LL_WWDG_PRESCALER_4
00200   *         @arg @ref LL_WWDG_PRESCALER_8
00201   *         @arg @ref LL_WWDG_PRESCALER_16
00202   *         @arg @ref LL_WWDG_PRESCALER_32
00203   *         @arg @ref LL_WWDG_PRESCALER_64
00204   *         @arg @ref LL_WWDG_PRESCALER_128
00205   */
00206 __STATIC_INLINE uint32_t LL_WWDG_GetPrescaler(WWDG_TypeDef *WWDGx)
00207 {
00208   return (READ_BIT(WWDGx->CFR, WWDG_CFR_WDGTB));
00209 }
00210 
00211 /**
00212   * @brief  Set the Watchdog Window value to be compared to the downcounter (7-bits W[6:0]).
00213   * @note   This window value defines when write in the WWDG_CR register
00214   *         to program Watchdog counter is allowed.
00215   *         Watchdog counter value update must occur only when the counter value
00216   *         is lower than the Watchdog window register value.
00217   *         Otherwise, a MCU reset is generated if the 7-bit Watchdog counter value
00218   *         (in the control register) is refreshed before the downcounter has reached
00219   *         the watchdog window register value.
00220   *         Physically is possible to set the Window lower then 0x40 but it is not recommended.
00221   *         To generate an immediate reset, it is possible to set the Counter lower than 0x40.
00222   * @rmtoll CFR          W             LL_WWDG_SetWindow
00223   * @param  WWDGx WWDG Instance
00224   * @param  Window 0x00..0x7F (7 bit Window value)
00225   * @retval None
00226   */
00227 __STATIC_INLINE void LL_WWDG_SetWindow(WWDG_TypeDef *WWDGx, uint32_t Window)
00228 {
00229   MODIFY_REG(WWDGx->CFR, WWDG_CFR_W, Window);
00230 }
00231 
00232 /**
00233   * @brief  Return current Watchdog Window Value (7 bits value)
00234   * @rmtoll CFR          W             LL_WWDG_GetWindow
00235   * @param  WWDGx WWDG Instance
00236   * @retval 7 bit Watchdog Window value
00237   */
00238 __STATIC_INLINE uint32_t LL_WWDG_GetWindow(WWDG_TypeDef *WWDGx)
00239 {
00240   return (READ_BIT(WWDGx->CFR, WWDG_CFR_W));
00241 }
00242 
00243 /**
00244   * @}
00245   */
00246 
00247 /** @defgroup WWDG_LL_EF_FLAG_Management FLAG_Management
00248   * @{
00249   */
00250 /**
00251   * @brief  Indicates if the WWDG Early Wakeup Interrupt Flag is set or not.
00252   * @note   This bit is set by hardware when the counter has reached the value 0x40.
00253   *         It must be cleared by software by writing 0.
00254   *         A write of 1 has no effect. This bit is also set if the interrupt is not enabled.
00255   * @rmtoll SR           EWIF          LL_WWDG_IsActiveFlag_EWKUP
00256   * @param  WWDGx WWDG Instance
00257   * @retval State of bit (1 or 0).
00258   */
00259 __STATIC_INLINE uint32_t LL_WWDG_IsActiveFlag_EWKUP(WWDG_TypeDef *WWDGx)
00260 {
00261   return ((READ_BIT(WWDGx->SR, WWDG_SR_EWIF) == (WWDG_SR_EWIF)) ? 1UL : 0UL);
00262 }
00263 
00264 /**
00265   * @brief  Clear WWDG Early Wakeup Interrupt Flag (EWIF)
00266   * @rmtoll SR           EWIF          LL_WWDG_ClearFlag_EWKUP
00267   * @param  WWDGx WWDG Instance
00268   * @retval None
00269   */
00270 __STATIC_INLINE void LL_WWDG_ClearFlag_EWKUP(WWDG_TypeDef *WWDGx)
00271 {
00272   WRITE_REG(WWDGx->SR, ~WWDG_SR_EWIF);
00273 }
00274 
00275 /**
00276   * @}
00277   */
00278 
00279 /** @defgroup WWDG_LL_EF_IT_Management IT_Management
00280   * @{
00281   */
00282 /**
00283   * @brief  Enable the Early Wakeup Interrupt.
00284   * @note   When set, an interrupt occurs whenever the counter reaches value 0x40.
00285   *         This interrupt is only cleared by hardware after a reset
00286   * @rmtoll CFR          EWI           LL_WWDG_EnableIT_EWKUP
00287   * @param  WWDGx WWDG Instance
00288   * @retval None
00289   */
00290 __STATIC_INLINE void LL_WWDG_EnableIT_EWKUP(WWDG_TypeDef *WWDGx)
00291 {
00292   SET_BIT(WWDGx->CFR, WWDG_CFR_EWI);
00293 }
00294 
00295 /**
00296   * @brief  Check if Early Wakeup Interrupt is enabled
00297   * @rmtoll CFR          EWI           LL_WWDG_IsEnabledIT_EWKUP
00298   * @param  WWDGx WWDG Instance
00299   * @retval State of bit (1 or 0).
00300   */
00301 __STATIC_INLINE uint32_t LL_WWDG_IsEnabledIT_EWKUP(WWDG_TypeDef *WWDGx)
00302 {
00303   return ((READ_BIT(WWDGx->CFR, WWDG_CFR_EWI) == (WWDG_CFR_EWI)) ? 1UL : 0UL);
00304 }
00305 
00306 /**
00307   * @}
00308   */
00309 
00310 /**
00311   * @}
00312   */
00313 
00314 /**
00315   * @}
00316   */
00317 
00318 #endif /* WWDG1 || WWDG2 */
00319 
00320 /**
00321   * @}
00322   */
00323 
00324 #ifdef __cplusplus
00325 }
00326 #endif
00327 
00328 #endif /* STM32H7xx_LL_WWDG_H */