2 ******************************************************************************
3 * @file stm32f1xx_hal_rtc_ex.h
4 * @author MCD Application Team
6 * @date 15-December-2014
7 * @brief Header file of RTC HAL Extension module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 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_HAL_RTC_EX_H
40 #define __STM32F1xx_HAL_RTC_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f1xx_hal_def.h"
49 /** @addtogroup STM32F1xx_HAL_Driver
57 /** @addtogroup RTCEx_Private_Macros
61 /** @defgroup RTCEx_Alias_For_Legacy Alias define maintained for legacy
64 #define HAL_RTCEx_TamperTimeStampIRQHandler HAL_RTCEx_TamperIRQHandler
70 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
73 #define IS_RTC_TAMPER(__TAMPER__) ((__TAMPER__) == RTC_TAMPER_1)
75 #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__) (((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL) || \
76 ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL))
78 #if RTC_BKP_NUMBER > 10
79 #define IS_RTC_BKP(BKP) (((BKP) <= (uint32_t) RTC_BKP_DR10) || (((BKP) >= (uint32_t) RTC_BKP_DR11) && ((BKP) <= (uint32_t) RTC_BKP_DR42)))
81 #define IS_RTC_BKP(BKP) ((BKP) <= (uint32_t) RTC_BKP_NUMBER)
83 #define IS_RTC_SMOOTH_CALIB_MINUS(__VALUE__) ((__VALUE__) <= 0x0000007F)
93 /* Exported types ------------------------------------------------------------*/
94 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
98 * @brief RTC Tamper structure definition
102 uint32_t Tamper; /*!< Specifies the Tamper Pin.
103 This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions */
105 uint32_t Trigger; /*!< Specifies the Tamper Trigger.
106 This parameter can be a value of @ref RTCEx_Tamper_Trigger_Definitions */
114 /* Exported constants --------------------------------------------------------*/
115 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
119 /** @defgroup RTCEx_Tamper_Pins_Definitions Tamper Pins Definitions
122 #define RTC_TAMPER_1 BKP_CR_TPE /*!< Select tamper to be enabled (mainly for legacy purposes) */
128 /** @defgroup RTCEx_Tamper_Trigger_Definitions Tamper Trigger Definitions
131 #define RTC_TAMPERTRIGGER_LOWLEVEL BKP_CR_TPAL /*!< A high level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
132 #define RTC_TAMPERTRIGGER_HIGHLEVEL ((uint32_t)0x00000000) /*!< A low level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
138 /** @defgroup RTCEx_Backup_Registers_Definitions Backup Registers Definitions
141 #if RTC_BKP_NUMBER > 0
142 #define RTC_BKP_DR1 ((uint32_t)0x00000001)
143 #define RTC_BKP_DR2 ((uint32_t)0x00000002)
144 #define RTC_BKP_DR3 ((uint32_t)0x00000003)
145 #define RTC_BKP_DR4 ((uint32_t)0x00000004)
146 #define RTC_BKP_DR5 ((uint32_t)0x00000005)
147 #define RTC_BKP_DR6 ((uint32_t)0x00000006)
148 #define RTC_BKP_DR7 ((uint32_t)0x00000007)
149 #define RTC_BKP_DR8 ((uint32_t)0x00000008)
150 #define RTC_BKP_DR9 ((uint32_t)0x00000009)
151 #define RTC_BKP_DR10 ((uint32_t)0x0000000A)
152 #endif /* RTC_BKP_NUMBER > 0 */
154 #if RTC_BKP_NUMBER > 10
155 #define RTC_BKP_DR11 ((uint32_t)0x00000010)
156 #define RTC_BKP_DR12 ((uint32_t)0x00000011)
157 #define RTC_BKP_DR13 ((uint32_t)0x00000012)
158 #define RTC_BKP_DR14 ((uint32_t)0x00000013)
159 #define RTC_BKP_DR15 ((uint32_t)0x00000014)
160 #define RTC_BKP_DR16 ((uint32_t)0x00000015)
161 #define RTC_BKP_DR17 ((uint32_t)0x00000016)
162 #define RTC_BKP_DR18 ((uint32_t)0x00000017)
163 #define RTC_BKP_DR19 ((uint32_t)0x00000018)
164 #define RTC_BKP_DR20 ((uint32_t)0x00000019)
165 #define RTC_BKP_DR21 ((uint32_t)0x0000001A)
166 #define RTC_BKP_DR22 ((uint32_t)0x0000001B)
167 #define RTC_BKP_DR23 ((uint32_t)0x0000001C)
168 #define RTC_BKP_DR24 ((uint32_t)0x0000001D)
169 #define RTC_BKP_DR25 ((uint32_t)0x0000001E)
170 #define RTC_BKP_DR26 ((uint32_t)0x0000001F)
171 #define RTC_BKP_DR27 ((uint32_t)0x00000020)
172 #define RTC_BKP_DR28 ((uint32_t)0x00000021)
173 #define RTC_BKP_DR29 ((uint32_t)0x00000022)
174 #define RTC_BKP_DR30 ((uint32_t)0x00000023)
175 #define RTC_BKP_DR31 ((uint32_t)0x00000024)
176 #define RTC_BKP_DR32 ((uint32_t)0x00000025)
177 #define RTC_BKP_DR33 ((uint32_t)0x00000026)
178 #define RTC_BKP_DR34 ((uint32_t)0x00000027)
179 #define RTC_BKP_DR35 ((uint32_t)0x00000028)
180 #define RTC_BKP_DR36 ((uint32_t)0x00000029)
181 #define RTC_BKP_DR37 ((uint32_t)0x0000002A)
182 #define RTC_BKP_DR38 ((uint32_t)0x0000002B)
183 #define RTC_BKP_DR39 ((uint32_t)0x0000002C)
184 #define RTC_BKP_DR40 ((uint32_t)0x0000002D)
185 #define RTC_BKP_DR41 ((uint32_t)0x0000002E)
186 #define RTC_BKP_DR42 ((uint32_t)0x0000002F)
187 #endif /* RTC_BKP_NUMBER > 10 */
197 /* Exported macro ------------------------------------------------------------*/
198 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
203 * @brief Enable the RTC Tamper interrupt.
204 * @param __HANDLE__: specifies the RTC handle.
205 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be enabled
206 * This parameter can be any combination of the following values:
207 * @arg RTC_IT_TAMP1: Tamper A interrupt
210 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT(BKP->CSR, (__INTERRUPT__))
213 * @brief Disable the RTC Tamper interrupt.
214 * @param __HANDLE__: specifies the RTC handle.
215 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be disabled.
216 * This parameter can be any combination of the following values:
217 * @arg RTC_IT_TAMP1: Tamper A interrupt
220 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT(BKP->CSR, (__INTERRUPT__))
223 * @brief Check whether the specified RTC Tamper interrupt has been enabled or not.
224 * @param __HANDLE__: specifies the RTC handle.
225 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked.
226 * This parameter can be:
230 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((BKP->CSR) & ((__INTERRUPT__))) != RESET)? SET : RESET)
233 * @brief Get the selected RTC Tamper's flag status.
234 * @param __HANDLE__: specifies the RTC handle.
235 * @param __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
236 * This parameter can be:
237 * @arg RTC_FLAG_TAMP1F
240 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__) ((((BKP->CSR) & (__FLAG__)) != RESET)? SET : RESET)
243 * @brief Get the selected RTC Tamper's flag status.
244 * @param __HANDLE__: specifies the RTC handle.
245 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked.
246 * This parameter can be:
250 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__) ((((BKP->CSR) & (BKP_CSR_TEF)) != RESET)? SET : RESET)
253 * @brief Clear the RTC Tamper's pending flags.
254 * @param __HANDLE__: specifies the RTC handle.
255 * @param __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
256 * This parameter can be:
257 * @arg RTC_FLAG_TAMP1F
260 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT(BKP->CSR, BKP_CSR_CTE | BKP_CSR_CTI)
263 * @brief Enable the RTC Second interrupt.
264 * @param __HANDLE__: specifies the RTC handle.
265 * @param __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled
266 * This parameter can be any combination of the following values:
267 * @arg RTC_IT_SEC: Second A interrupt
270 #define __HAL_RTC_SECOND_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
273 * @brief Disable the RTC Second interrupt.
274 * @param __HANDLE__: specifies the RTC handle.
275 * @param __INTERRUPT__: specifies the RTC Second interrupt sources to be disabled.
276 * This parameter can be any combination of the following values:
277 * @arg RTC_IT_SEC: Second A interrupt
280 #define __HAL_RTC_SECOND_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
283 * @brief Check whether the specified RTC Second interrupt has occurred or not.
284 * @param __HANDLE__: specifies the RTC handle.
285 * @param __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled or disabled.
286 * This parameter can be:
287 * @arg RTC_IT_SEC: Second A interrupt
290 #define __HAL_RTC_SECOND_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__)))) != RESET)? SET : RESET)
293 * @brief Get the selected RTC Second's flag status.
294 * @param __HANDLE__: specifies the RTC handle.
295 * @param __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled.
296 * This parameter can be:
300 #define __HAL_RTC_SECOND_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET)
303 * @brief Clear the RTC Second's pending flags.
304 * @param __HANDLE__: specifies the RTC handle.
305 * @param __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled.
306 * This parameter can be:
310 #define __HAL_RTC_SECOND_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CRL) = ~(__FLAG__)
313 * @brief Enable the RTC Overflow interrupt.
314 * @param __HANDLE__: specifies the RTC handle.
315 * @param __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled
316 * This parameter can be any combination of the following values:
317 * @arg RTC_IT_OW: Overflow A interrupt
320 #define __HAL_RTC_OVERFLOW_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
323 * @brief Disable the RTC Overflow interrupt.
324 * @param __HANDLE__: specifies the RTC handle.
325 * @param __INTERRUPT__: specifies the RTC Overflow interrupt sources to be disabled.
326 * This parameter can be any combination of the following values:
327 * @arg RTC_IT_OW: Overflow A interrupt
330 #define __HAL_RTC_OVERFLOW_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__))
333 * @brief Check whether the specified RTC Overflow interrupt has occurred or not.
334 * @param __HANDLE__: specifies the RTC handle.
335 * @param __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled or disabled.
336 * This parameter can be:
337 * @arg RTC_IT_OW: Overflow A interrupt
340 #define __HAL_RTC_OVERFLOW_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__))) ) != RESET)? SET : RESET)
343 * @brief Get the selected RTC Overflow's flag status.
344 * @param __HANDLE__: specifies the RTC handle.
345 * @param __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled.
346 * This parameter can be:
350 #define __HAL_RTC_OVERFLOW_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET)
353 * @brief Clear the RTC Overflow's pending flags.
354 * @param __HANDLE__: specifies the RTC handle.
355 * @param __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled.
356 * This parameter can be:
360 #define __HAL_RTC_OVERFLOW_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CRL) = ~(__FLAG__)
366 /* Exported functions --------------------------------------------------------*/
367 /** @addtogroup RTCEx_Exported_Functions
371 /* RTC Tamper functions *****************************************/
372 /** @addtogroup RTCEx_Exported_Functions_Group1
375 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper);
376 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper);
377 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
378 void HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc);
379 void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
380 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
386 /* RTC Second functions *****************************************/
387 /** @addtogroup RTCEx_Exported_Functions_Group2
390 HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc);
391 HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc);
392 void HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef* hrtc);
393 void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc);
394 void HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc);
400 /* Extension Control functions ************************************************/
401 /** @addtogroup RTCEx_Exported_Functions_Group3
404 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
405 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
407 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue);
428 #endif /* __STM32F1xx_HAL_RTC_EX_H */
430 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/