stm32l4xx_ll_wwdg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_wwdg.h
  4. * @author MCD Application Team
  5. * @brief Header file of WWDG LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_LL_WWDG_H
  37. #define __STM32L4xx_LL_WWDG_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx.h"
  43. /** @addtogroup STM32L4xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (WWDG)
  47. /** @defgroup WWDG_LL WWDG
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /* Private macros ------------------------------------------------------------*/
  54. /* Exported types ------------------------------------------------------------*/
  55. /* Exported constants --------------------------------------------------------*/
  56. /** @defgroup WWDG_LL_Exported_Constants WWDG Exported Constants
  57. * @{
  58. */
  59. /** @defgroup WWDG_LL_EC_IT IT Defines
  60. * @brief IT defines which can be used with LL_WWDG_ReadReg and LL_WWDG_WriteReg functions
  61. * @{
  62. */
  63. #define LL_WWDG_CFR_EWI WWDG_CFR_EWI
  64. /**
  65. * @}
  66. */
  67. /** @defgroup WWDG_LL_EC_PRESCALER PRESCALER
  68. * @{
  69. */
  70. #define LL_WWDG_PRESCALER_1 0x00000000U /*!< WWDG counter clock = (PCLK1/4096)/1 */
  71. #define LL_WWDG_PRESCALER_2 WWDG_CFR_WDGTB_0 /*!< WWDG counter clock = (PCLK1/4096)/2 */
  72. #define LL_WWDG_PRESCALER_4 WWDG_CFR_WDGTB_1 /*!< WWDG counter clock = (PCLK1/4096)/4 */
  73. #define LL_WWDG_PRESCALER_8 (WWDG_CFR_WDGTB_0 | WWDG_CFR_WDGTB_1) /*!< WWDG counter clock = (PCLK1/4096)/8 */
  74. /**
  75. * @}
  76. */
  77. /**
  78. * @}
  79. */
  80. /* Exported macro ------------------------------------------------------------*/
  81. /** @defgroup WWDG_LL_Exported_Macros WWDG Exported Macros
  82. * @{
  83. */
  84. /** @defgroup WWDG_LL_EM_WRITE_READ Common Write and read registers macros
  85. * @{
  86. */
  87. /**
  88. * @brief Write a value in WWDG register
  89. * @param __INSTANCE__ WWDG Instance
  90. * @param __REG__ Register to be written
  91. * @param __VALUE__ Value to be written in the register
  92. * @retval None
  93. */
  94. #define LL_WWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  95. /**
  96. * @brief Read a value in WWDG register
  97. * @param __INSTANCE__ WWDG Instance
  98. * @param __REG__ Register to be read
  99. * @retval Register value
  100. */
  101. #define LL_WWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  102. /**
  103. * @}
  104. */
  105. /**
  106. * @}
  107. */
  108. /* Exported functions --------------------------------------------------------*/
  109. /** @defgroup WWDG_LL_Exported_Functions WWDG Exported Functions
  110. * @{
  111. */
  112. /** @defgroup WWDG_LL_EF_Configuration Configuration
  113. * @{
  114. */
  115. /**
  116. * @brief Enable Window Watchdog. The watchdog is always disabled after a reset.
  117. * @note It is enabled by setting the WDGA bit in the WWDG_CR register,
  118. * then it cannot be disabled again except by a reset.
  119. * This bit is set by software and only cleared by hardware after a reset.
  120. * When WDGA = 1, the watchdog can generate a reset.
  121. * @rmtoll CR WDGA LL_WWDG_Enable
  122. * @param WWDGx WWDG Instance
  123. * @retval None
  124. */
  125. __STATIC_INLINE void LL_WWDG_Enable(WWDG_TypeDef *WWDGx)
  126. {
  127. SET_BIT(WWDGx->CR, WWDG_CR_WDGA);
  128. }
  129. /**
  130. * @brief Checks if Window Watchdog is enabled
  131. * @rmtoll CR WDGA LL_WWDG_IsEnabled
  132. * @param WWDGx WWDG Instance
  133. * @retval State of bit (1 or 0).
  134. */
  135. __STATIC_INLINE uint32_t LL_WWDG_IsEnabled(WWDG_TypeDef *WWDGx)
  136. {
  137. return (READ_BIT(WWDGx->CR, WWDG_CR_WDGA) == (WWDG_CR_WDGA));
  138. }
  139. /**
  140. * @brief Set the Watchdog counter value to provided value (7-bits T[6:0])
  141. * @note When writing to the WWDG_CR register, always write 1 in the MSB b6 to avoid generating an immediate reset
  142. * This counter is decremented every (4096 x 2expWDGTB) PCLK cycles
  143. * A reset is produced when it rolls over from 0x40 to 0x3F (bit T6 becomes cleared)
  144. * Setting the counter lower then 0x40 causes an immediate reset (if WWDG enabled)
  145. * @rmtoll CR T LL_WWDG_SetCounter
  146. * @param WWDGx WWDG Instance
  147. * @param Counter 0..0x7F (7 bit counter value)
  148. * @retval None
  149. */
  150. __STATIC_INLINE void LL_WWDG_SetCounter(WWDG_TypeDef *WWDGx, uint32_t Counter)
  151. {
  152. MODIFY_REG(WWDGx->CR, WWDG_CR_T, Counter);
  153. }
  154. /**
  155. * @brief Return current Watchdog Counter Value (7 bits counter value)
  156. * @rmtoll CR T LL_WWDG_GetCounter
  157. * @param WWDGx WWDG Instance
  158. * @retval 7 bit Watchdog Counter value
  159. */
  160. __STATIC_INLINE uint32_t LL_WWDG_GetCounter(WWDG_TypeDef *WWDGx)
  161. {
  162. return (uint32_t)(READ_BIT(WWDGx->CR, WWDG_CR_T));
  163. }
  164. /**
  165. * @brief Set the time base of the prescaler (WDGTB).
  166. * @note Prescaler is used to apply ratio on PCLK clock, so that Watchdog counter
  167. * is decremented every (4096 x 2expWDGTB) PCLK cycles
  168. * @rmtoll CFR WDGTB LL_WWDG_SetPrescaler
  169. * @param WWDGx WWDG Instance
  170. * @param Prescaler This parameter can be one of the following values:
  171. * @arg @ref LL_WWDG_PRESCALER_1
  172. * @arg @ref LL_WWDG_PRESCALER_2
  173. * @arg @ref LL_WWDG_PRESCALER_4
  174. * @arg @ref LL_WWDG_PRESCALER_8
  175. * @retval None
  176. */
  177. __STATIC_INLINE void LL_WWDG_SetPrescaler(WWDG_TypeDef *WWDGx, uint32_t Prescaler)
  178. {
  179. MODIFY_REG(WWDGx->CFR, WWDG_CFR_WDGTB, Prescaler);
  180. }
  181. /**
  182. * @brief Return current Watchdog Prescaler Value
  183. * @rmtoll CFR WDGTB LL_WWDG_GetPrescaler
  184. * @param WWDGx WWDG Instance
  185. * @retval Returned value can be one of the following values:
  186. * @arg @ref LL_WWDG_PRESCALER_1
  187. * @arg @ref LL_WWDG_PRESCALER_2
  188. * @arg @ref LL_WWDG_PRESCALER_4
  189. * @arg @ref LL_WWDG_PRESCALER_8
  190. */
  191. __STATIC_INLINE uint32_t LL_WWDG_GetPrescaler(WWDG_TypeDef *WWDGx)
  192. {
  193. return (uint32_t)(READ_BIT(WWDGx->CFR, WWDG_CFR_WDGTB));
  194. }
  195. /**
  196. * @brief Set the Watchdog Window value to be compared to the downcounter (7-bits W[6:0]).
  197. * @note This window value defines when write in the WWDG_CR register
  198. * to program Watchdog counter is allowed.
  199. * Watchdog counter value update must occur only when the counter value
  200. * is lower than the Watchdog window register value.
  201. * Otherwise, a MCU reset is generated if the 7-bit Watchdog counter value
  202. * (in the control register) is refreshed before the downcounter has reached
  203. * the watchdog window register value.
  204. * Physically is possible to set the Window lower then 0x40 but it is not recommended.
  205. * To generate an immediate reset, it is possible to set the Counter lower than 0x40.
  206. * @rmtoll CFR W LL_WWDG_SetWindow
  207. * @param WWDGx WWDG Instance
  208. * @param Window 0x00..0x7F (7 bit Window value)
  209. * @retval None
  210. */
  211. __STATIC_INLINE void LL_WWDG_SetWindow(WWDG_TypeDef *WWDGx, uint32_t Window)
  212. {
  213. MODIFY_REG(WWDGx->CFR, WWDG_CFR_W, Window);
  214. }
  215. /**
  216. * @brief Return current Watchdog Window Value (7 bits value)
  217. * @rmtoll CFR W LL_WWDG_GetWindow
  218. * @param WWDGx WWDG Instance
  219. * @retval 7 bit Watchdog Window value
  220. */
  221. __STATIC_INLINE uint32_t LL_WWDG_GetWindow(WWDG_TypeDef *WWDGx)
  222. {
  223. return (uint32_t)(READ_BIT(WWDGx->CFR, WWDG_CFR_W));
  224. }
  225. /**
  226. * @}
  227. */
  228. /** @defgroup WWDG_LL_EF_FLAG_Management FLAG_Management
  229. * @{
  230. */
  231. /**
  232. * @brief Indicates if the WWDG Early Wakeup Interrupt Flag is set or not.
  233. * @note This bit is set by hardware when the counter has reached the value 0x40.
  234. * It must be cleared by software by writing 0.
  235. * A write of 1 has no effect. This bit is also set if the interrupt is not enabled.
  236. * @rmtoll SR EWIF LL_WWDG_IsActiveFlag_EWKUP
  237. * @param WWDGx WWDG Instance
  238. * @retval State of bit (1 or 0).
  239. */
  240. __STATIC_INLINE uint32_t LL_WWDG_IsActiveFlag_EWKUP(WWDG_TypeDef *WWDGx)
  241. {
  242. return (READ_BIT(WWDGx->SR, WWDG_SR_EWIF) == (WWDG_SR_EWIF));
  243. }
  244. /**
  245. * @brief Clear WWDG Early Wakeup Interrupt Flag (EWIF)
  246. * @rmtoll SR EWIF LL_WWDG_ClearFlag_EWKUP
  247. * @param WWDGx WWDG Instance
  248. * @retval None
  249. */
  250. __STATIC_INLINE void LL_WWDG_ClearFlag_EWKUP(WWDG_TypeDef *WWDGx)
  251. {
  252. WRITE_REG(WWDGx->SR, ~WWDG_SR_EWIF);
  253. }
  254. /**
  255. * @}
  256. */
  257. /** @defgroup WWDG_LL_EF_IT_Management IT_Management
  258. * @{
  259. */
  260. /**
  261. * @brief Enable the Early Wakeup Interrupt.
  262. * @note When set, an interrupt occurs whenever the counter reaches value 0x40.
  263. * This interrupt is only cleared by hardware after a reset
  264. * @rmtoll CFR EWI LL_WWDG_EnableIT_EWKUP
  265. * @param WWDGx WWDG Instance
  266. * @retval None
  267. */
  268. __STATIC_INLINE void LL_WWDG_EnableIT_EWKUP(WWDG_TypeDef *WWDGx)
  269. {
  270. SET_BIT(WWDGx->CFR, WWDG_CFR_EWI);
  271. }
  272. /**
  273. * @brief Check if Early Wakeup Interrupt is enabled
  274. * @rmtoll CFR EWI LL_WWDG_IsEnabledIT_EWKUP
  275. * @param WWDGx WWDG Instance
  276. * @retval State of bit (1 or 0).
  277. */
  278. __STATIC_INLINE uint32_t LL_WWDG_IsEnabledIT_EWKUP(WWDG_TypeDef *WWDGx)
  279. {
  280. return (READ_BIT(WWDGx->CFR, WWDG_CFR_EWI) == (WWDG_CFR_EWI));
  281. }
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. /**
  289. * @}
  290. */
  291. #endif /* WWDG */
  292. /**
  293. * @}
  294. */
  295. #ifdef __cplusplus
  296. }
  297. #endif
  298. #endif /* __STM32L4xx_LL_WWDG_H */
  299. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/