2 ******************************************************************************
3 * @file stm32f1xx_ll_iwdg.h
4 * @author MCD Application Team
7 * @brief Header file of IWDG LL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F1xx_LL_IWDG_H
40 #define __STM32F1xx_LL_IWDG_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f1xx.h"
49 /** @addtogroup STM32F1xx_LL_Driver
55 /** @defgroup IWDG_LL IWDG
59 /* Private types -------------------------------------------------------------*/
60 /* Private variables ---------------------------------------------------------*/
62 /* Private constants ---------------------------------------------------------*/
63 /** @defgroup IWDG_LL_Private_Constants IWDG Private Constants
67 #define LL_IWDG_KEY_RELOAD 0x0000AAAAU /*!< IWDG Reload Counter Enable */
68 #define LL_IWDG_KEY_ENABLE 0x0000CCCCU /*!< IWDG Peripheral Enable */
69 #define LL_IWDG_KEY_WR_ACCESS_ENABLE 0x00005555U /*!< IWDG KR Write Access Enable */
70 #define LL_IWDG_KEY_WR_ACCESS_DISABLE 0x00000000U /*!< IWDG KR Write Access Disable */
76 /* Private macros ------------------------------------------------------------*/
78 /* Exported types ------------------------------------------------------------*/
79 /* Exported constants --------------------------------------------------------*/
80 /** @defgroup IWDG_LL_Exported_Constants IWDG Exported Constants
84 /** @defgroup IWDG_LL_EC_GET_FLAG Get Flags Defines
85 * @brief Flags defines which can be used with LL_IWDG_ReadReg function
88 #define LL_IWDG_SR_PVU IWDG_SR_PVU /*!< Watchdog prescaler value update */
89 #define LL_IWDG_SR_RVU IWDG_SR_RVU /*!< Watchdog counter reload value update */
95 /** @defgroup IWDG_LL_EC_PRESCALER Prescaler Divider
98 #define LL_IWDG_PRESCALER_4 0x00000000U /*!< Divider by 4 */
99 #define LL_IWDG_PRESCALER_8 (IWDG_PR_PR_0) /*!< Divider by 8 */
100 #define LL_IWDG_PRESCALER_16 (IWDG_PR_PR_1) /*!< Divider by 16 */
101 #define LL_IWDG_PRESCALER_32 (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< Divider by 32 */
102 #define LL_IWDG_PRESCALER_64 (IWDG_PR_PR_2) /*!< Divider by 64 */
103 #define LL_IWDG_PRESCALER_128 (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< Divider by 128 */
104 #define LL_IWDG_PRESCALER_256 (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< Divider by 256 */
113 /* Exported macro ------------------------------------------------------------*/
114 /** @defgroup IWDG_LL_Exported_Macros IWDG Exported Macros
118 /** @defgroup IWDG_LL_EM_WRITE_READ Common Write and read registers Macros
123 * @brief Write a value in IWDG register
124 * @param __INSTANCE__ IWDG Instance
125 * @param __REG__ Register to be written
126 * @param __VALUE__ Value to be written in the register
129 #define LL_IWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
132 * @brief Read a value in IWDG register
133 * @param __INSTANCE__ IWDG Instance
134 * @param __REG__ Register to be read
135 * @retval Register value
137 #define LL_IWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
147 /* Exported functions --------------------------------------------------------*/
148 /** @defgroup IWDG_LL_Exported_Functions IWDG Exported Functions
151 /** @defgroup IWDG_LL_EF_Configuration Configuration
156 * @brief Start the Independent Watchdog
157 * @note Except if the hardware watchdog option is selected
158 * @rmtoll KR KEY LL_IWDG_Enable
159 * @param IWDGx IWDG Instance
162 __STATIC_INLINE
void LL_IWDG_Enable(IWDG_TypeDef
*IWDGx
)
164 WRITE_REG(IWDG
->KR
, LL_IWDG_KEY_ENABLE
);
168 * @brief Reloads IWDG counter with value defined in the reload register
169 * @rmtoll KR KEY LL_IWDG_ReloadCounter
170 * @param IWDGx IWDG Instance
173 __STATIC_INLINE
void LL_IWDG_ReloadCounter(IWDG_TypeDef
*IWDGx
)
175 WRITE_REG(IWDG
->KR
, LL_IWDG_KEY_RELOAD
);
179 * @brief Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
180 * @rmtoll KR KEY LL_IWDG_EnableWriteAccess
181 * @param IWDGx IWDG Instance
184 __STATIC_INLINE
void LL_IWDG_EnableWriteAccess(IWDG_TypeDef
*IWDGx
)
186 WRITE_REG(IWDG
->KR
, LL_IWDG_KEY_WR_ACCESS_ENABLE
);
190 * @brief Disable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
191 * @rmtoll KR KEY LL_IWDG_DisableWriteAccess
192 * @param IWDGx IWDG Instance
195 __STATIC_INLINE
void LL_IWDG_DisableWriteAccess(IWDG_TypeDef
*IWDGx
)
197 WRITE_REG(IWDG
->KR
, LL_IWDG_KEY_WR_ACCESS_DISABLE
);
201 * @brief Select the prescaler of the IWDG
202 * @rmtoll PR PR LL_IWDG_SetPrescaler
203 * @param IWDGx IWDG Instance
204 * @param Prescaler This parameter can be one of the following values:
205 * @arg @ref LL_IWDG_PRESCALER_4
206 * @arg @ref LL_IWDG_PRESCALER_8
207 * @arg @ref LL_IWDG_PRESCALER_16
208 * @arg @ref LL_IWDG_PRESCALER_32
209 * @arg @ref LL_IWDG_PRESCALER_64
210 * @arg @ref LL_IWDG_PRESCALER_128
211 * @arg @ref LL_IWDG_PRESCALER_256
214 __STATIC_INLINE
void LL_IWDG_SetPrescaler(IWDG_TypeDef
*IWDGx
, uint32_t Prescaler
)
216 WRITE_REG(IWDGx
->PR
, IWDG_PR_PR
& Prescaler
);
220 * @brief Get the selected prescaler of the IWDG
221 * @rmtoll PR PR LL_IWDG_GetPrescaler
222 * @param IWDGx IWDG Instance
223 * @retval Returned value can be one of the following values:
224 * @arg @ref LL_IWDG_PRESCALER_4
225 * @arg @ref LL_IWDG_PRESCALER_8
226 * @arg @ref LL_IWDG_PRESCALER_16
227 * @arg @ref LL_IWDG_PRESCALER_32
228 * @arg @ref LL_IWDG_PRESCALER_64
229 * @arg @ref LL_IWDG_PRESCALER_128
230 * @arg @ref LL_IWDG_PRESCALER_256
232 __STATIC_INLINE
uint32_t LL_IWDG_GetPrescaler(IWDG_TypeDef
*IWDGx
)
234 return (uint32_t)(READ_REG(IWDGx
->PR
));
238 * @brief Specify the IWDG down-counter reload value
239 * @rmtoll RLR RL LL_IWDG_SetReloadCounter
240 * @param IWDGx IWDG Instance
241 * @param Counter Value between Min_Data=0 and Max_Data=0x0FFF
244 __STATIC_INLINE
void LL_IWDG_SetReloadCounter(IWDG_TypeDef
*IWDGx
, uint32_t Counter
)
246 WRITE_REG(IWDGx
->RLR
, IWDG_RLR_RL
& Counter
);
250 * @brief Get the specified IWDG down-counter reload value
251 * @rmtoll RLR RL LL_IWDG_GetReloadCounter
252 * @param IWDGx IWDG Instance
253 * @retval Value between Min_Data=0 and Max_Data=0x0FFF
255 __STATIC_INLINE
uint32_t LL_IWDG_GetReloadCounter(IWDG_TypeDef
*IWDGx
)
257 return (uint32_t)(READ_REG(IWDGx
->RLR
));
265 /** @defgroup IWDG_LL_EF_FLAG_Management FLAG_Management
270 * @brief Check if flag Prescaler Value Update is set or not
271 * @rmtoll SR PVU LL_IWDG_IsActiveFlag_PVU
272 * @param IWDGx IWDG Instance
273 * @retval State of bit (1 or 0).
275 __STATIC_INLINE
uint32_t LL_IWDG_IsActiveFlag_PVU(IWDG_TypeDef
*IWDGx
)
277 return (READ_BIT(IWDGx
->SR
, IWDG_SR_PVU
) == (IWDG_SR_PVU
));
281 * @brief Check if flag Reload Value Update is set or not
282 * @rmtoll SR RVU LL_IWDG_IsActiveFlag_RVU
283 * @param IWDGx IWDG Instance
284 * @retval State of bit (1 or 0).
286 __STATIC_INLINE
uint32_t LL_IWDG_IsActiveFlag_RVU(IWDG_TypeDef
*IWDGx
)
288 return (READ_BIT(IWDGx
->SR
, IWDG_SR_RVU
) == (IWDG_SR_RVU
));
293 * @brief Check if all flags Prescaler, Reload & Window Value Update are reset or not
294 * @rmtoll SR PVU LL_IWDG_IsReady\n
295 * SR RVU LL_IWDG_IsReady
296 * @param IWDGx IWDG Instance
297 * @retval State of bits (1 or 0).
299 __STATIC_INLINE
uint32_t LL_IWDG_IsReady(IWDG_TypeDef
*IWDGx
)
301 return (READ_BIT(IWDGx
->SR
, IWDG_SR_PVU
| IWDG_SR_RVU
) == 0U);
327 #endif /* __STM32F1xx_LL_IWDG_H */
329 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/