```html
|
STM32G474xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_hal_rtc_ex.c 00004 * @author MCD Application Team 00005 * @brief Extended RTC HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Real Time Clock (RTC) Extended peripheral: 00008 * + RTC Time Stamp functions 00009 * + RTC Tamper functions 00010 * + RTC Wake-up functions 00011 * + Extended Control functions 00012 * + Extended RTC features functions 00013 * 00014 ****************************************************************************** 00015 * @attention 00016 * 00017 * Copyright (c) 2019 STMicroelectronics. 00018 * All rights reserved. 00019 * 00020 * This software is licensed under terms that can be found in the LICENSE file 00021 * in the root directory of this software component. 00022 * If no LICENSE file comes with this software, it is provided AS-IS. 00023 * 00024 ****************************************************************************** 00025 @verbatim 00026 ============================================================================== 00027 ##### How to use this driver ##### 00028 ============================================================================== 00029 [..] 00030 (+) Enable the RTC domain access. 00031 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour 00032 format using the HAL_RTC_Init() function. 00033 00034 *** RTC Wakeup configuration *** 00035 ================================ 00036 [..] 00037 (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer() 00038 function. You can also configure the RTC Wakeup timer with interrupt mode 00039 using the HAL_RTCEx_SetWakeUpTimer_IT() function. 00040 (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer() 00041 function. 00042 00043 *** Outputs configuration *** 00044 ============================= 00045 [..] The RTC has 2 different outputs: 00046 (+) RTC_ALARM: this output is used to manage the RTC Alarm A, Alarm B 00047 and WaKeUp signals. 00048 To output the selected RTC signal, use the HAL_RTC_Init() function. 00049 (+) RTC_CALIB: this output is 512Hz signal or 1Hz. 00050 To enable the RTC_CALIB, use the HAL_RTCEx_SetCalibrationOutPut() function. 00051 (+) Two pins can be used as RTC_ALARM or RTC_CALIB (PC13, PB2) managed on 00052 the RTC_OR register. 00053 (+) When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is 00054 automatically configured in output alternate function. 00055 00056 *** Smooth digital Calibration configuration *** 00057 ================================================ 00058 [..] 00059 (+) Configure the RTC Original Digital Calibration Value and the corresponding 00060 calibration cycle period (32s,16s and 8s) using the HAL_RTCEx_SetSmoothCalib() 00061 function. 00062 00063 *** TimeStamp configuration *** 00064 =============================== 00065 [..] 00066 (+) Enable the RTC TimeStamp using the HAL_RTCEx_SetTimeStamp() function. 00067 You can also configure the RTC TimeStamp with interrupt mode using the 00068 HAL_RTCEx_SetTimeStamp_IT() function. 00069 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() 00070 function. 00071 00072 *** Internal TimeStamp configuration *** 00073 =============================== 00074 [..] 00075 (+) Enable the RTC internal TimeStamp using the HAL_RTCEx_SetInternalTimeStamp() function. 00076 User has to check internal timestamp occurrence using __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG. 00077 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() 00078 function. 00079 00080 *** Tamper configuration *** 00081 ============================ 00082 [..] 00083 (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge 00084 or Level according to the Tamper filter (if equal to 0 Edge else Level) 00085 value, sampling frequency, NoErase, MaskFlag, precharge or discharge and 00086 Pull-UP using the HAL_RTCEx_SetTamper() function. You can configure RTC Tamper 00087 with interrupt mode using HAL_RTCEx_SetTamper_IT() function. 00088 (+) The default configuration of the Tamper erases the backup registers. To avoid 00089 erase, enable the NoErase field on the RTC_TAMPCR register. 00090 (+) If you do not intend to have tamper using RTC clock, you can bypass its initialization 00091 by setting ClockEnable init field to RTC_CLOCK_DISABLE. 00092 (+) Enable Internal tamper using HAL_RTCEx_SetInternalTamper. IT mode can be chosen using 00093 setting Interrupt field. 00094 00095 *** Backup Data Registers configuration *** 00096 =========================================== 00097 [..] 00098 (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite() 00099 function. 00100 (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead() 00101 function. 00102 00103 @endverbatim 00104 ****************************************************************************** 00105 */ 00106 00107 /* Includes ------------------------------------------------------------------*/ 00108 #include "stm32g4xx_hal.h" 00109 00110 /** @addtogroup STM32G4xx_HAL_Driver 00111 * @{ 00112 */ 00113 00114 /** @addtogroup RTCEx 00115 * @brief RTC Extended HAL module driver 00116 * @{ 00117 */ 00118 00119 #ifdef HAL_RTC_MODULE_ENABLED 00120 00121 /* Private typedef -----------------------------------------------------------*/ 00121 /* Private define ------------------------------------------------------------*/ 00122 00123 /* Private macro -------------------------------------------------------------*/ 00124 /* Private variables ---------------------------------------------------------*/ 00125 /* Private function prototypes -----------------------------------------------*/ 00126 /* Exported functions --------------------------------------------------------*/ 00127 00128 /** @addtogroup RTCEx_Exported_Functions 00129 * @{ 00130 */ 00131 00132 /** @addtogroup RTCEx_Exported_Functions_Group1 00133 * @brief RTC TimeStamp and Tamper functions 00134 * 00135 @verbatim 00136 =============================================================================== 00137 ##### RTC TimeStamp and Tamper functions ##### 00138 =============================================================================== 00139 00140 [..] This section provides functions allowing to configure TimeStamp feature 00141 00142 @endverbatim 00143 * @{ 00144 */ 00145 00146 /** 00147 * @brief Set TimeStamp. 00148 * @note This API must be called before enabling the TimeStamp feature. 00149 * @param hrtc RTC handle 00150 * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is 00151 * activated. 00152 * This parameter can be one of the following values: 00153 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the 00154 * rising edge of the related pin. 00155 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the 00156 * falling edge of the related pin. 00157 * @param RTC_TimeStampPin specifies the RTC TimeStamp Pin. 00158 * This parameter can be one of the following values: 00159 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. 00160 * The RTC TimeStamp Pin is per default PC13, but for reasons of 00161 * compatibility, this parameter is required. 00162 * @retval HAL status 00163 */ 00164 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) 00165 { 00166 /* Check the parameters */ 00167 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); 00168 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); 00169 UNUSED(RTC_TimeStampPin); 00170 00171 /* Process Locked */ 00172 __HAL_LOCK(hrtc); 00173 00174 hrtc->State = HAL_RTC_STATE_BUSY; 00175 00176 /* Get the RTC_CR register and clear the bits to be configured */ 00177 CLEAR_BIT(hrtc->Instance->CR, (RTC_CR_TSEDGE | RTC_CR_TSE)); 00178 00179 /* Disable the write protection for RTC registers */ 00180 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00181 00182 /* Configure the Time Stamp TSEDGE and Enable bits */ 00183 SET_BIT(hrtc->Instance->CR, (uint32_t)TimeStampEdge | RTC_CR_TSE); 00184 00185 /* Enable the write protection for RTC registers */ 00186 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00187 00188 /* Change RTC state */ 00189 hrtc->State = HAL_RTC_STATE_READY; 00190 00191 /* Process Unlocked */ 00192 __HAL_UNLOCK(hrtc); 00193 00194 return HAL_OK; 00195 } 00196 00197 /** 00198 * @brief Set TimeStamp with Interrupt. 00199 * @note This API must be called before enabling the TimeStamp feature. 00200 * @param hrtc RTC handle 00201 * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is 00202 * activated. 00203 * This parameter can be one of the following values: 00204 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the 00205 * rising edge of the related pin. 00206 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the 00207 * falling edge of the related pin. 00208 * @param RTC_TimeStampPin Specifies the RTC TimeStamp Pin. 00209 * This parameter can be one of the following values: 00210 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. 00211 * The RTC TimeStamp Pin is per default PC13, but for reasons of 00212 * compatibility, this parameter is required. 00213 * @retval HAL status 00214 */ 00215 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) 00216 {