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