38
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file stm32f4xx_hal_rtc_ex.c
|
|
4 * @author MCD Application Team
|
|
5 * @version V1.2.0
|
|
6 * @date 26-December-2014
|
|
7 * @brief RTC HAL module driver.
|
|
8 * This file provides firmware functions to manage the following
|
|
9 * functionalities of the Real Time Clock (RTC) Extension peripheral:
|
|
10 * + RTC Time Stamp functions
|
|
11 * + RTC Tamper functions
|
|
12 * + RTC Wake-up functions
|
|
13 * + Extension Control functions
|
|
14 * + Extension RTC features functions
|
|
15 *
|
|
16 @verbatim
|
|
17 ==============================================================================
|
|
18 ##### How to use this driver #####
|
|
19 ==============================================================================
|
|
20 [..]
|
|
21 (+) Enable the RTC domain access.
|
|
22 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
|
|
23 format using the HAL_RTC_Init() function.
|
|
24
|
|
25 *** RTC Wake-up configuration ***
|
|
26 ================================
|
|
27 [..]
|
|
28 (+) To configure the RTC Wake-up Clock source and Counter use the HAL_RTC_SetWakeUpTimer()
|
|
29 function. You can also configure the RTC Wake-up timer in interrupt mode
|
|
30 using the HAL_RTC_SetWakeUpTimer_IT() function.
|
|
31 (+) To read the RTC Wake-up Counter register, use the HAL_RTC_GetWakeUpTimer()
|
|
32 function.
|
|
33
|
|
34 *** TimeStamp configuration ***
|
|
35 ===============================
|
|
36 [..]
|
|
37 (+) Configure the RTC_AFx trigger and enable the RTC TimeStamp using the
|
|
38 HAL_RTC_SetTimeStamp() function. You can also configure the RTC TimeStamp with
|
|
39 interrupt mode using the HAL_RTC_SetTimeStamp_IT() function.
|
|
40 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTC_GetTimeStamp()
|
|
41 function.
|
|
42 (+) The TIMESTAMP alternate function can be mapped either to RTC_AF1 (PC13)
|
|
43 or RTC_AF2 (PI8) depending on the value of TSINSEL bit in
|
|
44 RTC_TAFCR register. The corresponding pin is also selected by HAL_RTC_SetTimeStamp()
|
|
45 or HAL_RTC_SetTimeStamp_IT() function.
|
|
46
|
|
47 *** Tamper configuration ***
|
|
48 ============================
|
|
49 [..]
|
|
50 (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge
|
|
51 or Level according to the Tamper filter (if equal to 0 Edge else Level)
|
|
52 value, sampling frequency, precharge or discharge and Pull-UP using the
|
|
53 HAL_RTC_SetTamper() function. You can configure RTC Tamper in interrupt
|
|
54 mode using HAL_RTC_SetTamper_IT() function.
|
|
55 (+) The TAMPER1 alternate function can be mapped either to RTC_AF1 (PC13)
|
|
56 or RTC_AF2 (PI8) depending on the value of TAMP1INSEL bit in
|
|
57 RTC_TAFCR register. The corresponding pin is also selected by HAL_RTC_SetTamper()
|
|
58 or HAL_RTC_SetTamper_IT() function.
|
|
59
|
|
60 *** Backup Data Registers configuration ***
|
|
61 ===========================================
|
|
62 [..]
|
|
63 (+) To write to the RTC Backup Data registers, use the HAL_RTC_BKUPWrite()
|
|
64 function.
|
|
65 (+) To read the RTC Backup Data registers, use the HAL_RTC_BKUPRead()
|
|
66 function.
|
|
67
|
|
68 @endverbatim
|
|
69 ******************************************************************************
|
|
70 * @attention
|
|
71 *
|
|
72 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
|
|
73 *
|
|
74 * Redistribution and use in source and binary forms, with or without modification,
|
|
75 * are permitted provided that the following conditions are met:
|
|
76 * 1. Redistributions of source code must retain the above copyright notice,
|
|
77 * this list of conditions and the following disclaimer.
|
|
78 * 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
79 * this list of conditions and the following disclaimer in the documentation
|
|
80 * and/or other materials provided with the distribution.
|
|
81 * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
82 * may be used to endorse or promote products derived from this software
|
|
83 * without specific prior written permission.
|
|
84 *
|
|
85 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
86 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
88 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
89 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
90 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
91 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
92 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
93 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
94 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
95 *
|
|
96 ******************************************************************************
|
|
97 */
|
|
98
|
|
99 /* Includes ------------------------------------------------------------------*/
|
|
100 #include "stm32f4xx_hal.h"
|
|
101
|
|
102 /** @addtogroup STM32F4xx_HAL_Driver
|
|
103 * @{
|
|
104 */
|
|
105
|
|
106 /** @defgroup RTCEx RTCEx
|
|
107 * @brief RTC HAL module driver
|
|
108 * @{
|
|
109 */
|
|
110
|
|
111 #ifdef HAL_RTC_MODULE_ENABLED
|
|
112
|
|
113 /* Private typedef -----------------------------------------------------------*/
|
|
114 /* Private define ------------------------------------------------------------*/
|
|
115 /* Private macro -------------------------------------------------------------*/
|
|
116 /* Private variables ---------------------------------------------------------*/
|
|
117 /* Private function prototypes -----------------------------------------------*/
|
|
118 /* Private functions ---------------------------------------------------------*/
|
|
119
|
|
120 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
|
|
121 * @{
|
|
122 */
|
|
123
|
|
124 /** @defgroup RTCEx_Exported_Functions_Group1 RTC TimeStamp and Tamper functions
|
|
125 * @brief RTC TimeStamp and Tamper functions
|
|
126 *
|
|
127 @verbatim
|
|
128 ===============================================================================
|
|
129 ##### RTC TimeStamp and Tamper functions #####
|
|
130 ===============================================================================
|
|
131
|
|
132 [..] This section provides functions allowing to configure TimeStamp feature
|
|
133
|
|
134 @endverbatim
|
|
135 * @{
|
|
136 */
|
|
137
|
|
138 /**
|
|
139 * @brief Sets TimeStamp.
|
|
140 * @note This API must be called before enabling the TimeStamp feature.
|
|
141 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
142 * the configuration information for RTC.
|
|
143 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
|
|
144 * activated.
|
|
145 * This parameter can be one of the following values:
|
|
146 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
|
|
147 * rising edge of the related pin.
|
|
148 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
|
|
149 * falling edge of the related pin.
|
|
150 * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin.
|
|
151 * This parameter can be one of the following values:
|
|
152 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
|
|
153 * @arg RTC_TIMESTAMPPIN_PI8: PI8 is selected as RTC TimeStamp Pin.
|
|
154 * @retval HAL status
|
|
155 */
|
|
156 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
|
|
157 {
|
|
158 uint32_t tmpreg = 0;
|
|
159
|
|
160 /* Check the parameters */
|
|
161 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
|
|
162 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
|
|
163
|
|
164 /* Process Locked */
|
|
165 __HAL_LOCK(hrtc);
|
|
166
|
|
167 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
168
|
|
169 /* Get the RTC_CR register and clear the bits to be configured */
|
|
170 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
|
|
171
|
|
172 tmpreg|= TimeStampEdge;
|
|
173
|
|
174 /* Disable the write protection for RTC registers */
|
|
175 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
176
|
|
177 hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL;
|
|
178 hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin);
|
|
179
|
|
180 /* Configure the Time Stamp TSEDGE and Enable bits */
|
|
181 hrtc->Instance->CR = (uint32_t)tmpreg;
|
|
182
|
|
183 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
|
|
184
|
|
185 /* Enable the write protection for RTC registers */
|
|
186 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
187
|
|
188 /* Change RTC state */
|
|
189 hrtc->State = HAL_RTC_STATE_READY;
|
|
190
|
|
191 /* Process Unlocked */
|
|
192 __HAL_UNLOCK(hrtc);
|
|
193
|
|
194 return HAL_OK;
|
|
195 }
|
|
196
|
|
197 /**
|
|
198 * @brief Sets TimeStamp with Interrupt.
|
|
199 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
200 * the configuration information for RTC.
|
|
201 * @note This API must be called before enabling the TimeStamp feature.
|
|
202 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
|
|
203 * activated.
|
|
204 * This parameter can be one of the following values:
|
|
205 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
|
|
206 * rising edge of the related pin.
|
|
207 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
|
|
208 * falling edge of the related pin.
|
|
209 * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin.
|
|
210 * This parameter can be one of the following values:
|
|
211 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
|
|
212 * @arg RTC_TIMESTAMPPIN_PI8: PI8 is selected as RTC TimeStamp Pin.
|
|
213 * @retval HAL status
|
|
214 */
|
|
215 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
|
|
216 {
|
|
217 uint32_t tmpreg = 0;
|
|
218
|
|
219 /* Check the parameters */
|
|
220 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
|
|
221 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
|
|
222
|
|
223 /* Process Locked */
|
|
224 __HAL_LOCK(hrtc);
|
|
225
|
|
226 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
227
|
|
228 /* Get the RTC_CR register and clear the bits to be configured */
|
|
229 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
|
|
230
|
|
231 tmpreg |= TimeStampEdge;
|
|
232
|
|
233 /* Disable the write protection for RTC registers */
|
|
234 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
235
|
|
236 /* Configure the Time Stamp TSEDGE and Enable bits */
|
|
237 hrtc->Instance->CR = (uint32_t)tmpreg;
|
|
238
|
|
239 hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL;
|
|
240 hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin);
|
|
241
|
|
242 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
|
|
243
|
|
244 /* Enable IT timestamp */
|
|
245 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS);
|
|
246
|
|
247 /* RTC timestamp Interrupt Configuration: EXTI configuration */
|
|
248 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
|
|
249
|
|
250 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
|
|
251
|
|
252 /* Enable the write protection for RTC registers */
|
|
253 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
254
|
|
255 hrtc->State = HAL_RTC_STATE_READY;
|
|
256
|
|
257 /* Process Unlocked */
|
|
258 __HAL_UNLOCK(hrtc);
|
|
259
|
|
260 return HAL_OK;
|
|
261 }
|
|
262
|
|
263 /**
|
|
264 * @brief Deactivates TimeStamp.
|
|
265 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
266 * the configuration information for RTC.
|
|
267 * @retval HAL status
|
|
268 */
|
|
269 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
|
|
270 {
|
|
271 uint32_t tmpreg = 0;
|
|
272
|
|
273 /* Process Locked */
|
|
274 __HAL_LOCK(hrtc);
|
|
275
|
|
276 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
277
|
|
278 /* Disable the write protection for RTC registers */
|
|
279 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
280
|
|
281 /* In case of interrupt mode is used, the interrupt source must disabled */
|
|
282 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS);
|
|
283
|
|
284 /* Get the RTC_CR register and clear the bits to be configured */
|
|
285 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
|
|
286
|
|
287 /* Configure the Time Stamp TSEDGE and Enable bits */
|
|
288 hrtc->Instance->CR = (uint32_t)tmpreg;
|
|
289
|
|
290 /* Enable the write protection for RTC registers */
|
|
291 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
292
|
|
293 hrtc->State = HAL_RTC_STATE_READY;
|
|
294
|
|
295 /* Process Unlocked */
|
|
296 __HAL_UNLOCK(hrtc);
|
|
297
|
|
298 return HAL_OK;
|
|
299 }
|
|
300
|
|
301 /**
|
|
302 * @brief Gets the RTC TimeStamp value.
|
|
303 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
304 * the configuration information for RTC.
|
|
305 * @param sTimeStamp: Pointer to Time structure
|
|
306 * @param sTimeStampDate: Pointer to Date structure
|
|
307 * @param Format: specifies the format of the entered parameters.
|
|
308 * This parameter can be one of the following values:
|
|
309 * RTC_FORMAT_BIN: Binary data format
|
|
310 * RTC_FORMAT_BCD: BCD data format
|
|
311 * @retval HAL status
|
|
312 */
|
|
313 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format)
|
|
314 {
|
|
315 uint32_t tmptime = 0, tmpdate = 0;
|
|
316
|
|
317 /* Check the parameters */
|
|
318 assert_param(IS_RTC_FORMAT(Format));
|
|
319
|
|
320 /* Get the TimeStamp time and date registers values */
|
|
321 tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
|
|
322 tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
|
|
323
|
|
324 /* Fill the Time structure fields with the read parameters */
|
|
325 sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
|
|
326 sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
|
|
327 sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
|
|
328 sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
|
|
329 sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR;
|
|
330
|
|
331 /* Fill the Date structure fields with the read parameters */
|
|
332 sTimeStampDate->Year = 0;
|
|
333 sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
|
|
334 sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
|
|
335 sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
|
|
336
|
|
337 /* Check the input parameters format */
|
|
338 if(Format == RTC_FORMAT_BIN)
|
|
339 {
|
|
340 /* Convert the TimeStamp structure parameters to Binary format */
|
|
341 sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
|
|
342 sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
|
|
343 sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
|
|
344
|
|
345 /* Convert the DateTimeStamp structure parameters to Binary format */
|
|
346 sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
|
|
347 sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
|
|
348 sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
|
|
349 }
|
|
350
|
|
351 /* Clear the TIMESTAMP Flag */
|
|
352 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
|
|
353
|
|
354 return HAL_OK;
|
|
355 }
|
|
356
|
|
357 /**
|
|
358 * @brief Sets Tamper
|
|
359 * @note By calling this API we disable the tamper interrupt for all tampers.
|
|
360 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
361 * the configuration information for RTC.
|
|
362 * @param sTamper: Pointer to Tamper Structure.
|
|
363 * @retval HAL status
|
|
364 */
|
|
365 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
|
|
366 {
|
|
367 uint32_t tmpreg = 0;
|
|
368
|
|
369 /* Check the parameters */
|
|
370 assert_param(IS_RTC_TAMPER(sTamper->Tamper));
|
|
371 assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection));
|
|
372 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
|
|
373 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
|
|
374 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
|
|
375 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
|
|
376 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
|
|
377 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
|
|
378
|
|
379 /* Process Locked */
|
|
380 __HAL_LOCK(hrtc);
|
|
381
|
|
382 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
383
|
|
384 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
|
|
385 {
|
|
386 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
|
|
387 }
|
|
388
|
|
389 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)sTamper->Trigger |\
|
|
390 (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
|
|
391 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
|
|
392
|
|
393 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
|
|
394 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
|
|
395 (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPINSEL | (uint32_t)RTC_TAFCR_TAMPIE);
|
|
396
|
|
397 hrtc->Instance->TAFCR |= tmpreg;
|
|
398
|
|
399 hrtc->State = HAL_RTC_STATE_READY;
|
|
400
|
|
401 /* Process Unlocked */
|
|
402 __HAL_UNLOCK(hrtc);
|
|
403
|
|
404 return HAL_OK;
|
|
405 }
|
|
406
|
|
407 /**
|
|
408 * @brief Sets Tamper with interrupt.
|
|
409 * @note By calling this API we force the tamper interrupt for all tampers.
|
|
410 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
411 * the configuration information for RTC.
|
|
412 * @param sTamper: Pointer to RTC Tamper.
|
|
413 * @retval HAL status
|
|
414 */
|
|
415 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
|
|
416 {
|
|
417 uint32_t tmpreg = 0;
|
|
418
|
|
419 /* Check the parameters */
|
|
420 assert_param(IS_RTC_TAMPER(sTamper->Tamper));
|
|
421 assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection));
|
|
422 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
|
|
423 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
|
|
424 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
|
|
425 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
|
|
426 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
|
|
427 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
|
|
428
|
|
429 /* Process Locked */
|
|
430 __HAL_LOCK(hrtc);
|
|
431
|
|
432 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
433
|
|
434 /* Configure the tamper trigger */
|
|
435 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
|
|
436 {
|
|
437 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
|
|
438 }
|
|
439
|
|
440 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)sTamper->Trigger |\
|
|
441 (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
|
|
442 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
|
|
443
|
|
444 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
|
|
445 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
|
|
446 (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPINSEL);
|
|
447
|
|
448 hrtc->Instance->TAFCR |= tmpreg;
|
|
449
|
|
450 /* Configure the Tamper Interrupt in the RTC_TAFCR */
|
|
451 hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE;
|
|
452
|
|
453 /* RTC Tamper Interrupt Configuration: EXTI configuration */
|
|
454 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
|
|
455
|
|
456 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
|
|
457
|
|
458 hrtc->State = HAL_RTC_STATE_READY;
|
|
459
|
|
460 /* Process Unlocked */
|
|
461 __HAL_UNLOCK(hrtc);
|
|
462
|
|
463 return HAL_OK;
|
|
464 }
|
|
465
|
|
466 /**
|
|
467 * @brief Deactivates Tamper.
|
|
468 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
469 * the configuration information for RTC.
|
|
470 * @param Tamper: Selected tamper pin.
|
|
471 * This parameter can be RTC_Tamper_1 and/or RTC_TAMPER_2.
|
|
472 * @retval HAL status
|
|
473 */
|
|
474 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
|
|
475 {
|
|
476 assert_param(IS_RTC_TAMPER(Tamper));
|
|
477
|
|
478 /* Process Locked */
|
|
479 __HAL_LOCK(hrtc);
|
|
480
|
|
481 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
482
|
|
483 /* Disable the selected Tamper pin */
|
|
484 hrtc->Instance->TAFCR &= (uint32_t)~Tamper;
|
|
485
|
|
486 hrtc->State = HAL_RTC_STATE_READY;
|
|
487
|
|
488 /* Process Unlocked */
|
|
489 __HAL_UNLOCK(hrtc);
|
|
490
|
|
491 return HAL_OK;
|
|
492 }
|
|
493
|
|
494 /**
|
|
495 * @brief This function handles TimeStamp interrupt request.
|
|
496 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
497 * the configuration information for RTC.
|
|
498 * @retval None
|
|
499 */
|
|
500 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
|
|
501 {
|
|
502 if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS))
|
|
503 {
|
|
504 /* Get the status of the Interrupt */
|
|
505 if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET)
|
|
506 {
|
|
507 /* TIMESTAMP callback */
|
|
508 HAL_RTCEx_TimeStampEventCallback(hrtc);
|
|
509
|
|
510 /* Clear the TIMESTAMP interrupt pending bit */
|
|
511 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF);
|
|
512 }
|
|
513 }
|
|
514
|
|
515 /* Get the status of the Interrupt */
|
|
516 if(__HAL_RTC_TAMPER_GET_IT(hrtc,RTC_IT_TAMP1))
|
|
517 {
|
|
518 /* Get the TAMPER Interrupt enable bit and pending bit */
|
|
519 if(((hrtc->Instance->TAFCR & (RTC_TAFCR_TAMPIE))) != (uint32_t)RESET)
|
|
520 {
|
|
521 /* Tamper callback */
|
|
522 HAL_RTCEx_Tamper1EventCallback(hrtc);
|
|
523
|
|
524 /* Clear the Tamper interrupt pending bit */
|
|
525 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
|
|
526 }
|
|
527 }
|
|
528
|
|
529 /* Get the status of the Interrupt */
|
|
530 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP2))
|
|
531 {
|
|
532 /* Get the TAMPER Interrupt enable bit and pending bit */
|
|
533 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
|
|
534 {
|
|
535 /* Tamper callback */
|
|
536 HAL_RTCEx_Tamper2EventCallback(hrtc);
|
|
537
|
|
538 /* Clear the Tamper interrupt pending bit */
|
|
539 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
|
|
540 }
|
|
541 }
|
|
542 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
|
|
543 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
|
|
544
|
|
545 /* Change RTC state */
|
|
546 hrtc->State = HAL_RTC_STATE_READY;
|
|
547 }
|
|
548
|
|
549 /**
|
|
550 * @brief TimeStamp callback.
|
|
551 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
552 * the configuration information for RTC.
|
|
553 * @retval None
|
|
554 */
|
|
555 __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
|
|
556 {
|
|
557 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
558 the HAL_RTC_TimeStampEventCallback could be implemented in the user file
|
|
559 */
|
|
560 }
|
|
561
|
|
562 /**
|
|
563 * @brief Tamper 1 callback.
|
|
564 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
565 * the configuration information for RTC.
|
|
566 * @retval None
|
|
567 */
|
|
568 __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
|
|
569 {
|
|
570 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
571 the HAL_RTC_Tamper1EventCallback could be implemented in the user file
|
|
572 */
|
|
573 }
|
|
574
|
|
575 /**
|
|
576 * @brief Tamper 2 callback.
|
|
577 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
578 * the configuration information for RTC.
|
|
579 * @retval None
|
|
580 */
|
|
581 __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
|
|
582 {
|
|
583 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
584 the HAL_RTC_Tamper2EventCallback could be implemented in the user file
|
|
585 */
|
|
586 }
|
|
587
|
|
588 /**
|
|
589 * @brief This function handles TimeStamp polling request.
|
|
590 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
591 * the configuration information for RTC.
|
|
592 * @param Timeout: Timeout duration
|
|
593 * @retval HAL status
|
|
594 */
|
|
595 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
|
|
596 {
|
|
597 uint32_t tickstart = 0;
|
|
598
|
|
599 /* Get tick */
|
|
600 tickstart = HAL_GetTick();
|
|
601
|
|
602 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET)
|
|
603 {
|
|
604 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET)
|
|
605 {
|
|
606 /* Clear the TIMESTAMP Overrun Flag */
|
|
607 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
|
|
608
|
|
609 /* Change TIMESTAMP state */
|
|
610 hrtc->State = HAL_RTC_STATE_ERROR;
|
|
611
|
|
612 return HAL_ERROR;
|
|
613 }
|
|
614
|
|
615 if(Timeout != HAL_MAX_DELAY)
|
|
616 {
|
|
617 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
618 {
|
|
619 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
620 return HAL_TIMEOUT;
|
|
621 }
|
|
622 }
|
|
623 }
|
|
624
|
|
625 /* Change RTC state */
|
|
626 hrtc->State = HAL_RTC_STATE_READY;
|
|
627
|
|
628 return HAL_OK;
|
|
629 }
|
|
630
|
|
631 /**
|
|
632 * @brief This function handles Tamper1 Polling.
|
|
633 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
634 * the configuration information for RTC.
|
|
635 * @param Timeout: Timeout duration
|
|
636 * @retval HAL status
|
|
637 */
|
|
638 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
|
|
639 {
|
|
640 uint32_t tickstart = 0;
|
|
641
|
|
642 /* Get tick */
|
|
643 tickstart = HAL_GetTick();
|
|
644
|
|
645 /* Get the status of the Interrupt */
|
|
646 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F)== RESET)
|
|
647 {
|
|
648 if(Timeout != HAL_MAX_DELAY)
|
|
649 {
|
|
650 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
651 {
|
|
652 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
653 return HAL_TIMEOUT;
|
|
654 }
|
|
655 }
|
|
656 }
|
|
657
|
|
658 /* Clear the Tamper Flag */
|
|
659 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
|
|
660
|
|
661 /* Change RTC state */
|
|
662 hrtc->State = HAL_RTC_STATE_READY;
|
|
663
|
|
664 return HAL_OK;
|
|
665 }
|
|
666
|
|
667 /**
|
|
668 * @brief This function handles Tamper2 Polling.
|
|
669 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
670 * the configuration information for RTC.
|
|
671 * @param Timeout: Timeout duration
|
|
672 * @retval HAL status
|
|
673 */
|
|
674 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
|
|
675 {
|
|
676 uint32_t tickstart = 0;
|
|
677
|
|
678 /* Get tick */
|
|
679 tickstart = HAL_GetTick();
|
|
680
|
|
681 /* Get the status of the Interrupt */
|
|
682 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == RESET)
|
|
683 {
|
|
684 if(Timeout != HAL_MAX_DELAY)
|
|
685 {
|
|
686 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
687 {
|
|
688 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
689 return HAL_TIMEOUT;
|
|
690 }
|
|
691 }
|
|
692 }
|
|
693
|
|
694 /* Clear the Tamper Flag */
|
|
695 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F);
|
|
696
|
|
697 /* Change RTC state */
|
|
698 hrtc->State = HAL_RTC_STATE_READY;
|
|
699
|
|
700 return HAL_OK;
|
|
701 }
|
|
702
|
|
703 /**
|
|
704 * @}
|
|
705 */
|
|
706
|
|
707 /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wake-up functions
|
|
708 * @brief RTC Wake-up functions
|
|
709 *
|
|
710 @verbatim
|
|
711 ===============================================================================
|
|
712 ##### RTC Wake-up functions #####
|
|
713 ===============================================================================
|
|
714
|
|
715 [..] This section provides functions allowing to configure Wake-up feature
|
|
716
|
|
717 @endverbatim
|
|
718 * @{
|
|
719 */
|
|
720
|
|
721 /**
|
|
722 * @brief Sets wake up timer.
|
|
723 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
724 * the configuration information for RTC.
|
|
725 * @param WakeUpCounter: Wake up counter
|
|
726 * @param WakeUpClock: Wake up clock
|
|
727 * @retval HAL status
|
|
728 */
|
|
729 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
|
|
730 {
|
|
731 uint32_t tickstart = 0;
|
|
732
|
|
733 /* Check the parameters */
|
|
734 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
|
|
735 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
|
|
736
|
|
737 /* Process Locked */
|
|
738 __HAL_LOCK(hrtc);
|
|
739
|
|
740 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
741
|
|
742 /* Disable the write protection for RTC registers */
|
|
743 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
744
|
|
745 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
|
|
746
|
|
747 /* Get tick */
|
|
748 tickstart = HAL_GetTick();
|
|
749
|
|
750 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
|
|
751 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
|
|
752 {
|
|
753 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
|
|
754 {
|
|
755 /* Enable the write protection for RTC registers */
|
|
756 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
757
|
|
758 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
759
|
|
760 /* Process Unlocked */
|
|
761 __HAL_UNLOCK(hrtc);
|
|
762
|
|
763 return HAL_TIMEOUT;
|
|
764 }
|
|
765 }
|
|
766
|
|
767 /* Clear the Wake-up Timer clock source bits in CR register */
|
|
768 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
|
|
769
|
|
770 /* Configure the clock source */
|
|
771 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
|
|
772
|
|
773 /* Configure the Wake-up Timer counter */
|
|
774 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
|
|
775
|
|
776 /* Enable the Wake-up Timer */
|
|
777 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
|
|
778
|
|
779 /* Enable the write protection for RTC registers */
|
|
780 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
781
|
|
782 hrtc->State = HAL_RTC_STATE_READY;
|
|
783
|
|
784 /* Process Unlocked */
|
|
785 __HAL_UNLOCK(hrtc);
|
|
786
|
|
787 return HAL_OK;
|
|
788 }
|
|
789
|
|
790 /**
|
|
791 * @brief Sets wake up timer with interrupt
|
|
792 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
793 * the configuration information for RTC.
|
|
794 * @param WakeUpCounter: Wake up counter
|
|
795 * @param WakeUpClock: Wake up clock
|
|
796 * @retval HAL status
|
|
797 */
|
|
798 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
|
|
799 {
|
|
800 uint32_t tickstart = 0;
|
|
801
|
|
802 /* Check the parameters */
|
|
803 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
|
|
804 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
|
|
805
|
|
806 /* Process Locked */
|
|
807 __HAL_LOCK(hrtc);
|
|
808
|
|
809 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
810
|
|
811 /* Disable the write protection for RTC registers */
|
|
812 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
813
|
|
814 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
|
|
815
|
|
816 /* Get tick */
|
|
817 tickstart = HAL_GetTick();
|
|
818
|
|
819 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
|
|
820 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
|
|
821 {
|
|
822 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
|
|
823 {
|
|
824 /* Enable the write protection for RTC registers */
|
|
825 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
826
|
|
827 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
828
|
|
829 /* Process Unlocked */
|
|
830 __HAL_UNLOCK(hrtc);
|
|
831
|
|
832 return HAL_TIMEOUT;
|
|
833 }
|
|
834 }
|
|
835
|
|
836 /* Configure the Wake-up Timer counter */
|
|
837 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
|
|
838
|
|
839 /* Clear the Wake-up Timer clock source bits in CR register */
|
|
840 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
|
|
841
|
|
842 /* Configure the clock source */
|
|
843 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
|
|
844
|
|
845 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
|
|
846 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
|
|
847
|
|
848 EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
|
|
849
|
|
850 /* Configure the Interrupt in the RTC_CR register */
|
|
851 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
|
|
852
|
|
853 /* Enable the Wake-up Timer */
|
|
854 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
|
|
855
|
|
856 /* Enable the write protection for RTC registers */
|
|
857 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
858
|
|
859 hrtc->State = HAL_RTC_STATE_READY;
|
|
860
|
|
861 /* Process Unlocked */
|
|
862 __HAL_UNLOCK(hrtc);
|
|
863
|
|
864 return HAL_OK;
|
|
865 }
|
|
866
|
|
867 /**
|
|
868 * @brief Deactivates wake up timer counter.
|
|
869 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
870 * the configuration information for RTC.
|
|
871 * @retval HAL status
|
|
872 */
|
|
873 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
|
|
874 {
|
|
875 uint32_t tickstart = 0;
|
|
876
|
|
877 /* Process Locked */
|
|
878 __HAL_LOCK(hrtc);
|
|
879
|
|
880 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
881
|
|
882 /* Disable the write protection for RTC registers */
|
|
883 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
884
|
|
885 /* Disable the Wake-up Timer */
|
|
886 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
|
|
887
|
|
888 /* In case of interrupt mode is used, the interrupt source must disabled */
|
|
889 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT);
|
|
890
|
|
891 /* Get tick */
|
|
892 tickstart = HAL_GetTick();
|
|
893
|
|
894 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
|
|
895 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
|
|
896 {
|
|
897 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
|
|
898 {
|
|
899 /* Enable the write protection for RTC registers */
|
|
900 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
901
|
|
902 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
903
|
|
904 /* Process Unlocked */
|
|
905 __HAL_UNLOCK(hrtc);
|
|
906
|
|
907 return HAL_TIMEOUT;
|
|
908 }
|
|
909 }
|
|
910
|
|
911 /* Enable the write protection for RTC registers */
|
|
912 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
913
|
|
914 hrtc->State = HAL_RTC_STATE_READY;
|
|
915
|
|
916 /* Process Unlocked */
|
|
917 __HAL_UNLOCK(hrtc);
|
|
918
|
|
919 return HAL_OK;
|
|
920 }
|
|
921
|
|
922 /**
|
|
923 * @brief Gets wake up timer counter.
|
|
924 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
925 * the configuration information for RTC.
|
|
926 * @retval Counter value
|
|
927 */
|
|
928 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
|
|
929 {
|
|
930 /* Get the counter value */
|
|
931 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
|
|
932 }
|
|
933
|
|
934 /**
|
|
935 * @brief This function handles Wake Up Timer interrupt request.
|
|
936 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
937 * the configuration information for RTC.
|
|
938 * @retval None
|
|
939 */
|
|
940 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
|
|
941 {
|
|
942 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT))
|
|
943 {
|
|
944 /* Get the status of the Interrupt */
|
|
945 if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET)
|
|
946 {
|
|
947 /* WAKEUPTIMER callback */
|
|
948 HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
|
|
949
|
|
950 /* Clear the WAKEUPTIMER interrupt pending bit */
|
|
951 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
|
|
952 }
|
|
953 }
|
|
954
|
|
955 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
|
|
956 __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
|
|
957
|
|
958 /* Change RTC state */
|
|
959 hrtc->State = HAL_RTC_STATE_READY;
|
|
960 }
|
|
961
|
|
962 /**
|
|
963 * @brief Wake Up Timer callback.
|
|
964 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
965 * the configuration information for RTC.
|
|
966 * @retval None
|
|
967 */
|
|
968 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
|
|
969 {
|
|
970 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
971 the HAL_RTC_WakeUpTimerEventCallback could be implemented in the user file
|
|
972 */
|
|
973 }
|
|
974
|
|
975 /**
|
|
976 * @brief This function handles Wake Up Timer Polling.
|
|
977 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
978 * the configuration information for RTC.
|
|
979 * @param Timeout: Timeout duration
|
|
980 * @retval HAL status
|
|
981 */
|
|
982 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
|
|
983 {
|
|
984 uint32_t tickstart = 0;
|
|
985
|
|
986 /* Get tick */
|
|
987 tickstart = HAL_GetTick();
|
|
988
|
|
989 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET)
|
|
990 {
|
|
991 if(Timeout != HAL_MAX_DELAY)
|
|
992 {
|
|
993 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
994 {
|
|
995 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
996
|
|
997 return HAL_TIMEOUT;
|
|
998 }
|
|
999 }
|
|
1000 }
|
|
1001
|
|
1002 /* Clear the WAKEUPTIMER Flag */
|
|
1003 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
|
|
1004
|
|
1005 /* Change RTC state */
|
|
1006 hrtc->State = HAL_RTC_STATE_READY;
|
|
1007
|
|
1008 return HAL_OK;
|
|
1009 }
|
|
1010
|
|
1011 /**
|
|
1012 * @}
|
|
1013 */
|
|
1014
|
|
1015
|
|
1016 /** @defgroup RTCEx_Exported_Functions_Group3 Extension Peripheral Control functions
|
|
1017 * @brief Extension Peripheral Control functions
|
|
1018 *
|
|
1019 @verbatim
|
|
1020 ===============================================================================
|
|
1021 ##### Extension Peripheral Control functions #####
|
|
1022 ===============================================================================
|
|
1023 [..]
|
|
1024 This subsection provides functions allowing to
|
|
1025 (+) Write a data in a specified RTC Backup data register
|
|
1026 (+) Read a data in a specified RTC Backup data register
|
|
1027 (+) Set the Coarse calibration parameters.
|
|
1028 (+) Deactivate the Coarse calibration parameters
|
|
1029 (+) Set the Smooth calibration parameters.
|
|
1030 (+) Configure the Synchronization Shift Control Settings.
|
|
1031 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
|
|
1032 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
|
|
1033 (+) Enable the RTC reference clock detection.
|
|
1034 (+) Disable the RTC reference clock detection.
|
|
1035 (+) Enable the Bypass Shadow feature.
|
|
1036 (+) Disable the Bypass Shadow feature.
|
|
1037
|
|
1038 @endverbatim
|
|
1039 * @{
|
|
1040 */
|
|
1041
|
|
1042 /**
|
|
1043 * @brief Writes a data in a specified RTC Backup data register.
|
|
1044 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1045 * the configuration information for RTC.
|
|
1046 * @param BackupRegister: RTC Backup data Register number.
|
|
1047 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
|
|
1048 * specify the register.
|
|
1049 * @param Data: Data to be written in the specified RTC Backup data register.
|
|
1050 * @retval None
|
|
1051 */
|
|
1052 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
|
|
1053 {
|
|
1054 uint32_t tmp = 0;
|
|
1055
|
|
1056 /* Check the parameters */
|
|
1057 assert_param(IS_RTC_BKP(BackupRegister));
|
|
1058
|
|
1059 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
|
|
1060 tmp += (BackupRegister * 4);
|
|
1061
|
|
1062 /* Write the specified register */
|
|
1063 *(__IO uint32_t *)tmp = (uint32_t)Data;
|
|
1064 }
|
|
1065
|
|
1066 /**
|
|
1067 * @brief Reads data from the specified RTC Backup data Register.
|
|
1068 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1069 * the configuration information for RTC.
|
|
1070 * @param BackupRegister: RTC Backup data Register number.
|
|
1071 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
|
|
1072 * specify the register.
|
|
1073 * @retval Read value
|
|
1074 */
|
|
1075 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
|
|
1076 {
|
|
1077 uint32_t tmp = 0;
|
|
1078
|
|
1079 /* Check the parameters */
|
|
1080 assert_param(IS_RTC_BKP(BackupRegister));
|
|
1081
|
|
1082 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
|
|
1083 tmp += (BackupRegister * 4);
|
|
1084
|
|
1085 /* Read the specified register */
|
|
1086 return (*(__IO uint32_t *)tmp);
|
|
1087 }
|
|
1088
|
|
1089 /**
|
|
1090 * @brief Sets the Coarse calibration parameters.
|
|
1091 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1092 * the configuration information for RTC.
|
|
1093 * @param CalibSign: Specifies the sign of the coarse calibration value.
|
|
1094 * This parameter can be one of the following values :
|
|
1095 * @arg RTC_CALIBSIGN_POSITIVE: The value sign is positive
|
|
1096 * @arg RTC_CALIBSIGN_NEGATIVE: The value sign is negative
|
|
1097 * @param Value: value of coarse calibration expressed in ppm (coded on 5 bits).
|
|
1098 *
|
|
1099 * @note This Calibration value should be between 0 and 63 when using negative
|
|
1100 * sign with a 2-ppm step.
|
|
1101 *
|
|
1102 * @note This Calibration value should be between 0 and 126 when using positive
|
|
1103 * sign with a 4-ppm step.
|
|
1104 * @retval HAL status
|
|
1105 */
|
|
1106 HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef* hrtc, uint32_t CalibSign, uint32_t Value)
|
|
1107 {
|
|
1108 /* Check the parameters */
|
|
1109 assert_param(IS_RTC_CALIB_SIGN(CalibSign));
|
|
1110 assert_param(IS_RTC_CALIB_VALUE(Value));
|
|
1111
|
|
1112 /* Process Locked */
|
|
1113 __HAL_LOCK(hrtc);
|
|
1114
|
|
1115 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1116
|
|
1117 /* Disable the write protection for RTC registers */
|
|
1118 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1119
|
|
1120 /* Set Initialization mode */
|
|
1121 if(RTC_EnterInitMode(hrtc) != HAL_OK)
|
|
1122 {
|
|
1123 /* Enable the write protection for RTC registers */
|
|
1124 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1125
|
|
1126 /* Set RTC state*/
|
|
1127 hrtc->State = HAL_RTC_STATE_ERROR;
|
|
1128
|
|
1129 /* Process Unlocked */
|
|
1130 __HAL_UNLOCK(hrtc);
|
|
1131
|
|
1132 return HAL_ERROR;
|
|
1133 }
|
|
1134 else
|
|
1135 {
|
|
1136 /* Enable the Coarse Calibration */
|
|
1137 __HAL_RTC_COARSE_CALIB_ENABLE(hrtc);
|
|
1138
|
|
1139 /* Set the coarse calibration value */
|
|
1140 hrtc->Instance->CALIBR = (uint32_t)(CalibSign|Value);
|
|
1141
|
|
1142 /* Exit Initialization mode */
|
|
1143 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
|
|
1144 }
|
|
1145
|
|
1146 /* Enable the write protection for RTC registers */
|
|
1147 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1148
|
|
1149 /* Change state */
|
|
1150 hrtc->State = HAL_RTC_STATE_READY;
|
|
1151
|
|
1152 /* Process Unlocked */
|
|
1153 __HAL_UNLOCK(hrtc);
|
|
1154
|
|
1155 return HAL_OK;
|
|
1156 }
|
|
1157
|
|
1158 /**
|
|
1159 * @brief Deactivates the Coarse calibration parameters.
|
|
1160 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1161 * the configuration information for RTC.
|
|
1162 * @retval HAL status
|
|
1163 */
|
|
1164 HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef* hrtc)
|
|
1165 {
|
|
1166 /* Process Locked */
|
|
1167 __HAL_LOCK(hrtc);
|
|
1168
|
|
1169 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1170
|
|
1171 /* Disable the write protection for RTC registers */
|
|
1172 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1173
|
|
1174 /* Set Initialization mode */
|
|
1175 if(RTC_EnterInitMode(hrtc) != HAL_OK)
|
|
1176 {
|
|
1177 /* Enable the write protection for RTC registers */
|
|
1178 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1179
|
|
1180 /* Set RTC state*/
|
|
1181 hrtc->State = HAL_RTC_STATE_ERROR;
|
|
1182
|
|
1183 /* Process Unlocked */
|
|
1184 __HAL_UNLOCK(hrtc);
|
|
1185
|
|
1186 return HAL_ERROR;
|
|
1187 }
|
|
1188 else
|
|
1189 {
|
|
1190 /* Enable the Coarse Calibration */
|
|
1191 __HAL_RTC_COARSE_CALIB_DISABLE(hrtc);
|
|
1192
|
|
1193 /* Exit Initialization mode */
|
|
1194 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
|
|
1195 }
|
|
1196
|
|
1197 /* Enable the write protection for RTC registers */
|
|
1198 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1199
|
|
1200 /* Change state */
|
|
1201 hrtc->State = HAL_RTC_STATE_READY;
|
|
1202
|
|
1203 /* Process Unlocked */
|
|
1204 __HAL_UNLOCK(hrtc);
|
|
1205
|
|
1206 return HAL_OK;
|
|
1207 }
|
|
1208
|
|
1209 /**
|
|
1210 * @brief Sets the Smooth calibration parameters.
|
|
1211 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1212 * the configuration information for RTC.
|
|
1213 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
|
|
1214 * This parameter can be can be one of the following values :
|
|
1215 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
|
|
1216 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
|
|
1217 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
|
|
1218 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
|
|
1219 * This parameter can be one of the following values:
|
|
1220 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
|
|
1221 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
|
|
1222 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
|
|
1223 * This parameter can be one any value from 0 to 0x000001FF.
|
|
1224 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
|
|
1225 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
|
|
1226 * SmouthCalibMinusPulsesValue must be equal to 0.
|
|
1227 * @retval HAL status
|
|
1228 */
|
|
1229 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
|
|
1230 {
|
|
1231 uint32_t tickstart = 0;
|
|
1232
|
|
1233 /* Check the parameters */
|
|
1234 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
|
|
1235 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
|
|
1236 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
|
|
1237
|
|
1238 /* Process Locked */
|
|
1239 __HAL_LOCK(hrtc);
|
|
1240
|
|
1241 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1242
|
|
1243 /* Disable the write protection for RTC registers */
|
|
1244 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1245
|
|
1246 /* check if a calibration is pending*/
|
|
1247 if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
|
|
1248 {
|
|
1249 /* Get tick */
|
|
1250 tickstart = HAL_GetTick();
|
|
1251
|
|
1252 /* check if a calibration is pending*/
|
|
1253 while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
|
|
1254 {
|
|
1255 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
|
|
1256 {
|
|
1257 /* Enable the write protection for RTC registers */
|
|
1258 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1259
|
|
1260 /* Change RTC state */
|
|
1261 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
1262
|
|
1263 /* Process Unlocked */
|
|
1264 __HAL_UNLOCK(hrtc);
|
|
1265
|
|
1266 return HAL_TIMEOUT;
|
|
1267 }
|
|
1268 }
|
|
1269 }
|
|
1270
|
|
1271 /* Configure the Smooth calibration settings */
|
|
1272 hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue);
|
|
1273
|
|
1274 /* Enable the write protection for RTC registers */
|
|
1275 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1276
|
|
1277 /* Change RTC state */
|
|
1278 hrtc->State = HAL_RTC_STATE_READY;
|
|
1279
|
|
1280 /* Process Unlocked */
|
|
1281 __HAL_UNLOCK(hrtc);
|
|
1282
|
|
1283 return HAL_OK;
|
|
1284 }
|
|
1285
|
|
1286 /**
|
|
1287 * @brief Configures the Synchronization Shift Control Settings.
|
|
1288 * @note When REFCKON is set, firmware must not write to Shift control register.
|
|
1289 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1290 * the configuration information for RTC.
|
|
1291 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
|
|
1292 * This parameter can be one of the following values :
|
|
1293 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
|
|
1294 * @arg RTC_SHIFTADD1S_RESET: No effect.
|
|
1295 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
|
|
1296 * This parameter can be one any value from 0 to 0x7FFF.
|
|
1297 * @retval HAL status
|
|
1298 */
|
|
1299 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
|
|
1300 {
|
|
1301 uint32_t tickstart = 0;
|
|
1302
|
|
1303 /* Check the parameters */
|
|
1304 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
|
|
1305 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
|
|
1306
|
|
1307 /* Process Locked */
|
|
1308 __HAL_LOCK(hrtc);
|
|
1309
|
|
1310 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1311
|
|
1312 /* Disable the write protection for RTC registers */
|
|
1313 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1314
|
|
1315 /* Get tick */
|
|
1316 tickstart = HAL_GetTick();
|
|
1317
|
|
1318 /* Wait until the shift is completed*/
|
|
1319 while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET)
|
|
1320 {
|
|
1321 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
|
|
1322 {
|
|
1323 /* Enable the write protection for RTC registers */
|
|
1324 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1325
|
|
1326 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
1327
|
|
1328 /* Process Unlocked */
|
|
1329 __HAL_UNLOCK(hrtc);
|
|
1330
|
|
1331 return HAL_TIMEOUT;
|
|
1332 }
|
|
1333 }
|
|
1334
|
|
1335 /* Check if the reference clock detection is disabled */
|
|
1336 if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET)
|
|
1337 {
|
|
1338 /* Configure the Shift settings */
|
|
1339 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
|
|
1340
|
|
1341 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
|
|
1342 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
|
|
1343 {
|
|
1344 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
|
|
1345 {
|
|
1346 /* Enable the write protection for RTC registers */
|
|
1347 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1348
|
|
1349 hrtc->State = HAL_RTC_STATE_ERROR;
|
|
1350
|
|
1351 /* Process Unlocked */
|
|
1352 __HAL_UNLOCK(hrtc);
|
|
1353
|
|
1354 return HAL_ERROR;
|
|
1355 }
|
|
1356 }
|
|
1357 }
|
|
1358 else
|
|
1359 {
|
|
1360 /* Enable the write protection for RTC registers */
|
|
1361 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1362
|
|
1363 /* Change RTC state */
|
|
1364 hrtc->State = HAL_RTC_STATE_ERROR;
|
|
1365
|
|
1366 /* Process Unlocked */
|
|
1367 __HAL_UNLOCK(hrtc);
|
|
1368
|
|
1369 return HAL_ERROR;
|
|
1370 }
|
|
1371
|
|
1372 /* Enable the write protection for RTC registers */
|
|
1373 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1374
|
|
1375 /* Change RTC state */
|
|
1376 hrtc->State = HAL_RTC_STATE_READY;
|
|
1377
|
|
1378 /* Process Unlocked */
|
|
1379 __HAL_UNLOCK(hrtc);
|
|
1380
|
|
1381 return HAL_OK;
|
|
1382 }
|
|
1383
|
|
1384 /**
|
|
1385 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
|
|
1386 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1387 * the configuration information for RTC.
|
|
1388 * @param CalibOutput: Select the Calibration output Selection .
|
|
1389 * This parameter can be one of the following values:
|
|
1390 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
|
|
1391 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
|
|
1392 * @retval HAL status
|
|
1393 */
|
|
1394 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput)
|
|
1395 {
|
|
1396 /* Check the parameters */
|
|
1397 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
|
|
1398
|
|
1399 /* Process Locked */
|
|
1400 __HAL_LOCK(hrtc);
|
|
1401
|
|
1402 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1403
|
|
1404 /* Disable the write protection for RTC registers */
|
|
1405 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1406
|
|
1407 /* Clear flags before config */
|
|
1408 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
|
|
1409
|
|
1410 /* Configure the RTC_CR register */
|
|
1411 hrtc->Instance->CR |= (uint32_t)CalibOutput;
|
|
1412
|
|
1413 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
|
|
1414
|
|
1415 /* Enable the write protection for RTC registers */
|
|
1416 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1417
|
|
1418 /* Change RTC state */
|
|
1419 hrtc->State = HAL_RTC_STATE_READY;
|
|
1420
|
|
1421 /* Process Unlocked */
|
|
1422 __HAL_UNLOCK(hrtc);
|
|
1423
|
|
1424 return HAL_OK;
|
|
1425 }
|
|
1426
|
|
1427 /**
|
|
1428 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
|
|
1429 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1430 * the configuration information for RTC.
|
|
1431 * @retval HAL status
|
|
1432 */
|
|
1433 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc)
|
|
1434 {
|
|
1435 /* Process Locked */
|
|
1436 __HAL_LOCK(hrtc);
|
|
1437
|
|
1438 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1439
|
|
1440 /* Disable the write protection for RTC registers */
|
|
1441 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1442
|
|
1443 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
|
|
1444
|
|
1445 /* Enable the write protection for RTC registers */
|
|
1446 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1447
|
|
1448 /* Change RTC state */
|
|
1449 hrtc->State = HAL_RTC_STATE_READY;
|
|
1450
|
|
1451 /* Process Unlocked */
|
|
1452 __HAL_UNLOCK(hrtc);
|
|
1453
|
|
1454 return HAL_OK;
|
|
1455 }
|
|
1456
|
|
1457 /**
|
|
1458 * @brief Enables the RTC reference clock detection.
|
|
1459 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1460 * the configuration information for RTC.
|
|
1461 * @retval HAL status
|
|
1462 */
|
|
1463 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc)
|
|
1464 {
|
|
1465 /* Process Locked */
|
|
1466 __HAL_LOCK(hrtc);
|
|
1467
|
|
1468 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1469
|
|
1470 /* Disable the write protection for RTC registers */
|
|
1471 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1472
|
|
1473 /* Set Initialization mode */
|
|
1474 if(RTC_EnterInitMode(hrtc) != HAL_OK)
|
|
1475 {
|
|
1476 /* Enable the write protection for RTC registers */
|
|
1477 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1478
|
|
1479 /* Set RTC state*/
|
|
1480 hrtc->State = HAL_RTC_STATE_ERROR;
|
|
1481
|
|
1482 /* Process Unlocked */
|
|
1483 __HAL_UNLOCK(hrtc);
|
|
1484
|
|
1485 return HAL_ERROR;
|
|
1486 }
|
|
1487 else
|
|
1488 {
|
|
1489 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
|
|
1490
|
|
1491 /* Exit Initialization mode */
|
|
1492 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
|
|
1493 }
|
|
1494
|
|
1495 /* Enable the write protection for RTC registers */
|
|
1496 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1497
|
|
1498 /* Change RTC state */
|
|
1499 hrtc->State = HAL_RTC_STATE_READY;
|
|
1500
|
|
1501 /* Process Unlocked */
|
|
1502 __HAL_UNLOCK(hrtc);
|
|
1503
|
|
1504 return HAL_OK;
|
|
1505 }
|
|
1506
|
|
1507 /**
|
|
1508 * @brief Disable the RTC reference clock detection.
|
|
1509 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1510 * the configuration information for RTC.
|
|
1511 * @retval HAL status
|
|
1512 */
|
|
1513 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc)
|
|
1514 {
|
|
1515 /* Process Locked */
|
|
1516 __HAL_LOCK(hrtc);
|
|
1517
|
|
1518 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1519
|
|
1520 /* Disable the write protection for RTC registers */
|
|
1521 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1522
|
|
1523 /* Set Initialization mode */
|
|
1524 if(RTC_EnterInitMode(hrtc) != HAL_OK)
|
|
1525 {
|
|
1526 /* Enable the write protection for RTC registers */
|
|
1527 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1528
|
|
1529 /* Set RTC state*/
|
|
1530 hrtc->State = HAL_RTC_STATE_ERROR;
|
|
1531
|
|
1532 /* Process Unlocked */
|
|
1533 __HAL_UNLOCK(hrtc);
|
|
1534
|
|
1535 return HAL_ERROR;
|
|
1536 }
|
|
1537 else
|
|
1538 {
|
|
1539 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
|
|
1540
|
|
1541 /* Exit Initialization mode */
|
|
1542 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
|
|
1543 }
|
|
1544
|
|
1545 /* Enable the write protection for RTC registers */
|
|
1546 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1547
|
|
1548 /* Change RTC state */
|
|
1549 hrtc->State = HAL_RTC_STATE_READY;
|
|
1550
|
|
1551 /* Process Unlocked */
|
|
1552 __HAL_UNLOCK(hrtc);
|
|
1553
|
|
1554 return HAL_OK;
|
|
1555 }
|
|
1556
|
|
1557 /**
|
|
1558 * @brief Enables the Bypass Shadow feature.
|
|
1559 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1560 * the configuration information for RTC.
|
|
1561 * @note When the Bypass Shadow is enabled the calendar value are taken
|
|
1562 * directly from the Calendar counter.
|
|
1563 * @retval HAL status
|
|
1564 */
|
|
1565 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc)
|
|
1566 {
|
|
1567 /* Process Locked */
|
|
1568 __HAL_LOCK(hrtc);
|
|
1569
|
|
1570 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1571
|
|
1572 /* Disable the write protection for RTC registers */
|
|
1573 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1574
|
|
1575 /* Set the BYPSHAD bit */
|
|
1576 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
|
|
1577
|
|
1578 /* Enable the write protection for RTC registers */
|
|
1579 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1580
|
|
1581 /* Change RTC state */
|
|
1582 hrtc->State = HAL_RTC_STATE_READY;
|
|
1583
|
|
1584 /* Process Unlocked */
|
|
1585 __HAL_UNLOCK(hrtc);
|
|
1586
|
|
1587 return HAL_OK;
|
|
1588 }
|
|
1589
|
|
1590 /**
|
|
1591 * @brief Disables the Bypass Shadow feature.
|
|
1592 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1593 * the configuration information for RTC.
|
|
1594 * @note When the Bypass Shadow is enabled the calendar value are taken
|
|
1595 * directly from the Calendar counter.
|
|
1596 * @retval HAL status
|
|
1597 */
|
|
1598 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc)
|
|
1599 {
|
|
1600 /* Process Locked */
|
|
1601 __HAL_LOCK(hrtc);
|
|
1602
|
|
1603 hrtc->State = HAL_RTC_STATE_BUSY;
|
|
1604
|
|
1605 /* Disable the write protection for RTC registers */
|
|
1606 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
|
|
1607
|
|
1608 /* Reset the BYPSHAD bit */
|
|
1609 hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
|
|
1610
|
|
1611 /* Enable the write protection for RTC registers */
|
|
1612 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
|
|
1613
|
|
1614 /* Change RTC state */
|
|
1615 hrtc->State = HAL_RTC_STATE_READY;
|
|
1616
|
|
1617 /* Process Unlocked */
|
|
1618 __HAL_UNLOCK(hrtc);
|
|
1619
|
|
1620 return HAL_OK;
|
|
1621 }
|
|
1622
|
|
1623 /**
|
|
1624 * @}
|
|
1625 */
|
|
1626
|
|
1627 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
|
|
1628 * @brief Extended features functions
|
|
1629 *
|
|
1630 @verbatim
|
|
1631 ===============================================================================
|
|
1632 ##### Extended features functions #####
|
|
1633 ===============================================================================
|
|
1634 [..] This section provides functions allowing to:
|
|
1635 (+) RTC Alarm B callback
|
|
1636 (+) RTC Poll for Alarm B request
|
|
1637
|
|
1638 @endverbatim
|
|
1639 * @{
|
|
1640 */
|
|
1641
|
|
1642 /**
|
|
1643 * @brief Alarm B callback.
|
|
1644 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1645 * the configuration information for RTC.
|
|
1646 * @retval None
|
|
1647 */
|
|
1648 __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
|
|
1649 {
|
|
1650 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
1651 the HAL_RTC_AlarmBEventCallback could be implemented in the user file
|
|
1652 */
|
|
1653 }
|
|
1654
|
|
1655 /**
|
|
1656 * @brief This function handles AlarmB Polling request.
|
|
1657 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
|
|
1658 * the configuration information for RTC.
|
|
1659 * @param Timeout: Timeout duration
|
|
1660 * @retval HAL status
|
|
1661 */
|
|
1662 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
|
|
1663 {
|
|
1664 uint32_t tickstart = 0;
|
|
1665
|
|
1666 /* Get tick */
|
|
1667 tickstart = HAL_GetTick();
|
|
1668
|
|
1669 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET)
|
|
1670 {
|
|
1671 if(Timeout != HAL_MAX_DELAY)
|
|
1672 {
|
|
1673 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
1674 {
|
|
1675 hrtc->State = HAL_RTC_STATE_TIMEOUT;
|
|
1676 return HAL_TIMEOUT;
|
|
1677 }
|
|
1678 }
|
|
1679 }
|
|
1680
|
|
1681 /* Clear the Alarm Flag */
|
|
1682 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
|
|
1683
|
|
1684 /* Change RTC state */
|
|
1685 hrtc->State = HAL_RTC_STATE_READY;
|
|
1686
|
|
1687 return HAL_OK;
|
|
1688 }
|
|
1689
|
|
1690 /**
|
|
1691 * @}
|
|
1692 */
|
|
1693
|
|
1694 /**
|
|
1695 * @}
|
|
1696 */
|
|
1697
|
|
1698 #endif /* HAL_RTC_MODULE_ENABLED */
|
|
1699 /**
|
|
1700 * @}
|
|
1701 */
|
|
1702
|
|
1703 /**
|
|
1704 * @}
|
|
1705 */
|
|
1706
|
|
1707 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|