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