Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 3 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_hal_rtc_ex.c |
3 | * @file stm32f1xx_hal_rtc_ex.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief Extended RTC HAL module driver. |
5 | * @brief Extended RTC HAL module driver. |
6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
7 | * functionalities of the Real Time Clock (RTC) Extension peripheral: |
7 | * functionalities of the Real Time Clock (RTC) Extension peripheral: |
8 | * + RTC Tamper functions |
8 | * + RTC Tamper functions |
9 | * + Extension Control functions |
9 | * + Extension Control functions |
10 | * + Extension RTC features functions |
10 | * + Extension RTC features functions |
11 | * |
11 | * |
12 | ****************************************************************************** |
12 | ****************************************************************************** |
13 | * @attention |
13 | * @attention |
14 | * |
14 | * |
15 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
15 | * Copyright (c) 2016 STMicroelectronics. |
16 | * All rights reserved.</center></h2> |
16 | * All rights reserved. |
17 | * |
17 | * |
18 | * This software component is licensed by ST under BSD 3-Clause license, |
18 | * This software is licensed under terms that can be found in the LICENSE file |
19 | * the "License"; You may not use this file except in compliance with the |
19 | * in the root directory of this software component. |
20 | * License. You may obtain a copy of the License at: |
20 | * If no LICENSE file comes with this software, it is provided AS-IS. |
21 | * opensource.org/licenses/BSD-3-Clause |
21 | * |
22 | * |
22 | ****************************************************************************** |
23 | ****************************************************************************** |
23 | */ |
24 | */ |
24 | |
25 | 25 | /* Includes ------------------------------------------------------------------*/ |
|
26 | /* Includes ------------------------------------------------------------------*/ |
26 | #include "stm32f1xx_hal.h" |
27 | #include "stm32f1xx_hal.h" |
27 | |
28 | 28 | /** @addtogroup STM32F1xx_HAL_Driver |
|
29 | /** @addtogroup STM32F1xx_HAL_Driver |
29 | * @{ |
30 | * @{ |
30 | */ |
31 | */ |
31 | |
32 | 32 | #ifdef HAL_RTC_MODULE_ENABLED |
|
33 | #ifdef HAL_RTC_MODULE_ENABLED |
33 | |
34 | 34 | /** @defgroup RTCEx RTCEx |
|
35 | /** @defgroup RTCEx RTCEx |
35 | * @brief RTC Extended HAL module driver |
36 | * @brief RTC Extended HAL module driver |
36 | * @{ |
37 | * @{ |
37 | */ |
38 | */ |
38 | |
39 | 39 | /* Private typedef -----------------------------------------------------------*/ |
|
40 | /* Private typedef -----------------------------------------------------------*/ |
40 | /* Private define ------------------------------------------------------------*/ |
41 | /* Private define ------------------------------------------------------------*/ |
41 | /* Private macro -------------------------------------------------------------*/ |
42 | /* Private macro -------------------------------------------------------------*/ |
42 | /** @defgroup RTCEx_Private_Macros RTCEx Private Macros |
43 | /** @defgroup RTCEx_Private_Macros RTCEx Private Macros |
43 | * @{ |
44 | * @{ |
44 | */ |
45 | */ |
45 | /** |
46 | /** |
46 | * @} |
47 | * @} |
47 | */ |
48 | */ |
48 | |
49 | 49 | /* Private variables ---------------------------------------------------------*/ |
|
50 | /* Private variables ---------------------------------------------------------*/ |
50 | /* Private function prototypes -----------------------------------------------*/ |
51 | /* Private function prototypes -----------------------------------------------*/ |
51 | /* Private functions ---------------------------------------------------------*/ |
52 | /* Private functions ---------------------------------------------------------*/ |
52 | |
53 | 53 | /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions |
|
54 | /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions |
54 | * @{ |
55 | * @{ |
55 | */ |
56 | */ |
56 | |
57 | 57 | /** @defgroup RTCEx_Exported_Functions_Group1 RTC Tamper functions |
|
58 | /** @defgroup RTCEx_Exported_Functions_Group1 RTC Tamper functions |
58 | * @brief RTC Tamper functions |
59 | * @brief RTC Tamper functions |
59 | * |
60 | * |
60 | @verbatim |
61 | @verbatim |
61 | =============================================================================== |
62 | =============================================================================== |
62 | ##### RTC Tamper functions ##### |
63 | ##### RTC Tamper functions ##### |
63 | =============================================================================== |
64 | =============================================================================== |
64 | |
65 | 65 | [..] This section provides functions allowing to configure Tamper feature |
|
66 | [..] This section provides functions allowing to configure Tamper feature |
66 | |
67 | 67 | @endverbatim |
|
68 | @endverbatim |
68 | * @{ |
69 | * @{ |
69 | */ |
70 | */ |
70 | |
71 | 71 | /** |
|
72 | /** |
72 | * @brief Sets Tamper |
73 | * @brief Sets Tamper |
73 | * @note By calling this API we disable the tamper interrupt for all tampers. |
74 | * @note By calling this API we disable the tamper interrupt for all tampers. |
74 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
75 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
75 | * the configuration information for RTC. |
76 | * the configuration information for RTC. |
76 | * @param sTamper: Pointer to Tamper Structure. |
77 | * @param sTamper: Pointer to Tamper Structure. |
77 | * @note Tamper can be enabled only if ASOE and CCO bit are reset |
78 | * @note Tamper can be enabled only if ASOE and CCO bit are reset |
78 | * @retval HAL status |
79 | * @retval HAL status |
79 | */ |
80 | */ |
80 | HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper) |
81 | HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper) |
81 | { |
82 | { |
82 | /* Check input parameters */ |
83 | /* Check input parameters */ |
83 | if ((hrtc == NULL) || (sTamper == NULL)) |
84 | if ((hrtc == NULL) || (sTamper == NULL)) |
84 | { |
85 | { |
85 | return HAL_ERROR; |
86 | return HAL_ERROR; |
86 | } |
87 | } |
87 | |
88 | 88 | /* Check the parameters */ |
|
89 | /* Check the parameters */ |
89 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
90 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
90 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
91 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
91 | |
92 | 92 | /* Process Locked */ |
|
93 | /* Process Locked */ |
93 | __HAL_LOCK(hrtc); |
94 | __HAL_LOCK(hrtc); |
94 | |
95 | 95 | hrtc->State = HAL_RTC_STATE_BUSY; |
|
96 | hrtc->State = HAL_RTC_STATE_BUSY; |
96 | |
97 | 97 | if (HAL_IS_BIT_SET(BKP->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE))) |
|
98 | if (HAL_IS_BIT_SET(BKP->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE))) |
98 | { |
99 | { |
99 | hrtc->State = HAL_RTC_STATE_ERROR; |
100 | hrtc->State = HAL_RTC_STATE_ERROR; |
100 | |
101 | 101 | /* Process Unlocked */ |
|
102 | /* Process Unlocked */ |
102 | __HAL_UNLOCK(hrtc); |
103 | __HAL_UNLOCK(hrtc); |
103 | |
104 | 104 | return HAL_ERROR; |
|
105 | return HAL_ERROR; |
105 | } |
106 | } |
106 | |
107 | 107 | MODIFY_REG(BKP->CR, (BKP_CR_TPE | BKP_CR_TPAL), (sTamper->Tamper | (sTamper->Trigger))); |
|
108 | MODIFY_REG(BKP->CR, (BKP_CR_TPE | BKP_CR_TPAL), (sTamper->Tamper | (sTamper->Trigger))); |
108 | |
109 | 109 | hrtc->State = HAL_RTC_STATE_READY; |
|
110 | hrtc->State = HAL_RTC_STATE_READY; |
110 | |
111 | 111 | /* Process Unlocked */ |
|
112 | /* Process Unlocked */ |
112 | __HAL_UNLOCK(hrtc); |
113 | __HAL_UNLOCK(hrtc); |
113 | |
114 | 114 | return HAL_OK; |
|
115 | return HAL_OK; |
115 | } |
116 | } |
116 | |
117 | 117 | /** |
|
118 | /** |
118 | * @brief Sets Tamper with interrupt. |
119 | * @brief Sets Tamper with interrupt. |
119 | * @note By calling this API we force the tamper interrupt for all tampers. |
120 | * @note By calling this API we force the tamper interrupt for all tampers. |
120 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
121 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
121 | * the configuration information for RTC. |
122 | * the configuration information for RTC. |
122 | * @param sTamper: Pointer to RTC Tamper. |
123 | * @param sTamper: Pointer to RTC Tamper. |
123 | * @note Tamper can be enabled only if ASOE and CCO bit are reset |
124 | * @note Tamper can be enabled only if ASOE and CCO bit are reset |
124 | * @retval HAL status |
125 | * @retval HAL status |
125 | */ |
126 | */ |
126 | HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper) |
127 | HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper) |
127 | { |
128 | { |
128 | /* Check input parameters */ |
129 | /* Check input parameters */ |
129 | if ((hrtc == NULL) || (sTamper == NULL)) |
130 | if ((hrtc == NULL) || (sTamper == NULL)) |
130 | { |
131 | { |
131 | return HAL_ERROR; |
132 | return HAL_ERROR; |
132 | } |
133 | } |
133 | |
134 | 134 | /* Check the parameters */ |
|
135 | /* Check the parameters */ |
135 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
136 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
136 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
137 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
137 | |
138 | 138 | /* Process Locked */ |
|
139 | /* Process Locked */ |
139 | __HAL_LOCK(hrtc); |
140 | __HAL_LOCK(hrtc); |
140 | |
141 | 141 | hrtc->State = HAL_RTC_STATE_BUSY; |
|
142 | hrtc->State = HAL_RTC_STATE_BUSY; |
142 | |
143 | 143 | if (HAL_IS_BIT_SET(BKP->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE))) |
|
144 | if (HAL_IS_BIT_SET(BKP->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE))) |
144 | { |
145 | { |
145 | hrtc->State = HAL_RTC_STATE_ERROR; |
146 | hrtc->State = HAL_RTC_STATE_ERROR; |
146 | |
147 | 147 | /* Process Unlocked */ |
|
148 | /* Process Unlocked */ |
148 | __HAL_UNLOCK(hrtc); |
149 | __HAL_UNLOCK(hrtc); |
149 | |
150 | 150 | return HAL_ERROR; |
|
151 | return HAL_ERROR; |
151 | } |
152 | } |
152 | |
153 | 153 | MODIFY_REG(BKP->CR, (BKP_CR_TPE | BKP_CR_TPAL), (sTamper->Tamper | (sTamper->Trigger))); |
|
154 | MODIFY_REG(BKP->CR, (BKP_CR_TPE | BKP_CR_TPAL), (sTamper->Tamper | (sTamper->Trigger))); |
154 | |
155 | 155 | /* Configure the Tamper Interrupt in the BKP->CSR */ |
|
156 | /* Configure the Tamper Interrupt in the BKP->CSR */ |
156 | __HAL_RTC_TAMPER_ENABLE_IT(hrtc, RTC_IT_TAMP1); |
157 | __HAL_RTC_TAMPER_ENABLE_IT(hrtc, RTC_IT_TAMP1); |
157 | |
158 | 158 | hrtc->State = HAL_RTC_STATE_READY; |
|
159 | hrtc->State = HAL_RTC_STATE_READY; |
159 | |
160 | 160 | /* Process Unlocked */ |
|
161 | /* Process Unlocked */ |
161 | __HAL_UNLOCK(hrtc); |
162 | __HAL_UNLOCK(hrtc); |
162 | |
163 | 163 | return HAL_OK; |
|
164 | return HAL_OK; |
164 | } |
165 | } |
165 | |
166 | 166 | /** |
|
167 | /** |
167 | * @brief Deactivates Tamper. |
168 | * @brief Deactivates Tamper. |
168 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
169 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
169 | * the configuration information for RTC. |
170 | * the configuration information for RTC. |
170 | * @param Tamper: Selected tamper pin. |
171 | * @param Tamper: Selected tamper pin. |
171 | * This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions |
172 | * This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions |
172 | * @retval HAL status |
173 | * @retval HAL status |
173 | */ |
174 | */ |
174 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) |
175 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) |
175 | { |
176 | { |
176 | /* Check input parameters */ |
177 | /* Check input parameters */ |
177 | if (hrtc == NULL) |
178 | if (hrtc == NULL) |
178 | { |
179 | { |
179 | return HAL_ERROR; |
180 | return HAL_ERROR; |
180 | } |
181 | } |
181 | /* Prevent unused argument(s) compilation warning */ |
182 | /* Prevent unused argument(s) compilation warning */ |
182 | UNUSED(Tamper); |
183 | UNUSED(Tamper); |
183 | |
184 | 184 | assert_param(IS_RTC_TAMPER(Tamper)); |
|
185 | assert_param(IS_RTC_TAMPER(Tamper)); |
185 | |
186 | 186 | /* Process Locked */ |
|
187 | /* Process Locked */ |
187 | __HAL_LOCK(hrtc); |
188 | __HAL_LOCK(hrtc); |
188 | |
189 | 189 | hrtc->State = HAL_RTC_STATE_BUSY; |
|
190 | hrtc->State = HAL_RTC_STATE_BUSY; |
190 | |
191 | 191 | /* Disable the selected Tamper pin */ |
|
192 | /* Disable the selected Tamper pin */ |
192 | CLEAR_BIT(BKP->CR, BKP_CR_TPE); |
193 | CLEAR_BIT(BKP->CR, BKP_CR_TPE); |
193 | |
194 | 194 | /* Disable the Tamper Interrupt in the BKP->CSR */ |
|
195 | /* Disable the Tamper Interrupt in the BKP->CSR */ |
195 | /* Configure the Tamper Interrupt in the BKP->CSR */ |
196 | /* Configure the Tamper Interrupt in the BKP->CSR */ |
196 | __HAL_RTC_TAMPER_DISABLE_IT(hrtc, RTC_IT_TAMP1); |
197 | __HAL_RTC_TAMPER_DISABLE_IT(hrtc, RTC_IT_TAMP1); |
197 | |
198 | 198 | /* Clear the Tamper interrupt pending bit */ |
|
199 | /* Clear the Tamper interrupt pending bit */ |
199 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
200 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
200 | SET_BIT(BKP->CSR, BKP_CSR_CTE); |
201 | SET_BIT(BKP->CSR, BKP_CSR_CTE); |
201 | |
202 | 202 | hrtc->State = HAL_RTC_STATE_READY; |
|
203 | hrtc->State = HAL_RTC_STATE_READY; |
203 | |
204 | 204 | /* Process Unlocked */ |
|
205 | /* Process Unlocked */ |
205 | __HAL_UNLOCK(hrtc); |
206 | __HAL_UNLOCK(hrtc); |
206 | |
207 | 207 | return HAL_OK; |
|
208 | return HAL_OK; |
208 | } |
209 | } |
209 | |
210 | 210 | /** |
|
211 | /** |
211 | * @brief This function handles Tamper interrupt request. |
212 | * @brief This function handles Tamper interrupt request. |
212 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
213 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
213 | * the configuration information for RTC. |
214 | * the configuration information for RTC. |
214 | * @retval None |
215 | * @retval None |
215 | */ |
216 | */ |
216 | void HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc) |
217 | void HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc) |
217 | { |
218 | { |
218 | /* Get the status of the Interrupt */ |
219 | /* Get the status of the Interrupt */ |
219 | if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP1)) |
220 | if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP1)) |
220 | { |
221 | { |
221 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
222 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
222 | if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != (uint32_t)RESET) |
223 | if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != (uint32_t)RESET) |
223 | { |
224 | { |
224 | /* Tamper callback */ |
225 | /* Tamper callback */ |
225 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
226 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
226 | hrtc->Tamper1EventCallback(hrtc); |
227 | hrtc->Tamper1EventCallback(hrtc); |
227 | #else |
228 | #else |
228 | HAL_RTCEx_Tamper1EventCallback(hrtc); |
229 | HAL_RTCEx_Tamper1EventCallback(hrtc); |
229 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
230 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
230 | |
231 | 231 | /* Clear the Tamper interrupt pending bit */ |
|
232 | /* Clear the Tamper interrupt pending bit */ |
232 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
233 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
233 | } |
234 | } |
234 | } |
235 | } |
235 | |
236 | 236 | /* Change RTC state */ |
|
237 | /* Change RTC state */ |
237 | hrtc->State = HAL_RTC_STATE_READY; |
238 | hrtc->State = HAL_RTC_STATE_READY; |
238 | } |
239 | } |
239 | |
240 | 240 | /** |
|
241 | /** |
241 | * @brief Tamper 1 callback. |
242 | * @brief Tamper 1 callback. |
242 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
243 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
243 | * the configuration information for RTC. |
244 | * the configuration information for RTC. |
244 | * @retval None |
245 | * @retval None |
245 | */ |
246 | */ |
246 | __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) |
247 | __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) |
247 | { |
248 | { |
248 | /* Prevent unused argument(s) compilation warning */ |
249 | /* Prevent unused argument(s) compilation warning */ |
249 | UNUSED(hrtc); |
250 | UNUSED(hrtc); |
250 | /* NOTE : This function Should not be modified, when the callback is needed, |
251 | /* NOTE : This function Should not be modified, when the callback is needed, |
251 | the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file |
252 | the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file |
252 | */ |
253 | */ |
253 | } |
254 | } |
254 | |
255 | 255 | /** |
|
256 | /** |
256 | * @brief This function handles Tamper1 Polling. |
257 | * @brief This function handles Tamper1 Polling. |
257 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
258 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
258 | * the configuration information for RTC. |
259 | * the configuration information for RTC. |
259 | * @param Timeout: Timeout duration |
260 | * @param Timeout: Timeout duration |
260 | * @retval HAL status |
261 | * @retval HAL status |
261 | */ |
262 | */ |
262 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
263 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
263 | { |
264 | { |
264 | uint32_t tickstart = HAL_GetTick(); |
265 | uint32_t tickstart = HAL_GetTick(); |
265 | |
266 | 266 | /* Check input parameters */ |
|
267 | /* Check input parameters */ |
267 | if (hrtc == NULL) |
268 | if (hrtc == NULL) |
268 | { |
269 | { |
269 | return HAL_ERROR; |
270 | return HAL_ERROR; |
270 | } |
271 | } |
271 | |
272 | 272 | /* Get the status of the Interrupt */ |
|
273 | /* Get the status of the Interrupt */ |
273 | while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) == RESET) |
274 | while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) == RESET) |
274 | { |
275 | { |
275 | if (Timeout != HAL_MAX_DELAY) |
276 | if (Timeout != HAL_MAX_DELAY) |
276 | { |
277 | { |
277 | if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) |
278 | if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) |
278 | { |
279 | { |
279 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
280 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
280 | return HAL_TIMEOUT; |
281 | return HAL_TIMEOUT; |
281 | } |
282 | } |
282 | } |
283 | } |
283 | } |
284 | } |
284 | |
285 | 285 | /* Clear the Tamper Flag */ |
|
286 | /* Clear the Tamper Flag */ |
286 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
287 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
287 | |
288 | 288 | /* Change RTC state */ |
|
289 | /* Change RTC state */ |
289 | hrtc->State = HAL_RTC_STATE_READY; |
290 | hrtc->State = HAL_RTC_STATE_READY; |
290 | |
291 | 291 | return HAL_OK; |
|
292 | return HAL_OK; |
292 | } |
293 | } |
293 | |
294 | 294 | /** |
|
295 | /** |
295 | * @} |
296 | * @} |
296 | */ |
297 | */ |
297 | |
298 | 298 | /** @defgroup RTCEx_Exported_Functions_Group2 RTC Second functions |
|
299 | /** @defgroup RTCEx_Exported_Functions_Group2 RTC Second functions |
299 | * @brief RTC Second functions |
300 | * @brief RTC Second functions |
300 | * |
301 | * |
301 | @verbatim |
302 | @verbatim |
302 | =============================================================================== |
303 | =============================================================================== |
303 | ##### RTC Second functions ##### |
304 | ##### RTC Second functions ##### |
304 | =============================================================================== |
305 | =============================================================================== |
305 | |
306 | 306 | [..] This section provides functions implementing second interrupt handlers |
|
307 | [..] This section provides functions implementing second interupt handlers |
307 | |
308 | 308 | @endverbatim |
|
309 | @endverbatim |
309 | * @{ |
310 | * @{ |
310 | */ |
311 | */ |
311 | |
312 | 312 | /** |
|
313 | /** |
313 | * @brief Sets Interrupt for second |
314 | * @brief Sets Interrupt for second |
314 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
315 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
315 | * the configuration information for RTC. |
316 | * the configuration information for RTC. |
316 | * @retval HAL status |
317 | * @retval HAL status |
317 | */ |
318 | */ |
318 | HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc) |
319 | HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc) |
319 | { |
320 | { |
320 | /* Check input parameters */ |
321 | /* Check input parameters */ |
321 | if (hrtc == NULL) |
322 | if (hrtc == NULL) |
322 | { |
323 | { |
323 | return HAL_ERROR; |
324 | return HAL_ERROR; |
324 | } |
325 | } |
325 | |
326 | 326 | /* Process Locked */ |
|
327 | /* Process Locked */ |
327 | __HAL_LOCK(hrtc); |
328 | __HAL_LOCK(hrtc); |
328 | |
329 | 329 | hrtc->State = HAL_RTC_STATE_BUSY; |
|
330 | hrtc->State = HAL_RTC_STATE_BUSY; |
330 | |
331 | 331 | /* Enable Second interruption */ |
|
332 | /* Enable Second interuption */ |
332 | __HAL_RTC_SECOND_ENABLE_IT(hrtc, RTC_IT_SEC); |
333 | __HAL_RTC_SECOND_ENABLE_IT(hrtc, RTC_IT_SEC); |
333 | |
334 | 334 | hrtc->State = HAL_RTC_STATE_READY; |
|
335 | hrtc->State = HAL_RTC_STATE_READY; |
335 | |
336 | 336 | /* Process Unlocked */ |
|
337 | /* Process Unlocked */ |
337 | __HAL_UNLOCK(hrtc); |
338 | __HAL_UNLOCK(hrtc); |
338 | |
339 | 339 | return HAL_OK; |
|
340 | return HAL_OK; |
340 | } |
341 | } |
341 | |
342 | 342 | /** |
|
343 | /** |
343 | * @brief Deactivates Second. |
344 | * @brief Deactivates Second. |
344 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
345 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
345 | * the configuration information for RTC. |
346 | * the configuration information for RTC. |
346 | * @retval HAL status |
347 | * @retval HAL status |
347 | */ |
348 | */ |
348 | HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc) |
349 | HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc) |
349 | { |
350 | { |
350 | /* Check input parameters */ |
351 | /* Check input parameters */ |
351 | if (hrtc == NULL) |
352 | if (hrtc == NULL) |
352 | { |
353 | { |
353 | return HAL_ERROR; |
354 | return HAL_ERROR; |
354 | } |
355 | } |
355 | |
356 | 356 | /* Process Locked */ |
|
357 | /* Process Locked */ |
357 | __HAL_LOCK(hrtc); |
358 | __HAL_LOCK(hrtc); |
358 | |
359 | 359 | hrtc->State = HAL_RTC_STATE_BUSY; |
|
360 | hrtc->State = HAL_RTC_STATE_BUSY; |
360 | |
361 | 361 | /* Deactivate Second interruption*/ |
|
362 | /* Deactivate Second interuption*/ |
362 | __HAL_RTC_SECOND_DISABLE_IT(hrtc, RTC_IT_SEC); |
363 | __HAL_RTC_SECOND_DISABLE_IT(hrtc, RTC_IT_SEC); |
363 | |
364 | 364 | hrtc->State = HAL_RTC_STATE_READY; |
|
365 | hrtc->State = HAL_RTC_STATE_READY; |
365 | |
366 | 366 | /* Process Unlocked */ |
|
367 | /* Process Unlocked */ |
367 | __HAL_UNLOCK(hrtc); |
368 | __HAL_UNLOCK(hrtc); |
368 | |
369 | 369 | return HAL_OK; |
|
370 | return HAL_OK; |
370 | } |
371 | } |
371 | |
372 | 372 | /** |
|
373 | /** |
373 | * @brief This function handles second interrupt request. |
374 | * @brief This function handles second interrupt request. |
374 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
375 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
375 | * the configuration information for RTC. |
376 | * the configuration information for RTC. |
376 | * @retval None |
377 | * @retval None |
377 | */ |
378 | */ |
378 | void HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef *hrtc) |
379 | void HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef *hrtc) |
379 | { |
380 | { |
380 | if (__HAL_RTC_SECOND_GET_IT_SOURCE(hrtc, RTC_IT_SEC)) |
381 | if (__HAL_RTC_SECOND_GET_IT_SOURCE(hrtc, RTC_IT_SEC)) |
381 | { |
382 | { |
382 | /* Get the status of the Interrupt */ |
383 | /* Get the status of the Interrupt */ |
383 | if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_SEC)) |
384 | if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_SEC)) |
384 | { |
385 | { |
385 | /* Check if Overrun occurred */ |
386 | /* Check if Overrun occurred */ |
386 | if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_OW)) |
387 | if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_OW)) |
387 | { |
388 | { |
388 | /* Second error callback */ |
389 | /* Second error callback */ |
389 | HAL_RTCEx_RTCEventErrorCallback(hrtc); |
390 | HAL_RTCEx_RTCEventErrorCallback(hrtc); |
390 | |
391 | 391 | /* Clear flag Second */ |
|
392 | /* Clear flag Second */ |
392 | __HAL_RTC_OVERFLOW_CLEAR_FLAG(hrtc, RTC_FLAG_OW); |
393 | __HAL_RTC_OVERFLOW_CLEAR_FLAG(hrtc, RTC_FLAG_OW); |
393 | |
394 | 394 | /* Change RTC state */ |
|
395 | /* Change RTC state */ |
395 | hrtc->State = HAL_RTC_STATE_ERROR; |
396 | hrtc->State = HAL_RTC_STATE_ERROR; |
396 | } |
397 | } |
397 | else |
398 | else |
398 | { |
399 | { |
399 | /* Second callback */ |
400 | /* Second callback */ |
400 | HAL_RTCEx_RTCEventCallback(hrtc); |
401 | HAL_RTCEx_RTCEventCallback(hrtc); |
401 | |
402 | 402 | /* Change RTC state */ |
|
403 | /* Change RTC state */ |
403 | hrtc->State = HAL_RTC_STATE_READY; |
404 | hrtc->State = HAL_RTC_STATE_READY; |
404 | } |
405 | } |
405 | |
406 | 406 | /* Clear flag Second */ |
|
407 | /* Clear flag Second */ |
407 | __HAL_RTC_SECOND_CLEAR_FLAG(hrtc, RTC_FLAG_SEC); |
408 | __HAL_RTC_SECOND_CLEAR_FLAG(hrtc, RTC_FLAG_SEC); |
408 | } |
409 | } |
409 | } |
410 | } |
410 | } |
411 | } |
411 | |
412 | 412 | /** |
|
413 | /** |
413 | * @brief Second event callback. |
414 | * @brief Second event callback. |
414 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
415 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
415 | * the configuration information for RTC. |
416 | * the configuration information for RTC. |
416 | * @retval None |
417 | * @retval None |
417 | */ |
418 | */ |
418 | __weak void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc) |
419 | __weak void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc) |
419 | { |
420 | { |
420 | /* Prevent unused argument(s) compilation warning */ |
421 | /* Prevent unused argument(s) compilation warning */ |
421 | UNUSED(hrtc); |
422 | UNUSED(hrtc); |
422 | /* NOTE : This function Should not be modified, when the callback is needed, |
423 | /* NOTE : This function Should not be modified, when the callback is needed, |
423 | the HAL_RTCEx_RTCEventCallback could be implemented in the user file |
424 | the HAL_RTCEx_RTCEventCallback could be implemented in the user file |
424 | */ |
425 | */ |
425 | } |
426 | } |
426 | |
427 | 427 | /** |
|
428 | /** |
428 | * @brief Second event error callback. |
429 | * @brief Second event error callback. |
429 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
430 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
430 | * the configuration information for RTC. |
431 | * the configuration information for RTC. |
431 | * @retval None |
432 | * @retval None |
432 | */ |
433 | */ |
433 | __weak void HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc) |
434 | __weak void HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc) |
434 | { |
435 | { |
435 | /* Prevent unused argument(s) compilation warning */ |
436 | /* Prevent unused argument(s) compilation warning */ |
436 | UNUSED(hrtc); |
437 | UNUSED(hrtc); |
437 | /* NOTE : This function Should not be modified, when the callback is needed, |
438 | /* NOTE : This function Should not be modified, when the callback is needed, |
438 | the HAL_RTCEx_RTCEventErrorCallback could be implemented in the user file |
439 | the HAL_RTCEx_RTCEventErrorCallback could be implemented in the user file |
439 | */ |
440 | */ |
440 | } |
441 | } |
441 | |
442 | 442 | /** |
|
443 | /** |
443 | * @} |
444 | * @} |
444 | */ |
445 | */ |
445 | |
446 | 446 | /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions |
|
447 | /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions |
447 | * @brief Extended Peripheral Control functions |
448 | * @brief Extended Peripheral Control functions |
448 | * |
449 | * |
449 | @verbatim |
450 | @verbatim |
450 | =============================================================================== |
451 | =============================================================================== |
451 | ##### Extension Peripheral Control functions ##### |
452 | ##### Extension Peripheral Control functions ##### |
452 | =============================================================================== |
453 | =============================================================================== |
453 | [..] |
454 | [..] |
454 | This subsection provides functions allowing to |
455 | This subsection provides functions allowing to |
455 | (+) Writes a data in a specified RTC Backup data register |
456 | (+) Writes a data in a specified RTC Backup data register |
456 | (+) Read a data in a specified RTC Backup data register |
457 | (+) Read a data in a specified RTC Backup data register |
457 | (+) Sets the Smooth calibration parameters. |
458 | (+) Sets the Smooth calibration parameters. |
458 | |
459 | 459 | @endverbatim |
|
460 | @endverbatim |
460 | * @{ |
461 | * @{ |
461 | */ |
462 | */ |
462 | |
463 | 463 | /** |
|
464 | /** |
464 | * @brief Writes a data in a specified RTC Backup data register. |
465 | * @brief Writes a data in a specified RTC Backup data register. |
465 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
466 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
466 | * the configuration information for RTC. |
467 | * the configuration information for RTC. |
467 | * @param BackupRegister: RTC Backup data Register number. |
468 | * @param BackupRegister: RTC Backup data Register number. |
468 | * This parameter can be: RTC_BKP_DRx where x can be from 1 to 10 (or 42) to |
469 | * This parameter can be: RTC_BKP_DRx where x can be from 1 to 10 (or 42) to |
469 | * specify the register (depending devices). |
470 | * specify the register (depending devices). |
470 | * @param Data: Data to be written in the specified RTC Backup data register. |
471 | * @param Data: Data to be written in the specified RTC Backup data register. |
471 | * @retval None |
472 | * @retval None |
472 | */ |
473 | */ |
473 | void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) |
474 | void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) |
474 | { |
475 | { |
475 | uint32_t tmp = 0U; |
476 | uint32_t tmp = 0U; |
476 | |
477 | 477 | /* Prevent unused argument(s) compilation warning */ |
|
478 | /* Prevent unused argument(s) compilation warning */ |
478 | UNUSED(hrtc); |
479 | UNUSED(hrtc); |
479 | |
480 | 480 | /* Check the parameters */ |
|
481 | /* Check the parameters */ |
481 | assert_param(IS_RTC_BKP(BackupRegister)); |
482 | assert_param(IS_RTC_BKP(BackupRegister)); |
482 | |
483 | 483 | tmp = (uint32_t)BKP_BASE; |
|
484 | tmp = (uint32_t)BKP_BASE; |
484 | tmp += (BackupRegister * 4U); |
485 | tmp += (BackupRegister * 4U); |
485 | |
486 | 486 | *(__IO uint32_t *) tmp = (Data & BKP_DR1_D); |
|
487 | *(__IO uint32_t *) tmp = (Data & BKP_DR1_D); |
487 | } |
488 | } |
488 | |
489 | 489 | /** |
|
490 | /** |
490 | * @brief Reads data from the specified RTC Backup data Register. |
491 | * @brief Reads data from the specified RTC Backup data Register. |
491 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
492 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
492 | * the configuration information for RTC. |
493 | * the configuration information for RTC. |
493 | * @param BackupRegister: RTC Backup data Register number. |
494 | * @param BackupRegister: RTC Backup data Register number. |
494 | * This parameter can be: RTC_BKP_DRx where x can be from 1 to 10 (or 42) to |
495 | * This parameter can be: RTC_BKP_DRx where x can be from 1 to 10 (or 42) to |
495 | * specify the register (depending devices). |
496 | * specify the register (depending devices). |
496 | * @retval Read value |
497 | * @retval Read value |
497 | */ |
498 | */ |
498 | uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) |
499 | uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) |
499 | { |
500 | { |
500 | uint32_t backupregister = 0U; |
501 | uint32_t backupregister = 0U; |
501 | uint32_t pvalue = 0U; |
502 | uint32_t pvalue = 0U; |
502 | |
503 | 503 | /* Prevent unused argument(s) compilation warning */ |
|
504 | /* Prevent unused argument(s) compilation warning */ |
504 | UNUSED(hrtc); |
505 | UNUSED(hrtc); |
505 | |
506 | 506 | /* Check the parameters */ |
|
507 | /* Check the parameters */ |
507 | assert_param(IS_RTC_BKP(BackupRegister)); |
508 | assert_param(IS_RTC_BKP(BackupRegister)); |
508 | |
509 | 509 | backupregister = (uint32_t)BKP_BASE; |
|
510 | backupregister = (uint32_t)BKP_BASE; |
510 | backupregister += (BackupRegister * 4U); |
511 | backupregister += (BackupRegister * 4U); |
511 | |
512 | 512 | pvalue = (*(__IO uint32_t *)(backupregister)) & BKP_DR1_D; |
|
513 | pvalue = (*(__IO uint32_t *)(backupregister)) & BKP_DR1_D; |
513 | |
514 | 514 | /* Read the specified register */ |
|
515 | /* Read the specified register */ |
515 | return pvalue; |
516 | return pvalue; |
516 | } |
517 | } |
517 | |
518 | 518 | ||
519 | 519 | /** |
|
520 | /** |
520 | * @brief Sets the Smooth calibration parameters. |
521 | * @brief Sets the Smooth calibration parameters. |
521 | * @param hrtc: RTC handle |
522 | * @param hrtc: RTC handle |
522 | * @param SmoothCalibPeriod: Not used (only present for compatibility with another families) |
523 | * @param SmoothCalibPeriod: Not used (only present for compatibility with another families) |
523 | * @param SmoothCalibPlusPulses: Not used (only present for compatibility with another families) |
524 | * @param SmoothCalibPlusPulses: Not used (only present for compatibility with another families) |
524 | * @param SmouthCalibMinusPulsesValue: specifies the RTC Clock Calibration value. |
525 | * @param SmouthCalibMinusPulsesValue: specifies the RTC Clock Calibration value. |
525 | * This parameter must be a number between 0 and 0x7F. |
526 | * This parameter must be a number between 0 and 0x7F. |
526 | * @retval HAL status |
527 | * @retval HAL status |
527 | */ |
528 | */ |
528 | HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue) |
529 | HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue) |
529 | { |
530 | { |
530 | /* Check input parameters */ |
531 | /* Check input parameters */ |
531 | if (hrtc == NULL) |
532 | if (hrtc == NULL) |
532 | { |
533 | { |
533 | return HAL_ERROR; |
534 | return HAL_ERROR; |
534 | } |
535 | } |
535 | /* Prevent unused argument(s) compilation warning */ |
536 | /* Prevent unused argument(s) compilation warning */ |
536 | UNUSED(SmoothCalibPeriod); |
537 | UNUSED(SmoothCalibPeriod); |
537 | UNUSED(SmoothCalibPlusPulses); |
538 | UNUSED(SmoothCalibPlusPulses); |
538 | |
539 | 539 | /* Check the parameters */ |
|
540 | /* Check the parameters */ |
540 | assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue)); |
541 | assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue)); |
541 | |
542 | 542 | /* Process Locked */ |
|
543 | /* Process Locked */ |
543 | __HAL_LOCK(hrtc); |
544 | __HAL_LOCK(hrtc); |
544 | |
545 | 545 | hrtc->State = HAL_RTC_STATE_BUSY; |
|
546 | hrtc->State = HAL_RTC_STATE_BUSY; |
546 | |
547 | 547 | /* Sets RTC Clock Calibration value.*/ |
|
548 | /* Sets RTC Clock Calibration value.*/ |
548 | MODIFY_REG(BKP->RTCCR, BKP_RTCCR_CAL, SmouthCalibMinusPulsesValue); |
549 | MODIFY_REG(BKP->RTCCR, BKP_RTCCR_CAL, SmouthCalibMinusPulsesValue); |
549 | |
550 | 550 | /* Change RTC state */ |
|
551 | /* Change RTC state */ |
551 | hrtc->State = HAL_RTC_STATE_READY; |
552 | hrtc->State = HAL_RTC_STATE_READY; |
552 | |
553 | 553 | /* Process Unlocked */ |
|
554 | /* Process Unlocked */ |
554 | __HAL_UNLOCK(hrtc); |
555 | __HAL_UNLOCK(hrtc); |
555 | |
556 | 556 | return HAL_OK; |
|
557 | return HAL_OK; |
557 | } |
558 | } |
558 | |
559 | 559 | /** |
|
560 | /** |
560 | * @} |
561 | * @} |
561 | */ |
562 | */ |
562 | |
563 | 563 | /** |
|
564 | /** |
564 | * @} |
565 | * @} |
565 | */ |
566 | */ |
566 | |
567 | 567 | /** |
|
568 | /** |
568 | * @} |
569 | * @} |
569 | */ |
570 | */ |
570 | |
571 | 571 | #endif /* HAL_RTC_MODULE_ENABLED */ |
|
572 | #endif /* HAL_RTC_MODULE_ENABLED */ |
572 | |
573 | 573 | /** |
|
574 | /** |
574 | * @} |
575 | * @} |
575 | */ |
576 | */ |
- | |
577 | - | ||
578 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
- | |
579 | - |