1 /** 2 ****************************************************************************** 3 * @file stm32h5xx_hal_iwdg.h 4 * @author MCD Application Team 5 * @brief Header file of IWDG HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32H5xx_HAL_IWDG_H 21 #define STM32H5xx_HAL_IWDG_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32h5xx_hal_def.h" 29 30 /** @addtogroup STM32H5xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @defgroup IWDG IWDG 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup IWDG_Exported_Types IWDG Exported Types 40 * @{ 41 */ 42 43 /** 44 * @brief IWDG Init structure definition 45 */ 46 typedef struct 47 { 48 uint32_t Prescaler; /*!< Select the prescaler of the IWDG. 49 This parameter can be a value of @ref IWDG_Prescaler */ 50 51 uint32_t Reload; /*!< Specifies the IWDG down-counter reload value. 52 This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */ 53 54 uint32_t Window; /*!< Specifies the window value to be compared to the down-counter. 55 This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */ 56 57 uint32_t EWI; /*!< Specifies if IWDG Early Wakeup Interrupt is enable or not and the comparator value. 58 This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF 59 value 0 means that EWI is disabled */ 60 } IWDG_InitTypeDef; 61 62 /** 63 * @brief IWDG Handle Structure definition 64 */ 65 #if (USE_HAL_IWDG_REGISTER_CALLBACKS == 1) 66 typedef struct __IWDG_HandleTypeDef 67 #else 68 typedef struct 69 #endif /* USE_HAL_IWDG_REGISTER_CALLBACKS */ 70 { 71 IWDG_TypeDef *Instance; /*!< Register base address */ 72 73 IWDG_InitTypeDef Init; /*!< IWDG required parameters */ 74 75 #if (USE_HAL_IWDG_REGISTER_CALLBACKS == 1) 76 void (* EwiCallback)(struct __IWDG_HandleTypeDef *hiwdg); /*!< IWDG Early WakeUp Interrupt callback */ 77 void (* MspInitCallback)(struct __IWDG_HandleTypeDef *hiwdg); /*!< IWDG Msp Init callback */ 78 #endif /* USE_HAL_IWDG_REGISTER_CALLBACKS */ 79 } IWDG_HandleTypeDef; 80 81 #if (USE_HAL_IWDG_REGISTER_CALLBACKS == 1) 82 /** 83 * @brief HAL IWDG common Callback ID enumeration definition 84 */ 85 typedef enum 86 { 87 HAL_IWDG_EWI_CB_ID = 0x00U, /*!< IWDG EWI callback ID */ 88 HAL_IWDG_MSPINIT_CB_ID = 0x01U, /*!< IWDG MspInit callback ID */ 89 } HAL_IWDG_CallbackIDTypeDef; 90 91 /** 92 * @brief HAL IWDG Callback pointer definition 93 */ 94 typedef void (*pIWDG_CallbackTypeDef)(IWDG_HandleTypeDef *hppp); /*!< pointer to a IWDG common callback functions */ 95 #endif /* USE_HAL_IWDG_REGISTER_CALLBACKS */ 96 97 98 /** 99 * @} 100 */ 101 102 /* Exported constants --------------------------------------------------------*/ 103 /** @defgroup IWDG_Exported_Constants IWDG Exported Constants 104 * @{ 105 */ 106 107 /** @defgroup IWDG_Prescaler IWDG Prescaler 108 * @{ 109 */ 110 #define IWDG_PRESCALER_4 0x00000000u /*!< IWDG prescaler set to 4 */ 111 #define IWDG_PRESCALER_8 IWDG_PR_PR_0 /*!< IWDG prescaler set to 8 */ 112 #define IWDG_PRESCALER_16 IWDG_PR_PR_1 /*!< IWDG prescaler set to 16 */ 113 #define IWDG_PRESCALER_32 (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 32 */ 114 #define IWDG_PRESCALER_64 IWDG_PR_PR_2 /*!< IWDG prescaler set to 64 */ 115 #define IWDG_PRESCALER_128 (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 128 */ 116 #define IWDG_PRESCALER_256 (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< IWDG prescaler set to 256 */ 117 #define IWDG_PRESCALER_512 (IWDG_PR_PR_2 | IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 512 */ 118 #define IWDG_PRESCALER_1024 IWDG_PR_PR_3 /*!< IWDG prescaler set to 1024 */ 119 /** 120 * @} 121 */ 122 123 /** @defgroup IWDG_Window_option IWDG Window option 124 * @{ 125 */ 126 #define IWDG_WINDOW_DISABLE IWDG_WINR_WIN 127 /** 128 * @} 129 */ 130 131 /** @defgroup IWDG_EWI_Mode IWDG Early Wakeup Interrupt Mode 132 * @{ 133 */ 134 #define IWDG_EWI_DISABLE 0x00000000u /*!< EWI Disable */ 135 /** 136 * @} 137 */ 138 139 /** @defgroup IWDG_Active_Status IWDG Active Status 140 * @{ 141 */ 142 #define IWDG_STATUS_DISABLE 0x00000000u 143 #define IWDG_STATUS_ENABLE IWDG_SR_ONF 144 /** 145 * @} 146 */ 147 148 /** 149 * @} 150 */ 151 152 /* Exported macros -----------------------------------------------------------*/ 153 /** @defgroup IWDG_Exported_Macros IWDG Exported Macros 154 * @{ 155 */ 156 157 /** 158 * @brief Enable the IWDG peripheral. 159 * @param __HANDLE__ IWDG handle 160 * @retval None 161 */ 162 #define __HAL_IWDG_START(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE) 163 164 /** 165 * @brief Reload IWDG counter with value defined in the reload register 166 * (write access to IWDG_PR, IWDG_RLR, IWDG_WINR and EWCR registers disabled). 167 * @param __HANDLE__ IWDG handle 168 * @retval None 169 */ 170 #define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD) 171 172 /** 173 * @} 174 */ 175 176 /* Exported functions --------------------------------------------------------*/ 177 /** @defgroup IWDG_Exported_Functions IWDG Exported Functions 178 * @{ 179 */ 180 181 /** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions 182 * @{ 183 */ 184 /* Initialization/Start functions ********************************************/ 185 HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg); 186 void HAL_IWDG_MspInit(IWDG_HandleTypeDef *hiwdg); 187 /* Callbacks Register/UnRegister functions ***********************************/ 188 #if (USE_HAL_IWDG_REGISTER_CALLBACKS == 1) 189 HAL_StatusTypeDef HAL_IWDG_RegisterCallback(IWDG_HandleTypeDef *hiwdg, HAL_IWDG_CallbackIDTypeDef CallbackID, 190 pIWDG_CallbackTypeDef pCallback); 191 HAL_StatusTypeDef HAL_IWDG_UnRegisterCallback(IWDG_HandleTypeDef *hiwdg, HAL_IWDG_CallbackIDTypeDef CallbackID); 192 #endif /* USE_HAL_IWDG_REGISTER_CALLBACKS */ 193 /** 194 * @} 195 */ 196 197 /** @defgroup IWDG_Exported_Functions_Group2 IO operation functions 198 * @{ 199 */ 200 /* I/O operation functions ****************************************************/ 201 HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg); 202 uint32_t HAL_IWDG_GetActiveStatus(IWDG_HandleTypeDef *hiwdg); 203 void HAL_IWDG_IRQHandler(IWDG_HandleTypeDef *hiwdg); 204 void HAL_IWDG_EarlyWakeupCallback(IWDG_HandleTypeDef *hiwdg); 205 /** 206 * @} 207 */ 208 209 /** 210 * @} 211 */ 212 213 /* Private constants ---------------------------------------------------------*/ 214 /** @defgroup IWDG_Private_Constants IWDG Private Constants 215 * @{ 216 */ 217 218 /** 219 * @brief IWDG Key Register BitMask 220 */ 221 #define IWDG_KEY_RELOAD 0x0000AAAAu /*!< IWDG Reload Counter Enable */ 222 #define IWDG_KEY_ENABLE 0x0000CCCCu /*!< IWDG Peripheral Enable */ 223 #define IWDG_KEY_WRITE_ACCESS_ENABLE 0x00005555u /*!< IWDG KR Write Access Enable */ 224 #define IWDG_KEY_WRITE_ACCESS_DISABLE 0x00000000u /*!< IWDG KR Write Access Disable */ 225 226 /** 227 * @} 228 */ 229 230 /* Private macros ------------------------------------------------------------*/ 231 /** @defgroup IWDG_Private_Macros IWDG Private Macros 232 * @{ 233 */ 234 235 /** 236 * @brief Enable write access to IWDG_PR, IWDG_RLR, IWDG_WINR and EWCR registers. 237 * @param __HANDLE__ IWDG handle 238 * @retval None 239 */ 240 #define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE) 241 242 /** 243 * @brief Disable write access to IWDG_PR, IWDG_RLR, IWDG_WINR and EWCR registers. 244 * @param __HANDLE__ IWDG handle 245 * @retval None 246 */ 247 #define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE) 248 249 /** 250 * @brief Check IWDG prescaler value. 251 * @param __PRESCALER__ IWDG prescaler value 252 * @retval None 253 */ 254 #define IS_IWDG_PRESCALER(__PRESCALER__) (((__PRESCALER__) == IWDG_PRESCALER_4) || \ 255 ((__PRESCALER__) == IWDG_PRESCALER_8) || \ 256 ((__PRESCALER__) == IWDG_PRESCALER_16) || \ 257 ((__PRESCALER__) == IWDG_PRESCALER_32) || \ 258 ((__PRESCALER__) == IWDG_PRESCALER_64) || \ 259 ((__PRESCALER__) == IWDG_PRESCALER_128)|| \ 260 ((__PRESCALER__) == IWDG_PRESCALER_256)|| \ 261 ((__PRESCALER__) == IWDG_PRESCALER_512)|| \ 262 ((__PRESCALER__) == IWDG_PRESCALER_1024)) 263 264 /** 265 * @brief Check IWDG reload value. 266 * @param __RELOAD__ IWDG reload value 267 * @retval None 268 */ 269 #define IS_IWDG_RELOAD(__RELOAD__) ((__RELOAD__) <= IWDG_RLR_RL) 270 271 /** 272 * @brief Check IWDG window value. 273 * @param __WINDOW__ IWDG window value 274 * @retval None 275 */ 276 #define IS_IWDG_WINDOW(__WINDOW__) ((__WINDOW__) <= IWDG_WINR_WIN) 277 278 /** 279 * @brief Check IWDG ewi value. 280 * @param __EWI__ IWDG ewi value 281 * @retval None 282 */ 283 #define IS_IWDG_EWI(__EWI__) ((__EWI__) <= IWDG_EWCR_EWIT) 284 285 /** 286 * @} 287 */ 288 289 /** 290 * @} 291 */ 292 293 /** 294 * @} 295 */ 296 297 298 #ifdef __cplusplus 299 } 300 #endif 301 302 #endif /* STM32H5xx_HAL_IWDG_H */ 303