1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_rtc.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© 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 36 /* Define to prevent recursive inclusion -------------------------------------*/ 37 #ifndef STM32L4xx_HAL_RTC_H 38 #define STM32L4xx_HAL_RTC_H 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* Includes ------------------------------------------------------------------*/ 45 #include "stm32l4xx_hal_def.h" 46 47 /** @addtogroup STM32L4xx_HAL_Driver 48 * @{ 49 */ 50 51 /** @defgroup RTC RTC 52 * @{ 53 */ 54 55 /* Exported types ------------------------------------------------------------*/ 56 /** @defgroup RTC_Exported_Types RTC Exported Types 57 * @{ 58 */ 59 60 /** 61 * @brief HAL State structures definition 62 */ 63 typedef enum 64 { 65 HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */ 66 HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */ 67 HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */ 68 HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */ 69 HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */ 70 71 }HAL_RTCStateTypeDef; 72 73 /** 74 * @brief RTC Configuration Structure definition 75 */ 76 typedef struct 77 { 78 uint32_t HourFormat; /*!< Specifies the RTC Hour Format. 79 This parameter can be a value of @ref RTC_Hour_Formats */ 80 81 uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value. 82 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */ 83 84 uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value. 85 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */ 86 87 uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output. 88 This parameter can be a value of @ref RTCEx_Output_selection_Definitions */ 89 90 uint32_t OutPutRemap; /*!< Specifies the remap for RTC output. 91 This parameter can be a value of @ref RTC_Output_ALARM_OUT_Remap */ 92 93 uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal. 94 This parameter can be a value of @ref RTC_Output_Polarity_Definitions */ 95 96 uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode. 97 This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */ 98 #if defined(STM32L412xx) || defined(STM32L422xx) 99 uint32_t OutPutPullUp; /*!< Specifies the RTC Output Pull-Up mode. 100 This parameter can be a value of @ref RTC_Output_PullUp_ALARM_OUT */ 101 #endif 102 }RTC_InitTypeDef; 103 104 /** 105 * @brief RTC Time structure definition 106 */ 107 typedef struct 108 { 109 uint8_t Hours; /*!< Specifies the RTC Time Hour. 110 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected. 111 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ 112 113 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 114 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 115 116 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 117 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 118 119 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 120 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 121 122 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. 123 This parameter corresponds to a time unit range between [0-1] Second 124 with [1 Sec / SecondFraction +1] granularity */ 125 126 uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content 127 corresponding to Synchronous pre-scaler factor value (PREDIV_S) 128 This parameter corresponds to a time unit range between [0-1] Second 129 with [1 Sec / SecondFraction +1] granularity. 130 This field will be used only by HAL_RTC_GetTime function */ 131 132 uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment. 133 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ 134 135 uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BKP bit 136 in CR register to store the operation. 137 This parameter can be a value of @ref RTC_StoreOperation_Definitions */ 138 }RTC_TimeTypeDef; 139 140 /** 141 * @brief RTC Date structure definition 142 */ 143 typedef struct 144 { 145 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 146 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 147 148 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 149 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 150 151 uint8_t Date; /*!< Specifies the RTC Date. 152 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 153 154 uint8_t Year; /*!< Specifies the RTC Date Year. 155 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ 156 157 }RTC_DateTypeDef; 158 159 /** 160 * @brief RTC Alarm structure definition 161 */ 162 typedef struct 163 { 164 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 165 166 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 167 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 168 169 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 170 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 171 172 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 173 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 174 175 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 176 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. 177 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ 178 179 uint32_t Alarm; /*!< Specifies the alarm . 180 This parameter can be a value of @ref RTC_Alarms_Definitions */ 181 }RTC_AlarmTypeDef; 182 183 /** 184 * @brief RTC Handle Structure definition 185 */ 186 typedef struct __RTC_HandleTypeDef 187 { 188 RTC_TypeDef *Instance; /*!< Register base address */ 189 190 #if defined(STM32L412xx) || defined(STM32L422xx) 191 uint32_t TampOffset; /*!< Offset to TAMP instance */ 192 #endif 193 RTC_InitTypeDef Init; /*!< RTC required parameters */ 194 195 HAL_LockTypeDef Lock; /*!< RTC locking object */ 196 197 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 198 199 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 200 void (* AlarmAEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Alarm A Event callback */ 201 void (* AlarmBEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Alarm B Event callback */ 202 void (* TimeStampEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC TimeStamp Event callback */ 203 void (* WakeUpTimerEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC WakeUpTimer Event callback */ 204 #if defined(RTC_TAMPER1_SUPPORT) 205 void (* Tamper1EventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Tamper 1 Event callback */ 206 #endif /* RTC_TAMPER1_SUPPORT */ 207 void (* Tamper2EventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Tamper 2 Event callback */ 208 #if defined(RTC_TAMPER3_SUPPORT) 209 void (* Tamper3EventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Tamper 3 Event callback */ 210 #endif /* RTC_TAMPER3_SUPPORT */ 211 void (* MspInitCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Msp Init callback */ 212 void (* MspDeInitCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Msp DeInit callback */ 213 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 214 215 }RTC_HandleTypeDef; 216 217 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 218 /** 219 * @brief HAL RTC Callback ID enumeration definition 220 */ 221 typedef enum 222 { 223 HAL_RTC_ALARM_A_EVENT_CB_ID = 0u, /*!< RTC Alarm A Event Callback ID */ 224 HAL_RTC_ALARM_B_EVENT_CB_ID = 1u, /*!< RTC Alarm B Event Callback ID */ 225 HAL_RTC_TIMESTAMP_EVENT_CB_ID = 2u, /*!< RTC TimeStamp Event Callback ID */ 226 HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 3u, /*!< RTC WakeUp Timer Event Callback ID */ 227 #if defined(RTC_TAMPER1_SUPPORT) 228 HAL_RTC_TAMPER1_EVENT_CB_ID = 4u, /*!< RTC Tamper 1 Callback ID */ 229 #endif /* RTC_TAMPER1_SUPPORT */ 230 HAL_RTC_TAMPER2_EVENT_CB_ID = 5u, /*!< RTC Tamper 2 Callback ID */ 231 #if defined(RTC_TAMPER3_SUPPORT) 232 HAL_RTC_TAMPER3_EVENT_CB_ID = 6u, /*!< RTC Tamper 3 Callback ID */ 233 #endif /* RTC_TAMPER3_SUPPORT */ 234 HAL_RTC_MSPINIT_CB_ID = 7u, /*!< RTC Msp Init callback ID */ 235 HAL_RTC_MSPDEINIT_CB_ID = 8u /*!< RTC Msp DeInit callback ID */ 236 }HAL_RTC_CallbackIDTypeDef; 237 238 /** 239 * @brief HAL RTC Callback pointer definition 240 */ 241 typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef * hrtc); /*!< pointer to an RTC callback function */ 242 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 243 244 /** 245 * @} 246 */ 247 248 /* Exported constants --------------------------------------------------------*/ 249 /** @defgroup RTC_Exported_Constants RTC Exported Constants 250 * @{ 251 */ 252 253 /** @defgroup RTC_Hour_Formats_Definitions RTC Hour Formats Definitions 254 * @{ 255 */ 256 #define RTC_HOURFORMAT_24 0x00000000u 257 #define RTC_HOURFORMAT_12 RTC_CR_FMT 258 /** 259 * @} 260 */ 261 262 /** @defgroup RTCEx_Output_selection_Definitions RTCEx Output Selection Definitions 263 * @{ 264 */ 265 #define RTC_OUTPUT_DISABLE 0x00000000u 266 #define RTC_OUTPUT_ALARMA RTC_CR_OSEL_0 267 #define RTC_OUTPUT_ALARMB RTC_CR_OSEL_1 268 #define RTC_OUTPUT_WAKEUP RTC_CR_OSEL 269 #if defined(STM32L412xx) || defined(STM32L422xx) 270 #define RTC_OUTPUT_TAMPER RTC_CR_TAMPOE 271 #endif 272 /** 273 * @} 274 */ 275 276 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions 277 * @{ 278 */ 279 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000u 280 #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL 281 /** 282 * @} 283 */ 284 285 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT 286 * @{ 287 */ 288 #if defined(STM32L412xx) || defined(STM32L422xx) 289 #define RTC_OUTPUT_TYPE_PUSHPULL 0x00000000u 290 #define RTC_OUTPUT_TYPE_OPENDRAIN RTC_CR_TAMPALRM_TYPE 291 #else 292 #define RTC_OUTPUT_TYPE_PUSHPULL RTC_OR_ALARMOUTTYPE 293 #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000u 294 #endif 295 /** 296 * @} 297 */ 298 299 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT 300 * @{ 301 */ 302 #if defined(STM32L412xx) || defined(STM32L422xx) 303 #define RTC_OUTPUT_PULLUP_NONE 0x00000000u 304 #define RTC_OUTPUT_PULLUP_ON RTC_CR_TAMPALRM_PU 305 #endif 306 /** 307 * @} 308 */ 309 310 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap 311 * @{ 312 */ 313 #if defined(STM32L412xx) || defined(STM32L422xx) 314 #define RTC_OUTPUT_REMAP_NONE 0x00000000u 315 #define RTC_OUTPUT_REMAP_POS1 RTC_CR_OUT2EN 316 #else 317 #define RTC_OUTPUT_REMAP_NONE 0x00000000u 318 #define RTC_OUTPUT_REMAP_POS1 RTC_OR_OUT_RMP 319 #endif 320 /** 321 * @} 322 */ 323 324 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 325 * @{ 326 */ 327 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00) 328 #define RTC_HOURFORMAT12_PM ((uint8_t)0x01) 329 /** 330 * @} 331 */ 332 333 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions 334 * @{ 335 */ 336 #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H 337 #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H 338 #define RTC_DAYLIGHTSAVING_NONE 0x00000000u 339 /** 340 * @} 341 */ 342 343 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions 344 * @{ 345 */ 346 #define RTC_STOREOPERATION_RESET 0x00000000u 347 #define RTC_STOREOPERATION_SET RTC_CR_BKP 348 /** 349 * @} 350 */ 351 352 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 353 * @{ 354 */ 355 #define RTC_FORMAT_BIN 0x00000000u 356 #define RTC_FORMAT_BCD 0x00000001u 357 /** 358 * @} 359 */ 360 361 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions (in BCD format) 362 * @{ 363 */ 364 365 /* Coded in BCD format */ 366 #define RTC_MONTH_JANUARY ((uint8_t)0x01U) 367 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02U) 368 #define RTC_MONTH_MARCH ((uint8_t)0x03U) 369 #define RTC_MONTH_APRIL ((uint8_t)0x04U) 370 #define RTC_MONTH_MAY ((uint8_t)0x05U) 371 #define RTC_MONTH_JUNE ((uint8_t)0x06U) 372 #define RTC_MONTH_JULY ((uint8_t)0x07U) 373 #define RTC_MONTH_AUGUST ((uint8_t)0x08U) 374 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09U) 375 #define RTC_MONTH_OCTOBER ((uint8_t)0x10U) 376 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11U) 377 #define RTC_MONTH_DECEMBER ((uint8_t)0x12U) 378 379 /** 380 * @} 381 */ 382 383 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 384 * @{ 385 */ 386 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01U) 387 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02U) 388 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03U) 389 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04U) 390 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05U) 391 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06U) 392 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07U) 393 394 /** 395 * @} 396 */ 397 398 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions 399 * @{ 400 */ 401 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000u 402 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL 403 404 /** 405 * @} 406 */ 407 408 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions 409 * @{ 410 */ 411 #define RTC_ALARMMASK_NONE 0x00000000u 412 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 413 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 414 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 415 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 416 #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_SECONDS) 417 418 /** 419 * @} 420 */ 421 422 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions 423 * @{ 424 */ 425 #define RTC_ALARM_A RTC_CR_ALRAE 426 #define RTC_ALARM_B RTC_CR_ALRBE 427 428 /** 429 * @} 430 */ 431 432 433 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 434 * @{ 435 */ 436 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000u /*!< All Alarm SS fields are masked. 437 There is no comparison on sub seconds 438 for Alarm */ 439 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 /*!< SS[14:1] are don't care in Alarm 440 comparison. Only SS[0] is compared. */ 441 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 /*!< SS[14:2] are don't care in Alarm 442 comparison. Only SS[1:0] are compared */ 443 #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1) /*!< SS[14:3] are don't care in Alarm 444 comparison. Only SS[2:0] are compared */ 445 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 /*!< SS[14:4] are don't care in Alarm 446 comparison. Only SS[3:0] are compared */ 447 #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:5] are don't care in Alarm 448 comparison. Only SS[4:0] are compared */ 449 #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:6] are don't care in Alarm 450 comparison. Only SS[5:0] are compared */ 451 #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:7] are don't care in Alarm 452 comparison. Only SS[6:0] are compared */ 453 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 /*!< SS[14:8] are don't care in Alarm 454 comparison. Only SS[7:0] are compared */ 455 #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:9] are don't care in Alarm 456 comparison. Only SS[8:0] are compared */ 457 #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:10] are don't care in Alarm 458 comparison. Only SS[9:0] are compared */ 459 #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:11] are don't care in Alarm 460 comparison. Only SS[10:0] are compared */ 461 #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:12] are don't care in Alarm 462 comparison.Only SS[11:0] are compared */ 463 #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:13] are don't care in Alarm 464 comparison. Only SS[12:0] are compared */ 465 #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14] is don't care in Alarm 466 comparison.Only SS[13:0] are compared */ 467 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS /*!< SS[14:0] are compared and must match 468 to activate alarm. */ 469 /** 470 * @} 471 */ 472 473 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 474 * @{ 475 */ 476 #define RTC_IT_TS RTC_CR_TSIE /*!< Enable Timestamp Interrupt */ 477 #define RTC_IT_WUT RTC_CR_WUTIE /*!< Enable Wakeup timer Interrupt */ 478 #define RTC_IT_ALRA RTC_CR_ALRAIE /*!< Enable Alarm A Interrupt */ 479 #define RTC_IT_ALRB RTC_CR_ALRBIE /*!< Enable Alarm B Interrupt */ 480 /** 481 * @} 482 */ 483 484 #if defined(STM32L412xx) || defined(STM32L422xx) 485 /** @defgroup RTC_Interruption_Mask RTC Interruptions Flag Mask 486 * @{ 487 */ 488 #define RTC_IT_MASK 0x001Fu /*!< RTC interruptions flags mask */ 489 /** 490 * @} 491 */ 492 493 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 494 * Elements values convention: 000000XX000YYYYYb 495 * - YYYYY : Interrupt flag position in the XX register (5bits) 496 * - XX : Interrupt status register (2bits) 497 * - 01: ICSR register 498 * - 10: SR register 499 * @{ 500 */ 501 #define RTC_FLAG_RECALPF 0x00000110u /*!< Recalibration pending Flag */ 502 #define RTC_FLAG_INITF 0x00000106u /*!< Initialization flag */ 503 #define RTC_FLAG_RSF 0x00000105u /*!< Registers synchronization flag */ 504 #define RTC_FLAG_INITS 0x00000104u /*!< Initialization status flag */ 505 #define RTC_FLAG_SHPF 0x00000103u /*!< Shift operation pending flag */ 506 #define RTC_FLAG_WUTWF 0x00000102u /*!< Wakeup timer write flag */ 507 #define RTC_FLAG_ALRBWF 0x00000101u /*!< Alarm B write flag */ 508 #define RTC_FLAG_ALRAWF 0x00000100u /*!< Alarm A write flag */ 509 #define RTC_FLAG_ITSF 0x00000205u /*!< Clear Internal Time-stamp flag */ 510 #define RTC_FLAG_TSOVF 0x00000204u /*!< Clear Time-stamp overflow flag */ 511 #define RTC_FLAG_TSF 0x00000203u /*!< Clear Time-stamp flag */ 512 #define RTC_FLAG_WUTF 0x00000202u /*!< Clear Wakeup timer flag */ 513 #define RTC_FLAG_ALRBF 0x00000201u /*!< Clear Alarm B flag */ 514 #define RTC_FLAG_ALRAF 0x00000200u /*!< Clear Alarm A flag */ 515 /** 516 * @} 517 */ 518 519 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions 520 * @{ 521 */ 522 #define RTC_CLEAR_ITSF RTC_SCR_CITSF /*!< Clear Internal Time-stamp flag */ 523 #define RTC_CLEAR_TSOVF RTC_SCR_CTSOVF /*!< Clear Time-stamp overflow flag */ 524 #define RTC_CLEAR_TSF RTC_SCR_CTSF /*!< Clear Time-stamp flag */ 525 #define RTC_CLEAR_WUTF RTC_SCR_CWUTF /*!< Clear Wakeup timer flag */ 526 #define RTC_CLEAR_ALRBF RTC_SCR_CALRBF /*!< Clear Alarm B flag */ 527 #define RTC_CLEAR_ALRAF RTC_SCR_CALRAF /*!< Clear Alarm A flag */ 528 529 /** 530 * @} 531 */ 532 533 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */ 534 535 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 536 * @{ 537 */ 538 #define RTC_FLAG_RECALPF RTC_ISR_RECALPF 539 #define RTC_FLAG_TSOVF RTC_ISR_TSOVF 540 #define RTC_FLAG_TSF RTC_ISR_TSF 541 #define RTC_FLAG_ITSF RTC_ISR_ITSF 542 #define RTC_FLAG_WUTF RTC_ISR_WUTF 543 #define RTC_FLAG_ALRBF RTC_ISR_ALRBF 544 #define RTC_FLAG_ALRAF RTC_ISR_ALRAF 545 #define RTC_FLAG_INITF RTC_ISR_INITF 546 #define RTC_FLAG_RSF RTC_ISR_RSF 547 #define RTC_FLAG_INITS RTC_ISR_INITS 548 #define RTC_FLAG_SHPF RTC_ISR_SHPF 549 #define RTC_FLAG_WUTWF RTC_ISR_WUTWF 550 #define RTC_FLAG_ALRBWF RTC_ISR_ALRBWF 551 #define RTC_FLAG_ALRAWF RTC_ISR_ALRAWF 552 /** 553 * @} 554 */ 555 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */ 556 557 /** 558 * @} 559 */ 560 561 /* Exported macros -----------------------------------------------------------*/ 562 /** @defgroup RTC_Exported_Macros RTC Exported Macros 563 * @{ 564 */ 565 566 /** @brief Reset RTC handle state 567 * @param __HANDLE__ RTC handle. 568 * @retval None 569 */ 570 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 571 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\ 572 (__HANDLE__)->State = HAL_RTC_STATE_RESET;\ 573 (__HANDLE__)->MspInitCallback = NULL;\ 574 (__HANDLE__)->MspDeInitCallback = NULL;\ 575 }while(0u) 576 #else 577 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 578 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 579 580 /** 581 * @brief Disable the write protection for RTC registers. 582 * @param __HANDLE__ specifies the RTC handle. 583 * @retval None 584 */ 585 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ 586 do{ \ 587 (__HANDLE__)->Instance->WPR = 0xCAU; \ 588 (__HANDLE__)->Instance->WPR = 0x53U; \ 589 } while(0u) 590 591 /** 592 * @brief Enable the write protection for RTC registers. 593 * @param __HANDLE__ specifies the RTC handle. 594 * @retval None 595 */ 596 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ 597 do{ \ 598 (__HANDLE__)->Instance->WPR = 0xFFU; \ 599 } while(0u) 600 601 /** 602 * @brief Add 1 hour (summer time change). 603 * @param __HANDLE__ specifies the RTC handle. 604 * @param __BKP__ Backup 605 * This parameter can be: 606 * @arg @ref RTC_STOREOPERATION_RESET 607 * @arg @ref RTC_STOREOPERATION_SET 608 * @retval None 609 */ 610 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__) \ 611 do { \ 612 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 613 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H); \ 614 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 615 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 616 } while(0u); 617 618 /** 619 * @brief Subtract 1 hour (winter time change). 620 * @param __HANDLE__ specifies the RTC handle. 621 * @param __BKP__ Backup 622 * This parameter can be: 623 * @arg @ref RTC_STOREOPERATION_RESET 624 * @arg @ref RTC_STOREOPERATION_SET 625 * @retval None 626 */ 627 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__) \ 628 do { \ 629 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 630 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H); \ 631 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 632 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 633 } while(0u); 634 635 /** 636 * @brief Enable the RTC ALARMA peripheral. 637 * @param __HANDLE__ specifies the RTC handle. 638 * @retval None 639 */ 640 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) 641 642 /** 643 * @brief Disable the RTC ALARMA peripheral. 644 * @param __HANDLE__ specifies the RTC handle. 645 * @retval None 646 */ 647 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) 648 649 /** 650 * @brief Enable the RTC ALARMB peripheral. 651 * @param __HANDLE__ specifies the RTC handle. 652 * @retval None 653 */ 654 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE)) 655 656 /** 657 * @brief Disable the RTC ALARMB peripheral. 658 * @param __HANDLE__ specifies the RTC handle. 659 * @retval None 660 */ 661 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE)) 662 663 /** 664 * @brief Enable the RTC Alarm interrupt. 665 * @param __HANDLE__ specifies the RTC handle. 666 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 667 * This parameter can be any combination of the following values: 668 * @arg @ref RTC_IT_ALRA Alarm A interrupt 669 * @arg @ref RTC_IT_ALRB Alarm B interrupt 670 * @retval None 671 */ 672 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 673 674 /** 675 * @brief Disable the RTC Alarm interrupt. 676 * @param __HANDLE__ specifies the RTC handle. 677 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 678 * This parameter can be any combination of the following values: 679 * @arg @ref RTC_IT_ALRA Alarm A interrupt 680 * @arg @ref RTC_IT_ALRB Alarm B interrupt 681 * @retval None 682 */ 683 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 684 685 /** 686 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 687 * @param __HANDLE__ specifies the RTC handle. 688 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 689 * This parameter can be: 690 * @arg @ref RTC_IT_ALRA Alarm A interrupt 691 * @arg @ref RTC_IT_ALRB Alarm B interrupt 692 * @retval None 693 */ 694 #if defined(STM32L412xx) || defined(STM32L422xx) 695 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& (__INTERRUPT__ >> 12)) != 0U)? 1U : 0U) 696 #else 697 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& (__INTERRUPT__ >> 4)) != 0U)? 1U : 0U) 698 #endif 699 /** 700 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 701 * @param __HANDLE__ specifies the RTC handle. 702 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 703 * This parameter can be: 704 * @arg @ref RTC_IT_ALRA Alarm A interrupt 705 * @arg @ref RTC_IT_ALRB Alarm B interrupt 706 * @retval None 707 */ 708 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U) 709 710 /** 711 * @brief Get the selected RTC Alarm's flag status. 712 * @param __HANDLE__ specifies the RTC handle. 713 * @param __FLAG__ specifies the RTC Alarm Flag sources to check. 714 * This parameter can be: 715 * @arg @ref RTC_FLAG_ALRAF 716 * @arg @ref RTC_FLAG_ALRBF 717 * @arg @ref RTC_FLAG_ALRAWF 718 * @arg @ref RTC_FLAG_ALRBWF 719 * @retval None 720 */ 721 #if defined(STM32L412xx) || defined(STM32L422xx) 722 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__))) 723 #else 724 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U) 725 #endif 726 727 /** 728 * @brief Clear the RTC Alarm's pending flags. 729 * @param __HANDLE__ specifies the RTC handle. 730 * @param __FLAG__ specifies the RTC Alarm Flag sources to clear. 731 * This parameter can be: 732 * @arg @ref RTC_FLAG_ALRAF 733 * @arg @ref RTC_FLAG_ALRBF 734 * @retval None 735 */ 736 #if defined(STM32L412xx) || defined(STM32L422xx) 737 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) == RTC_FLAG_ALRAF) ? (((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRAF))) : \ 738 ((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRBF))) 739 #else 740 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))) 741 #endif 742 743 /** 744 * @brief Enable interrupt on the RTC Alarm associated Exti line. 745 * @retval None 746 */ 747 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 748 749 /** 750 * @brief Disable interrupt on the RTC Alarm associated Exti line. 751 * @retval None 752 */ 753 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 754 755 /** 756 * @brief Enable event on the RTC Alarm associated Exti line. 757 * @retval None. 758 */ 759 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 760 761 /** 762 * @brief Disable event on the RTC Alarm associated Exti line. 763 * @retval None. 764 */ 765 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 766 767 /** 768 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line. 769 * @retval None 770 */ 771 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT) 772 773 /** 774 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line. 775 * @retval None 776 */ 777 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 778 779 /** 780 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line. 781 * @retval None 782 */ 783 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT) 784 785 /** 786 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line. 787 * @retval None 788 */ 789 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 790 791 /** 792 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. 793 * @retval None 794 */ 795 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 796 __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \ 797 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \ 798 } while(0u) 799 800 /** 801 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. 802 * @retval None 803 */ 804 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 805 __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \ 806 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \ 807 } while(0u) 808 809 /** 810 * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not. 811 * @retval Line Status. 812 */ 813 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR1 & RTC_EXTI_LINE_ALARM_EVENT) 814 815 /** 816 * @brief Clear the RTC Alarm associated Exti line flag. 817 * @retval None 818 */ 819 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR1 = RTC_EXTI_LINE_ALARM_EVENT) 820 821 /** 822 * @brief Generate a Software interrupt on RTC Alarm associated Exti line. 823 * @retval None 824 */ 825 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER1 |= RTC_EXTI_LINE_ALARM_EVENT) 826 827 /** 828 * @} 829 */ 830 831 /* Include RTC HAL Extended module */ 832 #include "stm32l4xx_hal_rtc_ex.h" 833 834 /* Exported functions --------------------------------------------------------*/ 835 /** @defgroup RTC_Exported_Functions RTC Exported Functions 836 * @{ 837 */ 838 839 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions 840 * @{ 841 */ 842 /* Initialization and de-initialization functions ****************************/ 843 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); 844 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 845 846 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 847 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 848 849 /* Callbacks Register/UnRegister functions ***********************************/ 850 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 851 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback); 852 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID); 853 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 854 /** 855 * @} 856 */ 857 858 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions 859 * @{ 860 */ 861 /* RTC Time and Date functions ************************************************/ 862 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 863 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 864 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 865 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 866 /** 867 * @} 868 */ 869 870 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions 871 * @{ 872 */ 873 /* RTC Alarm functions ********************************************************/ 874 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 875 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 876 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); 877 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); 878 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 879 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 880 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 881 /** 882 * @} 883 */ 884 885 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions 886 * @{ 887 */ 888 /* Peripheral Control functions ***********************************************/ 889 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc); 890 /** 891 * @} 892 */ 893 894 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions 895 * @{ 896 */ 897 /* Peripheral State functions *************************************************/ 898 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); 899 /** 900 * @} 901 */ 902 903 /** 904 * @} 905 */ 906 907 /* Private types -------------------------------------------------------------*/ 908 /* Private variables ---------------------------------------------------------*/ 909 /* Private constants ---------------------------------------------------------*/ 910 /** @defgroup RTC_Private_Constants RTC Private Constants 911 * @{ 912 */ 913 /* Masks Definition */ 914 #define RTC_TR_RESERVED_MASK (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \ 915 RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \ 916 RTC_TR_SU) 917 918 #define RTC_DR_RESERVED_MASK (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \ 919 RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \ 920 RTC_DR_DU) 921 922 #define RTC_INIT_MASK 0xFFFFFFFFu 923 #if defined(STM32L412xx) || defined(STM32L422xx) 924 #define RTC_RSF_MASK (~(RTC_ICSR_INIT | RTC_ICSR_RSF)) 925 #else 926 #define RTC_RSF_MASK (~(RTC_ISR_INIT | RTC_ISR_RSF)) 927 #endif 928 929 #define RTC_TIMEOUT_VALUE 1000u 930 931 #define RTC_EXTI_LINE_ALARM_EVENT EXTI_IMR1_IM18 /*!< External interrupt line 18 Connected to the RTC Alarm event */ 932 933 /** 934 * @} 935 */ 936 937 /* Private macros ------------------------------------------------------------*/ 938 /** @defgroup RTC_Private_Macros RTC Private Macros 939 * @{ 940 */ 941 942 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 943 * @{ 944 */ 945 #if defined(STM32L412xx) || defined(STM32L422xx) 946 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 947 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 948 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \ 949 ((OUTPUT) == RTC_OUTPUT_WAKEUP) || \ 950 ((OUTPUT) == RTC_OUTPUT_TAMPER)) 951 #else 952 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 953 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 954 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \ 955 ((OUTPUT) == RTC_OUTPUT_WAKEUP)) 956 #endif 957 958 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 959 ((FORMAT) == RTC_HOURFORMAT_24)) 960 961 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 962 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 963 964 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ 965 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) 966 967 #if defined(STM32L412xx) || defined(STM32L422xx) 968 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \ 969 ((TYPE) == RTC_OUTPUT_PULLUP_ON)) 970 #endif 971 972 #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \ 973 ((REMAP) == RTC_OUTPUT_REMAP_POS1)) 974 975 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \ 976 ((PM) == RTC_HOURFORMAT12_PM)) 977 978 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 979 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 980 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 981 982 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 983 ((OPERATION) == RTC_STOREOPERATION_SET)) 984 985 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \ 986 ((FORMAT) == RTC_FORMAT_BCD)) 987 988 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99u) 989 990 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1u) && ((MONTH) <= 12u)) 991 992 #define IS_RTC_DATE(DATE) (((DATE) >= 1u) && ((DATE) <= 31u)) 993 994 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 995 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 996 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 997 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 998 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 999 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 1000 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 1001 1002 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u)) 1003 1004 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 1005 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 1006 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 1007 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 1008 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 1009 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 1010 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 1011 1012 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 1013 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 1014 1015 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0U) 1016 1017 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || \ 1018 ((ALARM) == RTC_ALARM_B)) 1019 1020 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS) 1021 1022 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == 0u) || \ 1023 (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE))) 1024 1025 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos)) 1026 1027 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos)) 1028 1029 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0u) && ((HOUR) <= 12u)) 1030 1031 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23u) 1032 1033 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59u) 1034 1035 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59u) 1036 1037 /** 1038 * @} 1039 */ 1040 1041 /** 1042 * @} 1043 */ 1044 1045 /* Private functions -------------------------------------------------------------*/ 1046 /** @defgroup RTC_Private_Functions RTC Private Functions 1047 * @{ 1048 */ 1049 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc); 1050 uint8_t RTC_ByteToBcd2(uint8_t Value); 1051 uint8_t RTC_Bcd2ToByte(uint8_t Value); 1052 /** 1053 * @} 1054 */ 1055 1056 1057 /** 1058 * @} 1059 */ 1060 1061 /** 1062 * @} 1063 */ 1064 1065 /** 1066 * @} 1067 */ 1068 1069 #ifdef __cplusplus 1070 } 1071 #endif 1072 1073 #endif /* STM32L4xx_HAL_RTC_H */ 1074 1075 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 1076 1077