1 /** 2 ****************************************************************************** 3 * @file stm32l0xx_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) 2016 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 __STM32L0xx_HAL_RTC_H 38 #define __STM32L0xx_HAL_RTC_H 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* Includes ------------------------------------------------------------------*/ 45 #include "stm32l0xx_hal_def.h" 46 47 /** @addtogroup STM32L0xx_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 }RTC_InitTypeDef; 99 100 /** 101 * @brief RTC Time structure definition 102 */ 103 typedef struct 104 { 105 uint8_t Hours; /*!< Specifies the RTC Time Hour. 106 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected. 107 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ 108 109 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 110 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 111 112 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 113 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 114 115 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 116 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 117 118 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. 119 This parameter corresponds to a time unit range between [0-1] Second 120 with [1 Sec / SecondFraction +1] granularity */ 121 122 uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content 123 corresponding to Synchronous pre-scaler factor value (PREDIV_S) 124 This parameter corresponds to a time unit range between [0-1] Second 125 with [1 Sec / SecondFraction +1] granularity. 126 This field will be used only by HAL_RTC_GetTime function */ 127 128 uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment. 129 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ 130 131 uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit 132 in CR register to store the operation. 133 This parameter can be a value of @ref RTC_StoreOperation_Definitions */ 134 }RTC_TimeTypeDef; 135 136 /** 137 * @brief RTC Date structure definition 138 */ 139 typedef struct 140 { 141 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 142 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 143 144 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 145 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 146 147 uint8_t Date; /*!< Specifies the RTC Date. 148 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 149 150 uint8_t Year; /*!< Specifies the RTC Date Year. 151 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ 152 153 }RTC_DateTypeDef; 154 155 /** 156 * @brief RTC Alarm structure definition 157 */ 158 typedef struct 159 { 160 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 161 162 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 163 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 164 165 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 166 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 167 168 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 169 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 170 171 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 172 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. 173 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ 174 175 uint32_t Alarm; /*!< Specifies the alarm . 176 This parameter can be a value of @ref RTC_Alarms_Definitions */ 177 }RTC_AlarmTypeDef; 178 179 /** 180 * @brief RTC Handle Structure definition 181 */ 182 typedef struct 183 { 184 RTC_TypeDef *Instance; /*!< Register base address */ 185 186 RTC_InitTypeDef Init; /*!< RTC required parameters */ 187 188 HAL_LockTypeDef Lock; /*!< RTC locking object */ 189 190 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 191 192 }RTC_HandleTypeDef; 193 /** 194 * @} 195 */ 196 197 /* Exported constants --------------------------------------------------------*/ 198 /** @defgroup RTC_Exported_Constants RTC Exported Constants 199 * @{ 200 */ 201 202 /** @defgroup RTC_Hour_Formats RTC Hour Formats 203 * @{ 204 */ 205 #define RTC_HOURFORMAT_24 ((uint32_t)0x00000000U) 206 #define RTC_HOURFORMAT_12 ((uint32_t)RTC_CR_FMT) 207 208 /** 209 * @} 210 */ 211 212 213 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions 214 * @{ 215 */ 216 #define RTC_OUTPUT_POLARITY_HIGH ((uint32_t)0x00000000U) 217 #define RTC_OUTPUT_POLARITY_LOW ((uint32_t)RTC_CR_POL) 218 219 /** 220 * @} 221 */ 222 223 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT 224 * @{ 225 */ 226 #define RTC_OUTPUT_TYPE_OPENDRAIN ((uint32_t)0x00000000U) 227 #define RTC_OUTPUT_TYPE_PUSHPULL ((uint32_t)RTC_OR_ALARMOUTTYPE) 228 229 /** 230 * @} 231 */ 232 233 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap 234 * @{ 235 */ 236 #define RTC_OUTPUT_REMAP_NONE ((uint32_t)0x00000000U) 237 #define RTC_OUTPUT_REMAP_POS1 ((uint32_t)RTC_OR_OUT_RMP) 238 /** 239 * @} 240 */ 241 242 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 243 * @{ 244 */ 245 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00U) 246 #define RTC_HOURFORMAT12_PM ((uint8_t)0x40U) 247 248 /** 249 * @} 250 */ 251 252 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions 253 * @{ 254 */ 255 #define RTC_DAYLIGHTSAVING_SUB1H ((uint32_t)RTC_CR_SUB1H) 256 #define RTC_DAYLIGHTSAVING_ADD1H ((uint32_t)RTC_CR_ADD1H) 257 #define RTC_DAYLIGHTSAVING_NONE ((uint32_t)0x00000000U) 258 259 /** 260 * @} 261 */ 262 263 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions 264 * @{ 265 */ 266 #define RTC_STOREOPERATION_RESET ((uint32_t)0x00000000U) 267 #define RTC_STOREOPERATION_SET ((uint32_t)RTC_CR_BCK) 268 269 /** 270 * @} 271 */ 272 273 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 274 * @{ 275 */ 276 #define RTC_FORMAT_BIN ((uint32_t)0x000000000U) 277 #define RTC_FORMAT_BCD ((uint32_t)0x000000001U) 278 279 /** 280 * @} 281 */ 282 283 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions 284 * @{ 285 */ 286 287 /* Coded in BCD format */ 288 #define RTC_MONTH_JANUARY ((uint8_t)0x01U) 289 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02U) 290 #define RTC_MONTH_MARCH ((uint8_t)0x03U) 291 #define RTC_MONTH_APRIL ((uint8_t)0x04U) 292 #define RTC_MONTH_MAY ((uint8_t)0x05U) 293 #define RTC_MONTH_JUNE ((uint8_t)0x06U) 294 #define RTC_MONTH_JULY ((uint8_t)0x07U) 295 #define RTC_MONTH_AUGUST ((uint8_t)0x08U) 296 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09U) 297 #define RTC_MONTH_OCTOBER ((uint8_t)0x10U) 298 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11U) 299 #define RTC_MONTH_DECEMBER ((uint8_t)0x12U) 300 301 /** 302 * @} 303 */ 304 305 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 306 * @{ 307 */ 308 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01U) 309 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02U) 310 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03U) 311 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04U) 312 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05U) 313 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06U) 314 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07U) 315 316 /** 317 * @} 318 */ 319 320 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions 321 * @{ 322 */ 323 #define RTC_ALARMDATEWEEKDAYSEL_DATE ((uint32_t)0x00000000U) 324 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL 325 326 /** 327 * @} 328 */ 329 330 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions 331 * @{ 332 */ 333 #define RTC_ALARMMASK_NONE ((uint32_t)0x00000000U) 334 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 335 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 336 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 337 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 338 #define RTC_ALARMMASK_ALL ((uint32_t) (RTC_ALARMMASK_NONE | \ 339 RTC_ALARMMASK_DATEWEEKDAY | \ 340 RTC_ALARMMASK_HOURS | \ 341 RTC_ALARMMASK_MINUTES | \ 342 RTC_ALARMMASK_SECONDS)) 343 344 /** 345 * @} 346 */ 347 348 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions 349 * @{ 350 */ 351 #define RTC_ALARM_A RTC_CR_ALRAE 352 #define RTC_ALARM_B RTC_CR_ALRBE 353 354 /** 355 * @} 356 */ 357 358 359 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 360 * @{ 361 */ 362 #define RTC_ALARMSUBSECONDMASK_ALL ((uint32_t)0x00000000U) /*!< All Alarm SS fields are masked. 363 There is no comparison on sub seconds 364 for Alarm */ 365 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 /*!< SS[14:1] are don't care in Alarm 366 comparison. Only SS[0] is compared. */ 367 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 /*!< SS[14:2] are don't care in Alarm 368 comparison. Only SS[1:0] are compared */ 369 #define RTC_ALARMSUBSECONDMASK_SS14_3 ((uint32_t) (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1)) /*!< SS[14:3] are don't care in Alarm 370 comparison. Only SS[2:0] are compared */ 371 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 /*!< SS[14:4] are don't care in Alarm 372 comparison. Only SS[3:0] are compared */ 373 #define RTC_ALARMSUBSECONDMASK_SS14_5 ((uint32_t) (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2)) /*!< SS[14:5] are don't care in Alarm 374 comparison. Only SS[4:0] are compared */ 375 #define RTC_ALARMSUBSECONDMASK_SS14_6 ((uint32_t) (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)) /*!< SS[14:6] are don't care in Alarm 376 comparison. Only SS[5:0] are compared */ 377 #define RTC_ALARMSUBSECONDMASK_SS14_7 ((uint32_t) (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)) /*!< SS[14:7] are don't care in Alarm 378 ` comparison. Only SS[6:0] are compared */ 379 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 /*!< SS[14:8] are don't care in Alarm 380 comparison. Only SS[7:0] are compared */ 381 #define RTC_ALARMSUBSECONDMASK_SS14_9 ((uint32_t) (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3)) /*!< SS[14:9] are don't care in Alarm 382 comparison. Only SS[8:0] are compared */ 383 #define RTC_ALARMSUBSECONDMASK_SS14_10 ((uint32_t) (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)) /*!< SS[14:10] are don't care in Alarm 384 comparison. Only SS[9:0] are compared */ 385 #define RTC_ALARMSUBSECONDMASK_SS14_11 ((uint32_t) (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)) /*!< SS[14:11] are don't care in Alarm 386 comparison. Only SS[10:0] are compared */ 387 #define RTC_ALARMSUBSECONDMASK_SS14_12 ((uint32_t) (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)) /*!< SS[14:12] are don't care in Alarm 388 comparison.Only SS[11:0] are compared */ 389 #define RTC_ALARMSUBSECONDMASK_SS14_13 ((uint32_t) (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)) /*!< SS[14:13] are don't care in Alarm 390 comparison. Only SS[12:0] are compared */ 391 #define RTC_ALARMSUBSECONDMASK_SS14 ((uint32_t) (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)) /*!< SS[14] is don't care in Alarm 392 comparison.Only SS[13:0] are compared */ 393 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS /*!< SS[14:0] are compared and must match 394 to activate alarm. */ 395 /** 396 * @} 397 */ 398 399 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 400 * @{ 401 */ 402 #define RTC_IT_TS ((uint32_t)RTC_CR_TSIE) /*!< Enable Timestamp Interrupt */ 403 #define RTC_IT_WUT ((uint32_t)RTC_CR_WUTIE) /*!< Enable Wakeup timer Interrupt */ 404 #define RTC_IT_ALRA ((uint32_t)RTC_CR_ALRAIE) /*!< Enable Alarm A Interrupt */ 405 #define RTC_IT_ALRB ((uint32_t)RTC_CR_ALRBIE) /*!< Enable Alarm B Interrupt */ 406 #define RTC_IT_TAMP ((uint32_t)RTC_TAMPCR_TAMPIE) /*!< Enable all Tamper Interrupt */ 407 408 #if defined (STM32L063xx) || defined (STM32L062xx) || defined (STM32L061xx) || \ 409 defined (STM32L053xx) || defined (STM32L052xx) || defined (STM32L051xx) ||\ 410 defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ 411 defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) || \ 412 defined (STM32L031xx) || defined (STM32L041xx) 413 414 #define RTC_IT_TAMP1 ((uint32_t)RTC_TAMPCR_TAMP1IE) /*!< Enable Tamper 1 Interrupt */ 415 #endif /* (STM32L063xx) || (STM32L062xx) || (STM32L061xx) || 416 * (STM32L053xx) || (STM32L052xx) || (STM32L051xx) || 417 * (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || 418 * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) || 419 * (STM32L031xx) || (STM32L041xx) 420 */ 421 #define RTC_IT_TAMP2 ((uint32_t)RTC_TAMPCR_TAMP2IE) /*!< Enable Tamper 2 Interrupt */ 422 /** 423 * @} 424 */ 425 426 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 427 * @{ 428 */ 429 #define RTC_FLAG_RECALPF ((uint32_t)RTC_ISR_RECALPF) 430 #define RTC_FLAG_TAMP2F ((uint32_t)RTC_ISR_TAMP2F) 431 432 #if defined (STM32L063xx) || defined (STM32L062xx) || defined (STM32L061xx) || \ 433 defined (STM32L053xx) || defined (STM32L052xx) || defined (STM32L051xx) ||\ 434 defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ 435 defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) || \ 436 defined (STM32L031xx) || defined (STM32L041xx) 437 #define RTC_FLAG_TAMP1F ((uint32_t)RTC_ISR_TAMP1F) 438 #endif /* (STM32L063xx) || (STM32L062xx) || (STM32L061xx) || 439 * (STM32L053xx) || (STM32L052xx) || (STM32L051xx) || 440 * (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || 441 * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) || 442 * (STM32L031xx) || (STM32L041xx) 443 */ 444 445 #define RTC_FLAG_TSOVF ((uint32_t)RTC_ISR_TSOVF) 446 #define RTC_FLAG_TSF ((uint32_t)RTC_ISR_TSF) 447 #define RTC_FLAG_WUTF ((uint32_t)RTC_ISR_WUTF) 448 #define RTC_FLAG_ALRBF ((uint32_t)RTC_ISR_ALRBF) 449 #define RTC_FLAG_ALRAF ((uint32_t)RTC_ISR_ALRAF) 450 #define RTC_FLAG_INITF ((uint32_t)RTC_ISR_INITF) 451 #define RTC_FLAG_RSF ((uint32_t)RTC_ISR_RSF) 452 #define RTC_FLAG_INITS ((uint32_t)RTC_ISR_INITS) 453 #define RTC_FLAG_SHPF ((uint32_t)RTC_ISR_SHPF) 454 #define RTC_FLAG_WUTWF ((uint32_t)RTC_ISR_WUTWF) 455 #define RTC_FLAG_ALRBWF ((uint32_t)RTC_ISR_ALRBWF) 456 #define RTC_FLAG_ALRAWF ((uint32_t)RTC_ISR_ALRAWF) 457 /** 458 * @} 459 */ 460 461 /** 462 * @} 463 */ 464 465 /* Exported macros -----------------------------------------------------------*/ 466 /** @defgroup RTC_Exported_Macros RTC Exported Macros 467 * @{ 468 */ 469 470 /** @brief Reset RTC handle state 471 * @param __HANDLE__: RTC handle. 472 * @retval None 473 */ 474 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 475 476 /** 477 * @brief Disable the write protection for RTC registers. 478 * @param __HANDLE__: specifies the RTC handle. 479 * @retval None 480 */ 481 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ 482 do{ \ 483 (__HANDLE__)->Instance->WPR = 0xCAU; \ 484 (__HANDLE__)->Instance->WPR = 0x53U; \ 485 } while(0U) 486 487 /** 488 * @brief Enable the write protection for RTC registers. 489 * @param __HANDLE__: specifies the RTC handle. 490 * @retval None 491 */ 492 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ 493 do{ \ 494 (__HANDLE__)->Instance->WPR = 0xFFU; \ 495 } while(0U) 496 497 /** 498 * @brief Enable the RTC ALARMA peripheral. 499 * @param __HANDLE__: specifies the RTC handle. 500 * @retval None 501 */ 502 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) 503 504 /** 505 * @brief Disable the RTC ALARMA peripheral. 506 * @param __HANDLE__: specifies the RTC handle. 507 * @retval None 508 */ 509 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) 510 511 /** 512 * @brief Enable the RTC ALARMB peripheral. 513 * @param __HANDLE__: specifies the RTC handle. 514 * @retval None 515 */ 516 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE)) 517 518 /** 519 * @brief Disable the RTC ALARMB peripheral. 520 * @param __HANDLE__: specifies the RTC handle. 521 * @retval None 522 */ 523 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE)) 524 525 /** 526 * @brief Enable the RTC Alarm interrupt. 527 * @param __HANDLE__: specifies the RTC handle. 528 * @param __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. 529 * This parameter can be any combination of the following values: 530 * @arg RTC_IT_ALRA: Alarm A interrupt 531 * @arg RTC_IT_ALRB: Alarm B interrupt 532 * @retval None 533 */ 534 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 535 536 /** 537 * @brief Disable the RTC Alarm interrupt. 538 * @param __HANDLE__: specifies the RTC handle. 539 * @param __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. 540 * This parameter can be any combination of the following values: 541 * @arg RTC_IT_ALRA: Alarm A interrupt 542 * @arg RTC_IT_ALRB: Alarm B interrupt 543 * @retval None 544 */ 545 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 546 547 /** 548 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 549 * @param __HANDLE__: specifies the RTC handle. 550 * @param __INTERRUPT__: specifies the RTC Alarm interrupt sources to check. 551 * This parameter can be: 552 * @arg RTC_IT_ALRA: Alarm A interrupt 553 * @arg RTC_IT_ALRB: Alarm B interrupt 554 * @retval None 555 */ 556 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET) 557 558 /** 559 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 560 * @param __HANDLE__: specifies the RTC handle. 561 * @param __INTERRUPT__: specifies the RTC Alarm interrupt sources to check. 562 * This parameter can be: 563 * @arg RTC_IT_ALRA: Alarm A interrupt 564 * @arg RTC_IT_ALRB: Alarm B interrupt 565 * @retval None 566 */ 567 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET) 568 569 /** 570 * @brief Get the selected RTC Alarm's flag status. 571 * @param __HANDLE__: specifies the RTC handle. 572 * @param __FLAG__: specifies the RTC Alarm Flag sources to check. 573 * This parameter can be: 574 * @arg RTC_FLAG_ALRAF 575 * @arg RTC_FLAG_ALRBF 576 * @arg RTC_FLAG_ALRAWF 577 * @arg RTC_FLAG_ALRBWF 578 * @retval None 579 */ 580 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET) 581 582 /** 583 * @brief Clear the RTC Alarm's pending flags. 584 * @param __HANDLE__: specifies the RTC handle. 585 * @param __FLAG__: specifies the RTC Alarm Flag sources to clear. 586 * This parameter can be: 587 * @arg RTC_FLAG_ALRAF 588 * @arg RTC_FLAG_ALRBF 589 * @retval None 590 */ 591 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT) | ((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 592 593 /** 594 * @brief Enable interrupt on the RTC Alarm associated Exti line. 595 * @retval None 596 */ 597 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT) 598 599 /** 600 * @brief Disable interrupt on the RTC Alarm associated Exti line. 601 * @retval None 602 */ 603 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 604 605 /** 606 * @brief Enable event on the RTC Alarm associated Exti line. 607 * @retval None. 608 */ 609 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT) 610 611 /** 612 * @brief Disable event on the RTC Alarm associated Exti line. 613 * @retval None. 614 */ 615 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 616 617 /** 618 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line. 619 * @retval None. 620 */ 621 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT) 622 623 /** 624 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line. 625 * @retval None. 626 */ 627 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 628 629 /** 630 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line. 631 * @retval None. 632 */ 633 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT) 634 635 /** 636 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line. 637 * @retval None. 638 */ 639 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 640 641 /** 642 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. 643 * @retval None. 644 */ 645 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 646 __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \ 647 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \ 648 } while(0U) 649 650 /** 651 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. 652 * @retval None. 653 */ 654 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 655 __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \ 656 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \ 657 } while(0U) 658 659 /** 660 * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not. 661 * @retval Line Status. 662 */ 663 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT) 664 665 /** 666 * @brief Clear the RTC Alarm associated Exti line flag. 667 * @retval None. 668 */ 669 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT) 670 671 /** 672 * @brief Generate a Software interrupt on RTC Alarm associated Exti line. 673 * @retval None. 674 */ 675 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT) 676 677 /** 678 * @} 679 */ 680 681 /* Include RTC HAL Extended module */ 682 #include "stm32l0xx_hal_rtc_ex.h" 683 684 /* Exported functions --------------------------------------------------------*/ 685 /** @defgroup RTC_Exported_Functions RTC Exported Functions 686 * @{ 687 */ 688 689 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions 690 * @{ 691 */ 692 /* Initialization and de-initialization functions ****************************/ 693 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); 694 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 695 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 696 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 697 /** 698 * @} 699 */ 700 701 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions 702 * @{ 703 */ 704 /* RTC Time and Date functions ************************************************/ 705 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 706 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 707 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 708 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 709 /** 710 * @} 711 */ 712 713 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions 714 * @{ 715 */ 716 /* RTC Alarm functions ********************************************************/ 717 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 718 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 719 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); 720 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); 721 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 722 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 723 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 724 /** 725 * @} 726 */ 727 728 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions 729 * @{ 730 */ 731 /* Peripheral Control functions ***********************************************/ 732 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc); 733 /** 734 * @} 735 */ 736 737 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions 738 * @{ 739 */ 740 /* Peripheral State functions *************************************************/ 741 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); 742 /** 743 * @} 744 */ 745 746 /** 747 * @} 748 */ 749 750 /* Private types -------------------------------------------------------------*/ 751 /* Private variables ---------------------------------------------------------*/ 752 /* Private constants ---------------------------------------------------------*/ 753 /** @defgroup RTC_Private_Constants RTC Private Constants 754 * @{ 755 */ 756 /* Masks Definition */ 757 #define RTC_TR_RESERVED_MASK ((uint32_t) (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \ 758 RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \ 759 RTC_TR_SU)) 760 #define RTC_DR_RESERVED_MASK ((uint32_t) (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \ 761 RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \ 762 RTC_DR_DU)) 763 #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFFU) 764 #define RTC_RSF_MASK ((uint32_t)~(RTC_ISR_INIT | RTC_ISR_RSF)) 765 766 #define RTC_TIMEOUT_VALUE 1000U 767 768 #define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_IM17) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 769 770 /** 771 * @} 772 */ 773 774 /* Private macros ------------------------------------------------------------*/ 775 /** @defgroup RTC_Private_Macros RTC Private Macros 776 * @{ 777 */ 778 779 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 780 * @{ 781 */ 782 783 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 784 ((FORMAT) == RTC_HOURFORMAT_24)) 785 786 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 787 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 788 789 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ 790 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) 791 792 #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \ 793 ((REMAP) == RTC_OUTPUT_REMAP_POS1)) 794 795 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \ 796 ((PM) == RTC_HOURFORMAT12_PM)) 797 798 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 799 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 800 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 801 802 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 803 ((OPERATION) == RTC_STOREOPERATION_SET)) 804 805 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD)) 806 807 #define IS_RTC_YEAR(YEAR) ((YEAR) <= (uint32_t)99U) 808 809 #define IS_RTC_MONTH(MONTH) (((MONTH) >= (uint32_t)1U) && ((MONTH) <= (uint32_t)12U)) 810 811 #define IS_RTC_DATE(DATE) (((DATE) >= (uint32_t)1U) && ((DATE) <= (uint32_t)31U)) 812 813 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 814 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 815 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 816 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 817 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 818 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 819 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 820 821 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >(uint32_t)0U) && ((DATE) <= (uint32_t)31U)) 822 823 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 824 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 825 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 826 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 827 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 828 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 829 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 830 831 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 832 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 833 834 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == (uint32_t)RESET) 835 836 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B)) 837 838 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS) 839 840 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \ 841 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \ 842 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \ 843 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \ 844 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \ 845 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \ 846 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \ 847 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \ 848 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \ 849 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \ 850 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \ 851 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \ 852 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \ 853 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \ 854 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \ 855 ((MASK) == RTC_ALARMSUBSECONDMASK_NONE)) 856 857 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= (uint32_t)0x7FU) 858 859 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= (uint32_t)0x7FFFU) 860 861 #define IS_RTC_HOUR12(HOUR) (((HOUR) > (uint32_t)0U) && ((HOUR) <= (uint32_t)12U)) 862 863 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= (uint32_t)23U) 864 865 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= (uint32_t)59U) 866 867 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= (uint32_t)59U) 868 869 /** 870 * @} 871 */ 872 873 /** 874 * @} 875 */ 876 877 /* Private functions -------------------------------------------------------------*/ 878 /** @defgroup RTC_Private_Functions RTC Private Functions 879 * @{ 880 */ 881 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc); 882 uint8_t RTC_ByteToBcd2(uint8_t Value); 883 uint8_t RTC_Bcd2ToByte(uint8_t Value); 884 /** 885 * @} 886 */ 887 888 889 /** 890 * @} 891 */ 892 893 /** 894 * @} 895 */ 896 897 #ifdef __cplusplus 898 } 899 #endif 900 901 #endif /* __STM32L0xx_HAL_RTC_H */ 902 903 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 904 905