Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 61 | Rev 77 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32l1xx_hal_rtc.c |
3 | * @file stm32l1xx_hal_rtc.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief RTC HAL module driver. |
5 | * @brief 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) peripheral: |
7 | * functionalities of the Real-Time Clock (RTC) peripheral: |
8 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
9 | * + RTC Time and Date functions |
9 | * + RTC Calendar (Time and Date) configuration functions |
10 | * + RTC Alarm functions |
10 | * + RTC Alarms (Alarm A and Alarm B) configuration functions |
11 | * + Peripheral Control functions |
11 | * + Peripheral Control functions |
12 | * + Peripheral State functions |
12 | * + Peripheral State functions |
13 | * |
13 | * |
14 | @verbatim |
14 | ****************************************************************************** |
15 | =============================================================================== |
15 | * @attention |
16 | ##### RTC Operating Condition ##### |
16 | * |
17 | =============================================================================== |
17 | * Copyright (c) 2016 STMicroelectronics. |
18 | [..] The real-time clock (RTC) and the RTC backup registers can be powered |
18 | * All rights reserved. |
19 | from the VBAT voltage when the main VDD supply is powered off. |
19 | * |
20 | To retain the content of the RTC backup registers and supply the RTC |
20 | * This software is licensed under terms that can be found in the LICENSE file |
21 | when VDD is turned off, VBAT pin can be connected to an optional |
21 | * in the root directory of this software component. |
22 | standby voltage supplied by a battery or by another source. |
22 | * If no LICENSE file comes with this software, it is provided AS-IS. |
23 | 23 | * |
|
24 | [..] To allow the RTC operating even when the main digital supply (VDD) is turned |
24 | ****************************************************************************** |
25 | off, the VBAT pin powers the following blocks: |
25 | @verbatim |
26 | (#) The RTC |
26 | ============================================================================== |
27 | (#) The LSE oscillator |
27 | ##### RTC and Backup Domain Operating Condition ##### |
28 | (#) PC13 to PC15 I/Os (when available) |
28 | ============================================================================== |
29 | 29 | [..] The real-time clock (RTC) and the RTC backup registers can be powered |
|
30 | [..] When the backup domain is supplied by VDD (analog switch connected to VDD), |
30 | from the VBAT voltage when the main VDD supply is powered off. |
31 | the following pins are available: |
31 | To retain the content of the RTC backup registers and supply the RTC when |
32 | (#) PC14 and PC15 can be used as either GPIO or LSE pins |
32 | VDD is turned off, VBAT pin can be connected to an optional standby |
33 | (#) PC13 can be used as a GPIO or as the RTC_AF1 pin |
33 | voltage supplied by a battery or by another source. |
34 | 34 | ||
35 | [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT |
35 | [..] To allow the RTC operating even when the main digital supply (VDD) is turned |
36 | because VDD is not present), the following pins are available: |
36 | off, the VBAT pin powers the following blocks: |
37 | (#) PC14 and PC15 can be used as LSE pins only |
37 | (#) The RTC |
38 | (#) PC13 can be used as the RTC_AF1 pin |
38 | (#) The LSE oscillator |
39 | 39 | (#) PC13 to PC15 I/Os, plus PA0 and PE6 I/Os (when available) |
|
40 | ##### Backup Domain Reset ##### |
40 | |
41 | =============================================================================== |
41 | [..] When the backup domain is supplied by VDD (analog switch connected to VDD), |
42 | [..] The backup domain reset sets all RTC registers and the RCC_BDCR register |
42 | the following pins are available: |
43 | to their reset values. |
43 | (#) PC14 and PC15 can be used as either GPIO or LSE pins |
44 | [..] A backup domain reset is generated when one of the following events occurs: |
44 | (#) PC13 can be used as a GPIO or as the RTC_AF1 pin |
45 | (#) Software reset, triggered by setting the BDRST bit in the |
45 | (#) PA0 can be used as a GPIO or as the RTC_AF2 pin |
46 | RCC Backup domain control register (RCC_BDCR). |
46 | (#) PE6 can be used as a GPIO or as the RTC_AF3 pin |
47 | (#) VDD or VBAT power on, if both supplies have previously been powered off. |
47 | |
48 | 48 | [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT |
|
49 | ##### Backup Domain Access ##### |
49 | because VDD is not present), the following pins are available: |
50 | =================================================================== |
50 | (#) PC14 and PC15 can be used as LSE pins only |
51 | [..] After reset, the backup domain (RTC registers, RTC backup data |
51 | (#) PC13 can be used as the RTC_AF1 pin |
52 | registers and backup SRAM) is protected against possible unwanted write |
52 | (#) PA0 can be used as the RTC_AF2 pin |
53 | accesses. |
53 | (#) PE6 can be used as the RTC_AF3 pin |
54 | [..] To enable access to the RTC Domain and RTC registers, proceed as follows: |
54 | |
55 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
55 | ##### Backup Domain Reset ##### |
56 | __HAL_RCC_PWR_CLK_ENABLE() function. |
56 | ================================================================== |
57 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
57 | [..] The backup domain reset sets all RTC registers and the RCC_BDCR register |
58 | (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function. |
58 | to their reset values. |
59 | (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function. |
59 | [..] A backup domain reset is generated when one of the following events occurs: |
60 | 60 | (#) Software reset, triggered by setting the BDRST bit in the |
|
61 | 61 | RCC Backup domain control register (RCC_BDCR). |
|
62 | ##### How to use RTC Driver ##### |
62 | (#) VDD or VBAT power on, if both supplies have previously been powered off. |
63 | =================================================================== |
63 | |
64 | [..] |
64 | ##### Backup Domain Access ##### |
65 | (+) Enable the RTC domain access (see description in the section above). |
65 | ================================================================== |
66 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
66 | [..] After reset, the backup domain (RTC registers, RTC backup data registers |
67 | format using the HAL_RTC_Init() function. |
67 | is protected against possible unwanted write accesses. |
68 | 68 | [..] To enable access to the RTC Domain and RTC registers, proceed as follows: |
|
69 | *** Time and Date configuration *** |
69 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
70 | =================================== |
70 | __HAL_RCC_PWR_CLK_ENABLE() macro. |
71 | [..] |
71 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
72 | (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime() |
72 | (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() macro. |
73 | and HAL_RTC_SetDate() functions. |
73 | (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() macro. |
74 | (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions. |
74 | |
75 | 75 | ============================================================================== |
|
76 | *** Alarm configuration *** |
76 | ##### How to use this driver ##### |
77 | =========================== |
77 | ============================================================================== |
78 | [..] |
78 | [..] |
79 | (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function. |
79 | (+) Enable the RTC domain access (see description in the section above). |
80 | You can also configure the RTC Alarm with interrupt mode using the |
80 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
81 | HAL_RTC_SetAlarm_IT() function. |
81 | format using the HAL_RTC_Init() function. |
82 | (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function. |
82 | |
83 | 83 | *** Time and Date configuration *** |
|
84 | ##### RTC and low power modes ##### |
84 | =================================== |
85 | ================================================================== |
85 | [..] |
86 | [..] The MCU can be woken up from a low power mode by an RTC alternate |
86 | (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime() |
87 | function. |
87 | and HAL_RTC_SetDate() functions. |
88 | [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), |
88 | (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() |
89 | RTC wakeup, RTC tamper event detection and RTC time stamp event detection. |
89 | functions. |
90 | These RTC alternate functions can wake up the system from the Stop and |
90 | (+) To manage the RTC summer or winter time change, use the following |
91 | Standby low power modes. |
91 | functions: |
92 | [..] The system can also wake up from low power modes without depending |
92 | (++) HAL_RTC_DST_Add1Hour() or HAL_RTC_DST_Sub1Hour to add or subtract |
93 | on an external interrupt (Auto-wakeup mode), by using the RTC alarm |
93 | 1 hour from the calendar time. |
94 | or the RTC wakeup events. |
94 | (++) HAL_RTC_DST_SetStoreOperation() or HAL_RTC_DST_ClearStoreOperation |
95 | [..] The RTC provides a programmable time base for waking up from the |
95 | to memorize whether the time change has been performed or not. |
96 | Stop or Standby mode at regular intervals. |
96 | |
97 | Wakeup from STOP and STANDBY modes is possible only when the RTC clock source |
97 | *** Alarm configuration *** |
98 | is LSE or LSI. |
98 | =========================== |
99 | 99 | [..] |
|
100 | *** Callback registration *** |
100 | (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function. |
101 | ============================================= |
101 | You can also configure the RTC Alarm with interrupt mode using the |
102 | 102 | HAL_RTC_SetAlarm_IT() function. |
|
103 | [..] |
103 | (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function. |
104 | The compilation define USE_RTC_REGISTER_CALLBACKS when set to 1 |
104 | |
105 | allows the user to configure dynamically the driver callbacks. |
105 | ##### RTC and low power modes ##### |
106 | Use Function @ref HAL_RTC_RegisterCallback() to register an interrupt callback. |
106 | ================================================================== |
107 | 107 | [..] The MCU can be woken up from a low power mode by an RTC alternate |
|
108 | [..] |
108 | function. |
109 | Function @ref HAL_RTC_RegisterCallback() allows to register following callbacks: |
109 | [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), |
110 | (+) AlarmAEventCallback : RTC Alarm A Event callback. |
110 | RTC wakeup, RTC tamper event detection and RTC timestamp event detection. |
111 | (+) AlarmBEventCallback : RTC Alarm B Event callback. |
111 | These RTC alternate functions can wake up the system from the Stop and |
112 | (+) TimeStampEventCallback : RTC TimeStamp Event callback. |
112 | Standby low power modes. |
113 | (+) WakeUpTimerEventCallback : RTC WakeUpTimer Event callback. |
113 | [..] The system can also wake up from low power modes without depending |
114 | (+) Tamper1EventCallback : RTC Tamper 1 Event callback. |
114 | on an external interrupt (Auto-wakeup mode), by using the RTC alarm |
115 | (+) Tamper2EventCallback : RTC Tamper 2 Event callback. |
115 | or the RTC wakeup events. |
116 | (+) Tamper3EventCallback : RTC Tamper 3 Event callback. |
116 | [..] The RTC provides a programmable time base for waking up from the |
117 | (+) MspInitCallback : RTC MspInit callback. |
117 | Stop or Standby mode at regular intervals. |
118 | (+) MspDeInitCallback : RTC MspDeInit callback. |
118 | Wakeup from STOP and STANDBY modes is possible only when the RTC clock |
119 | [..] |
119 | source is LSE or LSI. |
120 | This function takes as parameters the HAL peripheral handle, the Callback ID |
120 | |
121 | and a pointer to the user callback function. |
121 | *** Callback registration *** |
122 | 122 | ============================================= |
|
123 | [..] |
123 | [..] |
124 | Use function @ref HAL_RTC_UnRegisterCallback() to reset a callback to the default |
124 | The compilation define USE_HAL_RTC_REGISTER_CALLBACKS when set to 1 |
125 | weak function. |
125 | allows the user to configure dynamically the driver callbacks. |
126 | @ref HAL_RTC_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
126 | Use Function HAL_RTC_RegisterCallback() to register an interrupt callback. |
127 | and the Callback ID. |
127 | [..] |
128 | This function allows to reset following callbacks: |
128 | Function HAL_RTC_RegisterCallback() allows to register following callbacks: |
129 | (+) AlarmAEventCallback : RTC Alarm A Event callback. |
129 | (+) AlarmAEventCallback : RTC Alarm A Event callback. |
130 | (+) AlarmBEventCallback : RTC Alarm B Event callback. |
130 | (+) AlarmBEventCallback : RTC Alarm B Event callback. |
131 | (+) TimeStampEventCallback : RTC TimeStamp Event callback. |
131 | (+) TimeStampEventCallback : RTC Timestamp Event callback. |
132 | (+) WakeUpTimerEventCallback : RTC WakeUpTimer Event callback. |
132 | (+) WakeUpTimerEventCallback : RTC WakeUpTimer Event callback. |
133 | (+) Tamper1EventCallback : RTC Tamper 1 Event callback. |
133 | (+) Tamper1EventCallback : RTC Tamper 1 Event callback. |
134 | (+) Tamper2EventCallback : RTC Tamper 2 Event callback. |
134 | (+) Tamper2EventCallback : RTC Tamper 2 Event callback. |
135 | (+) Tamper3EventCallback : RTC Tamper 3 Event callback. |
135 | (+) Tamper3EventCallback : RTC Tamper 3 Event callback. |
136 | (+) MspInitCallback : RTC MspInit callback. |
136 | (+) MspInitCallback : RTC MspInit callback. |
137 | (+) MspDeInitCallback : RTC MspDeInit callback. |
137 | (+) MspDeInitCallback : RTC MspDeInit callback. |
138 | 138 | [..] |
|
139 | [..] |
139 | This function takes as parameters the HAL peripheral handle, the Callback ID |
140 | By default, after the @ref HAL_RTC_Init() and when the state is HAL_RTC_STATE_RESET, |
140 | and a pointer to the user callback function. |
141 | all callbacks are set to the corresponding weak functions : |
141 | [..] |
142 | examples @ref AlarmAEventCallback(), @ref WakeUpTimerEventCallback(). |
142 | Use function HAL_RTC_UnRegisterCallback() to reset a callback to the default |
143 | Exception done for MspInit and MspDeInit callbacks that are reset to the legacy weak function |
143 | weak function. |
144 | in the @ref HAL_RTC_Init()/@ref HAL_RTC_DeInit() only when these callbacks are null |
144 | HAL_RTC_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
145 | (not registered beforehand). |
145 | and the Callback ID. |
146 | If not, MspInit or MspDeInit are not null, @ref HAL_RTC_Init()/@ref HAL_RTC_DeInit() |
146 | This function allows to reset following callbacks: |
147 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) |
147 | (+) AlarmAEventCallback : RTC Alarm A Event callback. |
148 | 148 | (+) AlarmBEventCallback : RTC Alarm B Event callback. |
|
149 | [..] |
149 | (+) TimeStampEventCallback : RTC Timestamp Event callback. |
150 | Callbacks can be registered/unregistered in HAL_RTC_STATE_READY state only. |
150 | (+) WakeUpTimerEventCallback : RTC WakeUpTimer Event callback. |
151 | Exception done MspInit/MspDeInit that can be registered/unregistered |
151 | (+) Tamper1EventCallback : RTC Tamper 1 Event callback. |
152 | in HAL_RTC_STATE_READY or HAL_RTC_STATE_RESET state, |
152 | (+) Tamper2EventCallback : RTC Tamper 2 Event callback. |
153 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
153 | (+) Tamper3EventCallback : RTC Tamper 3 Event callback. |
154 | In that case first register the MspInit/MspDeInit user callbacks |
154 | (+) MspInitCallback : RTC MspInit callback. |
155 | using @ref HAL_RTC_RegisterCallback() before calling @ref HAL_RTC_DeInit() |
155 | (+) MspDeInitCallback : RTC MspDeInit callback. |
156 | or @ref HAL_RTC_Init() function. |
156 | [..] |
157 | 157 | By default, after the HAL_RTC_Init() and when the state is HAL_RTC_STATE_RESET, |
|
158 | [..] |
158 | all callbacks are set to the corresponding weak functions: |
159 | When The compilation define USE_HAL_RTC_REGISTER_CALLBACKS is set to 0 or |
159 | examples AlarmAEventCallback(), WakeUpTimerEventCallback(). |
160 | not defined, the callback registration feature is not available and all callbacks |
160 | Exception done for MspInit() and MspDeInit() callbacks that are reset to the |
161 | are set to the corresponding weak functions. |
161 | legacy weak function in the HAL_RTC_Init()/HAL_RTC_DeInit() only |
162 | 162 | when these callbacks are null (not registered beforehand). |
|
163 | @endverbatim |
163 | If not, MspInit() or MspDeInit() are not null, HAL_RTC_Init()/HAL_RTC_DeInit() |
164 | ****************************************************************************** |
164 | keep and use the user MspInit()/MspDeInit() callbacks (registered beforehand). |
165 | * @attention |
165 | [..] |
166 | * |
166 | Callbacks can be registered/unregistered in HAL_RTC_STATE_READY state only. |
167 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
167 | Exception done MspInit()/MspDeInit() that can be registered/unregistered |
168 | * All rights reserved.</center></h2> |
168 | in HAL_RTC_STATE_READY or HAL_RTC_STATE_RESET state. |
169 | * |
169 | Thus registered (user) MspInit()/MspDeInit() callbacks can be used during the |
170 | * This software component is licensed by ST under BSD 3-Clause license, |
170 | Init/DeInit. |
171 | * the "License"; You may not use this file except in compliance with the |
171 | In that case first register the MspInit()/MspDeInit() user callbacks |
172 | * License. You may obtain a copy of the License at: |
172 | using HAL_RTC_RegisterCallback() before calling HAL_RTC_DeInit() |
173 | * opensource.org/licenses/BSD-3-Clause |
173 | or HAL_RTC_Init() functions. |
174 | * |
174 | [..] |
175 | ****************************************************************************** |
175 | When The compilation define USE_HAL_RTC_REGISTER_CALLBACKS is set to 0 or |
176 | */ |
176 | not defined, the callback registration feature is not available and all |
177 | 177 | callbacks are set to the corresponding weak functions. |
|
178 | /* Includes ------------------------------------------------------------------*/ |
178 | |
179 | #include "stm32l1xx_hal.h" |
179 | @endverbatim |
180 | 180 | ****************************************************************************** |
|
181 | /** @addtogroup STM32L1xx_HAL_Driver |
181 | */ |
182 | * @{ |
182 | |
183 | */ |
183 | /* Includes ------------------------------------------------------------------*/ |
184 | 184 | #include "stm32l1xx_hal.h" |
|
185 | 185 | ||
186 | /** @addtogroup RTC |
186 | /** @addtogroup STM32L1xx_HAL_Driver |
187 | * @brief RTC HAL module driver |
187 | * @{ |
188 | * @{ |
188 | */ |
189 | */ |
189 | |
190 | 190 | /** @defgroup RTC RTC |
|
191 | #ifdef HAL_RTC_MODULE_ENABLED |
191 | * @brief RTC HAL module driver |
192 | 192 | * @{ |
|
193 | /* Private typedef -----------------------------------------------------------*/ |
193 | */ |
194 | /* Private define ------------------------------------------------------------*/ |
194 | |
195 | /* Private macro -------------------------------------------------------------*/ |
195 | #ifdef HAL_RTC_MODULE_ENABLED |
196 | /* Private variables ---------------------------------------------------------*/ |
196 | |
197 | /* Private function prototypes -----------------------------------------------*/ |
197 | /* Private typedef -----------------------------------------------------------*/ |
198 | /* Exported functions --------------------------------------------------------*/ |
198 | /* Private define ------------------------------------------------------------*/ |
199 | 199 | /* Private macro -------------------------------------------------------------*/ |
|
200 | /** @addtogroup RTC_Exported_Functions |
200 | /* Private variables ---------------------------------------------------------*/ |
201 | * @{ |
201 | /* Private function prototypes -----------------------------------------------*/ |
202 | */ |
202 | /* Exported functions --------------------------------------------------------*/ |
203 | 203 | ||
204 | /** @addtogroup RTC_Exported_Functions_Group1 |
204 | /** @defgroup RTC_Exported_Functions RTC Exported Functions |
205 | * @brief Initialization and Configuration functions |
205 | * @{ |
206 | * |
206 | */ |
207 | @verbatim |
207 | |
208 | =============================================================================== |
208 | /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions |
209 | ##### Initialization and de-initialization functions ##### |
209 | * @brief Initialization and Configuration functions |
210 | =============================================================================== |
210 | * |
211 | [..] This section provides functions allowing to initialize and configure the |
211 | @verbatim |
212 | RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable |
212 | =============================================================================== |
213 | RTC registers Write protection, enter and exit the RTC initialization mode, |
213 | ##### Initialization and de-initialization functions ##### |
214 | RTC registers synchronization check and reference clock detection enable. |
214 | =============================================================================== |
215 | (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. |
215 | [..] This section provides functions allowing to initialize and configure the |
216 | It is split into 2 programmable prescalers to minimize power consumption. |
216 | RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable |
217 | (++) A 7-bit asynchronous prescaler and a 13-bit synchronous prescaler. |
217 | RTC registers Write protection, enter and exit the RTC initialization mode, |
218 | (++) When both prescalers are used, it is recommended to configure the |
218 | RTC registers synchronization check and reference clock detection enable. |
219 | asynchronous prescaler to a high value to minimize power consumption. |
219 | (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. |
220 | (#) All RTC registers are Write protected. Writing to the RTC registers |
220 | It is split into 2 programmable prescalers to minimize power consumption. |
221 | is enabled by writing a key into the Write Protection register, RTC_WPR. |
221 | (++) A 7-bit asynchronous prescaler and a 15-bit synchronous prescaler. |
222 | (#) To configure the RTC Calendar, user application should enter |
222 | (++) When both prescalers are used, it is recommended to configure the |
223 | initialization mode. In this mode, the calendar counter is stopped |
223 | asynchronous prescaler to a high value to minimize power consumption. |
224 | and its value can be updated. When the initialization sequence is |
224 | (#) All RTC registers are Write protected. Writing to the RTC registers |
225 | complete, the calendar restarts counting after 4 RTCCLK cycles. |
225 | is enabled by writing a key into the Write Protection register, RTC_WPR. |
226 | (#) To read the calendar through the shadow registers after Calendar |
226 | (#) To configure the RTC Calendar, user application should enter |
227 | initialization, calendar update or after wakeup from low power modes |
227 | initialization mode. In this mode, the calendar counter is stopped |
228 | the software must first clear the RSF flag. The software must then |
228 | and its value can be updated. When the initialization sequence is |
229 | wait until it is set again before reading the calendar, which means |
229 | complete, the calendar restarts counting after 4 RTCCLK cycles. |
230 | that the calendar registers have been correctly copied into the |
230 | (#) To read the calendar through the shadow registers after Calendar |
231 | RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function |
231 | initialization, calendar update or after wakeup from low power modes |
232 | implements the above software sequence (RSF clear and RSF check). |
232 | the software must first clear the RSF flag. The software must then |
233 | 233 | wait until it is set again before reading the calendar, which means |
|
234 | @endverbatim |
234 | that the calendar registers have been correctly copied into the |
235 | * @{ |
235 | RTC_TR and RTC_DR shadow registers. The HAL_RTC_WaitForSynchro() function |
236 | */ |
236 | implements the above software sequence (RSF clear and RSF check). |
237 | 237 | ||
238 | /** |
238 | @endverbatim |
239 | * @brief Initialize the RTC peripheral |
239 | * @{ |
240 | * @param hrtc RTC handle |
240 | */ |
241 | * @retval HAL status |
241 | |
242 | */ |
242 | /** |
243 | HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc) |
243 | * @brief Initializes the RTC peripheral |
244 | { |
244 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
245 | /* Check the RTC peripheral state */ |
245 | * the configuration information for RTC. |
246 | if (hrtc == NULL) |
246 | * @retval HAL status |
247 | { |
247 | */ |
248 | return HAL_ERROR; |
248 | HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc) |
249 | } |
249 | { |
250 | 250 | HAL_StatusTypeDef status = HAL_ERROR; |
|
251 | /* Check the parameters */ |
251 | |
252 | assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance)); |
252 | /* Check RTC handler validity */ |
253 | assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat)); |
253 | if (hrtc == NULL) |
254 | assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv)); |
254 | { |
255 | assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv)); |
255 | return HAL_ERROR; |
256 | assert_param(IS_RTC_OUTPUT(hrtc->Init.OutPut)); |
256 | } |
257 | assert_param(IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity)); |
257 | |
258 | assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType)); |
258 | /* Check the parameters */ |
259 | 259 | assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance)); |
|
260 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
260 | assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat)); |
261 | if (hrtc->State == HAL_RTC_STATE_RESET) |
261 | assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv)); |
262 | { |
262 | assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv)); |
263 | /* Allocate lock resource and initialize it */ |
263 | assert_param(IS_RTC_OUTPUT(hrtc->Init.OutPut)); |
264 | hrtc->Lock = HAL_UNLOCKED; |
264 | assert_param(IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity)); |
265 | 265 | assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType)); |
|
266 | hrtc->AlarmAEventCallback = HAL_RTC_AlarmAEventCallback; /* Legacy weak AlarmAEventCallback */ |
266 | |
267 | hrtc->AlarmBEventCallback = HAL_RTCEx_AlarmBEventCallback; /* Legacy weak AlarmBEventCallback */ |
267 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
268 | hrtc->TimeStampEventCallback = HAL_RTCEx_TimeStampEventCallback; /* Legacy weak TimeStampEventCallback */ |
268 | if (hrtc->State == HAL_RTC_STATE_RESET) |
269 | hrtc->WakeUpTimerEventCallback = HAL_RTCEx_WakeUpTimerEventCallback; /* Legacy weak WakeUpTimerEventCallback */ |
269 | { |
270 | hrtc->Tamper1EventCallback = HAL_RTCEx_Tamper1EventCallback; /* Legacy weak Tamper1EventCallback */ |
270 | /* Allocate lock resource and initialize it */ |
271 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
271 | hrtc->Lock = HAL_UNLOCKED; |
272 | hrtc->Tamper2EventCallback = HAL_RTCEx_Tamper2EventCallback; /* Legacy weak Tamper2EventCallback */ |
272 | |
273 | hrtc->Tamper3EventCallback = HAL_RTCEx_Tamper3EventCallback; /* Legacy weak Tamper3EventCallback */ |
273 | hrtc->AlarmAEventCallback = HAL_RTC_AlarmAEventCallback; /* Legacy weak AlarmAEventCallback */ |
274 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
274 | hrtc->AlarmBEventCallback = HAL_RTCEx_AlarmBEventCallback; /* Legacy weak AlarmBEventCallback */ |
275 | 275 | hrtc->TimeStampEventCallback = HAL_RTCEx_TimeStampEventCallback; /* Legacy weak TimeStampEventCallback */ |
|
276 | if (hrtc->MspInitCallback == NULL) |
276 | hrtc->WakeUpTimerEventCallback = HAL_RTCEx_WakeUpTimerEventCallback; /* Legacy weak WakeUpTimerEventCallback */ |
277 | { |
277 | hrtc->Tamper1EventCallback = HAL_RTCEx_Tamper1EventCallback; /* Legacy weak Tamper1EventCallback */ |
278 | hrtc->MspInitCallback = HAL_RTC_MspInit; |
278 | #if defined(RTC_TAMPER2_SUPPORT) |
279 | } |
279 | hrtc->Tamper2EventCallback = HAL_RTCEx_Tamper2EventCallback; /* Legacy weak Tamper2EventCallback */ |
280 | /* Init the low level hardware */ |
280 | #endif /* RTC_TAMPER2_SUPPORT */ |
281 | hrtc->MspInitCallback(hrtc); |
281 | #if defined(RTC_TAMPER3_SUPPORT) |
282 | 282 | hrtc->Tamper3EventCallback = HAL_RTCEx_Tamper3EventCallback; /* Legacy weak Tamper3EventCallback */ |
|
283 | if (hrtc->MspDeInitCallback == NULL) |
283 | #endif /* RTC_TAMPER3_SUPPORT */ |
284 | { |
284 | |
285 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
285 | if (hrtc->MspInitCallback == NULL) |
286 | } |
286 | { |
287 | } |
287 | hrtc->MspInitCallback = HAL_RTC_MspInit; |
288 | #else |
288 | } |
289 | if (hrtc->State == HAL_RTC_STATE_RESET) |
289 | /* Init the low level hardware */ |
290 | { |
290 | hrtc->MspInitCallback(hrtc); |
291 | /* Allocate lock resource and initialize it */ |
291 | |
292 | hrtc->Lock = HAL_UNLOCKED; |
292 | if (hrtc->MspDeInitCallback == NULL) |
293 | 293 | { |
|
294 | /* Initialize RTC MSP */ |
294 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
295 | HAL_RTC_MspInit(hrtc); |
295 | } |
296 | } |
296 | } |
297 | #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ |
297 | #else /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
298 | 298 | if (hrtc->State == HAL_RTC_STATE_RESET) |
|
299 | /* Set RTC state */ |
299 | { |
300 | hrtc->State = HAL_RTC_STATE_BUSY; |
300 | /* Allocate lock resource and initialize it */ |
301 | 301 | hrtc->Lock = HAL_UNLOCKED; |
|
302 | /* Disable the write protection for RTC registers */ |
302 | |
303 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
303 | /* Initialize RTC MSP */ |
304 | 304 | HAL_RTC_MspInit(hrtc); |
|
305 | /* Set Initialization mode */ |
305 | } |
306 | if (RTC_EnterInitMode(hrtc) != HAL_OK) |
306 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
307 | { |
307 | |
308 | /* Enable the write protection for RTC registers */ |
308 | /* Set RTC state */ |
309 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
309 | hrtc->State = HAL_RTC_STATE_BUSY; |
310 | 310 | ||
311 | /* Set RTC state */ |
311 | /* Check whether the calendar needs to be initialized */ |
312 | hrtc->State = HAL_RTC_STATE_ERROR; |
312 | if (__HAL_RTC_IS_CALENDAR_INITIALIZED(hrtc) == 0U) |
313 | 313 | { |
|
314 | return HAL_ERROR; |
314 | /* Disable the write protection for RTC registers */ |
315 | } |
315 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
316 | else |
316 | |
317 | { |
317 | /* Enter Initialization mode */ |
318 | /* Clear RTC_CR FMT, OSEL and POL Bits */ |
318 | status = RTC_EnterInitMode(hrtc); |
319 | hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL)); |
319 | |
320 | /* Set RTC_CR register */ |
320 | if (status == HAL_OK) |
321 | hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity); |
321 | { |
322 | 322 | /* Clear RTC_CR FMT, OSEL and POL Bits */ |
|
323 | /* Configure the RTC PRER */ |
323 | hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL)); |
324 | hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv); |
324 | /* Set RTC_CR register */ |
325 | hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16U); |
325 | hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity); |
326 | 326 | ||
327 | /* Exit Initialization mode */ |
327 | /* Configure the RTC PRER */ |
328 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
328 | hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv); |
329 | #if defined (RTC_CR_BYPSHAD) |
329 | hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << RTC_PRER_PREDIV_A_Pos); |
330 | /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
330 | |
331 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
331 | /* Exit Initialization mode */ |
332 | #endif /* RTC_CR_BYPSHAD */ |
332 | status = RTC_ExitInitMode(hrtc); |
333 | { |
333 | } |
334 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
334 | |
335 | { |
335 | if (status == HAL_OK) |
336 | /* Enable the write protection for RTC registers */ |
336 | { |
337 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
337 | hrtc->Instance->TAFCR &= (uint32_t)~RTC_OUTPUT_TYPE_PUSHPULL; |
338 | 338 | hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType); |
|
339 | hrtc->State = HAL_RTC_STATE_ERROR; |
339 | } |
340 | 340 | ||
341 | return HAL_ERROR; |
341 | /* Enable the write protection for RTC registers */ |
342 | } |
342 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
343 | } |
343 | } |
344 | hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE; |
344 | else |
345 | hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType); |
345 | { |
346 | 346 | /* The calendar is already initialized */ |
|
347 | /* Enable the write protection for RTC registers */ |
347 | status = HAL_OK; |
348 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
348 | } |
349 | 349 | ||
350 | /* Set RTC state */ |
350 | if (status == HAL_OK) |
351 | hrtc->State = HAL_RTC_STATE_READY; |
351 | { |
352 | 352 | hrtc->State = HAL_RTC_STATE_READY; |
|
353 | return HAL_OK; |
353 | } |
354 | } |
354 | |
355 | } |
355 | return status; |
356 | 356 | } |
|
357 | /** |
357 | |
358 | * @brief DeInitialize the RTC peripheral. |
358 | /** |
359 | * @param hrtc RTC handle |
359 | * @brief DeInitializes the RTC peripheral |
360 | * @note This function does not reset the RTC Backup Data registers. |
360 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
361 | * @retval HAL status |
361 | * the configuration information for RTC. |
362 | */ |
362 | * @note This function does not reset the RTC Backup Data registers. |
363 | HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) |
363 | * @retval HAL status |
364 | { |
364 | */ |
365 | uint32_t tickstart; |
365 | HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) |
366 | 366 | { |
|
367 | /* Check the parameters */ |
367 | HAL_StatusTypeDef status = HAL_ERROR; |
368 | assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance)); |
368 | |
369 | 369 | /* Check the parameters */ |
|
370 | /* Set RTC state */ |
370 | assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance)); |
371 | hrtc->State = HAL_RTC_STATE_BUSY; |
371 | |
372 | 372 | /* Set RTC state */ |
|
373 | /* Disable the write protection for RTC registers */ |
373 | hrtc->State = HAL_RTC_STATE_BUSY; |
374 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
374 | |
375 | 375 | /* Disable the write protection for RTC registers */ |
|
376 | /* Set Initialization mode */ |
376 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
377 | if (RTC_EnterInitMode(hrtc) != HAL_OK) |
377 | |
378 | { |
378 | /* Enter Initialization mode */ |
379 | /* Enable the write protection for RTC registers */ |
379 | status = RTC_EnterInitMode(hrtc); |
380 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
380 | |
381 | 381 | if (status == HAL_OK) |
|
382 | /* Set RTC state */ |
382 | { |
383 | hrtc->State = HAL_RTC_STATE_ERROR; |
383 | /* Reset RTC registers */ |
384 | 384 | hrtc->Instance->TR = 0x00000000U; |
|
385 | return HAL_ERROR; |
385 | hrtc->Instance->DR = (RTC_DR_WDU_0 | RTC_DR_MU_0 | RTC_DR_DU_0); |
386 | } |
386 | hrtc->Instance->CR &= 0x00000000U; |
387 | else |
387 | hrtc->Instance->WUTR = RTC_WUTR_WUT; |
388 | { |
388 | hrtc->Instance->PRER = (uint32_t)(RTC_PRER_PREDIV_A | 0x000000FFU); |
389 | /* Reset TR, DR and CR registers */ |
389 | hrtc->Instance->CALIBR = 0x00000000U; |
390 | hrtc->Instance->TR = 0x00000000U; |
390 | hrtc->Instance->ALRMAR = 0x00000000U; |
391 | hrtc->Instance->DR = 0x00002101U; |
391 | hrtc->Instance->ALRMBR = 0x00000000U; |
392 | /* Reset All CR bits except CR[2:0] */ |
392 | #if defined(RTC_SMOOTHCALIB_SUPPORT) |
393 | hrtc->Instance->CR &= 0x00000007U; |
393 | hrtc->Instance->CALR = 0x00000000U; |
394 | 394 | #endif /* RTC_SMOOTHCALIB_SUPPORT */ |
|
395 | tickstart = HAL_GetTick(); |
395 | #if defined(RTC_SUBSECOND_SUPPORT) |
396 | 396 | hrtc->Instance->SHIFTR = 0x00000000U; |
|
397 | /* Wait till WUTWF flag is set and if Time out is reached exit */ |
397 | hrtc->Instance->ALRMASSR = 0x00000000U; |
398 | while (((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == 0U) |
398 | hrtc->Instance->ALRMBSSR = 0x00000000U; |
399 | { |
399 | #endif /* RTC_SUBSECOND_SUPPORT */ |
400 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
400 | |
401 | { |
401 | /* Exit Initialization mode */ |
402 | /* Enable the write protection for RTC registers */ |
402 | status = RTC_ExitInitMode(hrtc); |
403 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
403 | } |
404 | 404 | ||
405 | /* Set RTC state */ |
405 | /* Enable the write protection for RTC registers */ |
406 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
406 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
407 | 407 | ||
408 | return HAL_TIMEOUT; |
408 | if (status == HAL_OK) |
409 | } |
409 | { |
410 | } |
410 | /* Reset Tamper and alternate functions configuration register */ |
411 | 411 | hrtc->Instance->TAFCR = 0x00000000U; |
|
412 | /* Reset all RTC CR register bits */ |
412 | |
413 | hrtc->Instance->CR &= 0x00000000U; |
413 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
414 | hrtc->Instance->WUTR = 0x0000FFFFU; |
414 | if (hrtc->MspDeInitCallback == NULL) |
415 | hrtc->Instance->PRER = 0x007F00FFU; |
415 | { |
416 | hrtc->Instance->CALIBR = 0x00000000U; |
416 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
417 | hrtc->Instance->ALRMAR = 0x00000000U; |
417 | } |
418 | hrtc->Instance->ALRMBR = 0x00000000U; |
418 | |
419 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
419 | /* DeInit the low level hardware: CLOCK, NVIC.*/ |
420 | hrtc->Instance->SHIFTR = 0x00000000U; |
420 | hrtc->MspDeInitCallback(hrtc); |
421 | hrtc->Instance->CALR = 0x00000000U; |
421 | #else /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
422 | hrtc->Instance->ALRMASSR = 0x00000000U; |
422 | /* De-Initialize RTC MSP */ |
423 | hrtc->Instance->ALRMBSSR = 0x00000000U; |
423 | HAL_RTC_MspDeInit(hrtc); |
424 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
424 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
425 | /* Reset ISR register and exit initialization mode */ |
425 | |
426 | hrtc->Instance->ISR = 0x00000000U; |
426 | hrtc->State = HAL_RTC_STATE_RESET; |
427 | 427 | } |
|
428 | /* Reset Tamper and alternate functions configuration register */ |
428 | |
429 | hrtc->Instance->TAFCR = 0x00000000U; |
429 | /* Release Lock */ |
430 | 430 | __HAL_UNLOCK(hrtc); |
|
431 | /* Wait for synchro */ |
431 | |
432 | if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
432 | return status; |
433 | { |
433 | } |
434 | /* Enable the write protection for RTC registers */ |
434 | |
435 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
435 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
436 | 436 | /** |
|
437 | hrtc->State = HAL_RTC_STATE_ERROR; |
437 | * @brief Registers a User RTC Callback |
438 | 438 | * To be used instead of the weak predefined callback |
|
439 | return HAL_ERROR; |
439 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
440 | } |
440 | * the configuration information for RTC. |
441 | } |
441 | * @param CallbackID ID of the callback to be registered |
442 | 442 | * This parameter can be one of the following values: |
|
443 | /* Enable the write protection for RTC registers */ |
443 | * @arg @ref HAL_RTC_ALARM_A_EVENT_CB_ID Alarm A Event Callback ID |
444 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
444 | * @arg @ref HAL_RTC_ALARM_B_EVENT_CB_ID Alarm B Event Callback ID |
445 | 445 | * @arg @ref HAL_RTC_TIMESTAMP_EVENT_CB_ID Timestamp Event Callback ID |
|
446 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
446 | * @arg @ref HAL_RTC_WAKEUPTIMER_EVENT_CB_ID Wakeup Timer Event Callback ID |
447 | if (hrtc->MspDeInitCallback == NULL) |
447 | * @arg @ref HAL_RTC_TAMPER1_EVENT_CB_ID Tamper 1 Callback ID |
448 | { |
448 | * @arg @ref HAL_RTC_TAMPER2_EVENT_CB_ID Tamper 2 Callback ID |
449 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
449 | * @arg @ref HAL_RTC_TAMPER3_EVENT_CB_ID Tamper 3 Callback ID |
450 | } |
450 | * @arg @ref HAL_RTC_MSPINIT_CB_ID Msp Init callback ID |
451 | 451 | * @arg @ref HAL_RTC_MSPDEINIT_CB_ID Msp DeInit callback ID |
|
452 | /* DeInit the low level hardware: CLOCK, NVIC.*/ |
452 | * @note HAL_RTC_TAMPER2_EVENT_CB_ID is not applicable to all devices. |
453 | hrtc->MspDeInitCallback(hrtc); |
453 | * @note HAL_RTC_TAMPER3_EVENT_CB_ID is not applicable to all devices. |
454 | 454 | * @param pCallback pointer to the Callback function |
|
455 | #else |
455 | * @retval HAL status |
456 | /* De-Initialize RTC MSP */ |
456 | */ |
457 | HAL_RTC_MspDeInit(hrtc); |
457 | HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback) |
458 | #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ |
458 | { |
459 | 459 | HAL_StatusTypeDef status = HAL_OK; |
|
460 | hrtc->State = HAL_RTC_STATE_RESET; |
460 | |
461 | 461 | if (pCallback == NULL) |
|
462 | /* Release Lock */ |
462 | { |
463 | __HAL_UNLOCK(hrtc); |
463 | return HAL_ERROR; |
464 | 464 | } |
|
465 | return HAL_OK; |
465 | |
466 | } |
466 | /* Process locked */ |
467 | 467 | __HAL_LOCK(hrtc); |
|
468 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
468 | |
469 | /** |
469 | if (HAL_RTC_STATE_READY == hrtc->State) |
470 | * @brief Register a User RTC Callback |
470 | { |
471 | * To be used instead of the weak predefined callback |
471 | switch (CallbackID) |
472 | * @param hrtc RTC handle |
472 | { |
473 | * @param CallbackID ID of the callback to be registered |
473 | case HAL_RTC_ALARM_A_EVENT_CB_ID : |
474 | * This parameter can be one of the following values: |
474 | hrtc->AlarmAEventCallback = pCallback; |
475 | * @arg @ref HAL_RTC_ALARM_A_EVENT_CB_ID Alarm A Event Callback ID |
475 | break; |
476 | * @arg @ref HAL_RTC_ALARM_B_EVENT_CB_ID Alarm B Event Callback ID |
476 | |
477 | * @arg @ref HAL_RTC_TIMESTAMP_EVENT_CB_ID TimeStamp Event Callback ID |
477 | case HAL_RTC_ALARM_B_EVENT_CB_ID : |
478 | * @arg @ref HAL_RTC_WAKEUPTIMER_EVENT_CB_ID WakeUp Timer Event Callback ID |
478 | hrtc->AlarmBEventCallback = pCallback; |
479 | * @arg @ref HAL_RTC_TAMPER1_EVENT_CB_ID Tamper 1 Callback ID |
479 | break; |
480 | * @arg @ref HAL_RTC_TAMPER2_EVENT_CB_ID Tamper 2 Callback ID |
480 | |
481 | * @arg @ref HAL_RTC_TAMPER3_EVENT_CB_ID Tamper 3 Callback ID |
481 | case HAL_RTC_TIMESTAMP_EVENT_CB_ID : |
482 | * @arg @ref HAL_RTC_MSPINIT_CB_ID Msp Init callback ID |
482 | hrtc->TimeStampEventCallback = pCallback; |
483 | * @arg @ref HAL_RTC_MSPDEINIT_CB_ID Msp DeInit callback ID |
483 | break; |
484 | * @param pCallback pointer to the Callback function |
484 | |
485 | * @retval HAL status |
485 | case HAL_RTC_WAKEUPTIMER_EVENT_CB_ID : |
486 | */ |
486 | hrtc->WakeUpTimerEventCallback = pCallback; |
487 | HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback) |
487 | break; |
488 | { |
488 | |
489 | HAL_StatusTypeDef status = HAL_OK; |
489 | case HAL_RTC_TAMPER1_EVENT_CB_ID : |
490 | 490 | hrtc->Tamper1EventCallback = pCallback; |
|
491 | if (pCallback == NULL) |
491 | break; |
492 | { |
492 | |
493 | return HAL_ERROR; |
493 | #if defined(RTC_TAMPER2_SUPPORT) |
494 | } |
494 | case HAL_RTC_TAMPER2_EVENT_CB_ID : |
495 | 495 | hrtc->Tamper2EventCallback = pCallback; |
|
496 | /* Process locked */ |
496 | break; |
497 | __HAL_LOCK(hrtc); |
497 | #endif /* RTC_TAMPER2_SUPPORT */ |
498 | 498 | ||
499 | if (HAL_RTC_STATE_READY == hrtc->State) |
499 | #if defined(RTC_TAMPER3_SUPPORT) |
500 | { |
500 | case HAL_RTC_TAMPER3_EVENT_CB_ID : |
501 | switch (CallbackID) |
501 | hrtc->Tamper3EventCallback = pCallback; |
502 | { |
502 | break; |
503 | case HAL_RTC_ALARM_A_EVENT_CB_ID : |
503 | #endif /* RTC_TAMPER3_SUPPORT */ |
504 | hrtc->AlarmAEventCallback = pCallback; |
504 | |
505 | break; |
505 | case HAL_RTC_MSPINIT_CB_ID : |
506 | 506 | hrtc->MspInitCallback = pCallback; |
|
507 | case HAL_RTC_ALARM_B_EVENT_CB_ID : |
507 | break; |
508 | hrtc->AlarmBEventCallback = pCallback; |
508 | |
509 | break; |
509 | case HAL_RTC_MSPDEINIT_CB_ID : |
510 | 510 | hrtc->MspDeInitCallback = pCallback; |
|
511 | case HAL_RTC_TIMESTAMP_EVENT_CB_ID : |
511 | break; |
512 | hrtc->TimeStampEventCallback = pCallback; |
512 | |
513 | break; |
513 | default : |
514 | 514 | /* Return error status */ |
|
515 | case HAL_RTC_WAKEUPTIMER_EVENT_CB_ID : |
515 | status = HAL_ERROR; |
516 | hrtc->WakeUpTimerEventCallback = pCallback; |
516 | break; |
517 | break; |
517 | } |
518 | 518 | } |
|
519 | case HAL_RTC_TAMPER1_EVENT_CB_ID : |
519 | else if (HAL_RTC_STATE_RESET == hrtc->State) |
520 | hrtc->Tamper1EventCallback = pCallback; |
520 | { |
521 | break; |
521 | switch (CallbackID) |
522 | 522 | { |
|
523 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
523 | case HAL_RTC_MSPINIT_CB_ID : |
524 | case HAL_RTC_TAMPER2_EVENT_CB_ID : |
524 | hrtc->MspInitCallback = pCallback; |
525 | hrtc->Tamper2EventCallback = pCallback; |
525 | break; |
526 | break; |
526 | |
527 | 527 | case HAL_RTC_MSPDEINIT_CB_ID : |
|
528 | case HAL_RTC_TAMPER3_EVENT_CB_ID : |
528 | hrtc->MspDeInitCallback = pCallback; |
529 | hrtc->Tamper3EventCallback = pCallback; |
529 | break; |
530 | break; |
530 | |
531 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
531 | default : |
532 | 532 | /* Return error status */ |
|
533 | case HAL_RTC_MSPINIT_CB_ID : |
533 | status = HAL_ERROR; |
534 | hrtc->MspInitCallback = pCallback; |
534 | break; |
535 | break; |
535 | } |
536 | 536 | } |
|
537 | case HAL_RTC_MSPDEINIT_CB_ID : |
537 | else |
538 | hrtc->MspDeInitCallback = pCallback; |
538 | { |
539 | break; |
539 | /* Return error status */ |
540 | 540 | status = HAL_ERROR; |
|
541 | default : |
541 | } |
542 | /* Return error status */ |
542 | |
543 | status = HAL_ERROR; |
543 | /* Release Lock */ |
544 | break; |
544 | __HAL_UNLOCK(hrtc); |
545 | } |
545 | |
546 | } |
546 | return status; |
547 | else if (HAL_RTC_STATE_RESET == hrtc->State) |
547 | } |
548 | { |
548 | |
549 | switch (CallbackID) |
549 | /** |
550 | { |
550 | * @brief Unregisters an RTC Callback |
551 | case HAL_RTC_MSPINIT_CB_ID : |
551 | * RTC callback is redirected to the weak predefined callback |
552 | hrtc->MspInitCallback = pCallback; |
552 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
553 | break; |
553 | * the configuration information for RTC. |
554 | 554 | * @param CallbackID ID of the callback to be unregistered |
|
555 | case HAL_RTC_MSPDEINIT_CB_ID : |
555 | * This parameter can be one of the following values: |
556 | hrtc->MspDeInitCallback = pCallback; |
556 | * @arg @ref HAL_RTC_ALARM_A_EVENT_CB_ID Alarm A Event Callback ID |
557 | break; |
557 | * @arg @ref HAL_RTC_ALARM_B_EVENT_CB_ID Alarm B Event Callback ID |
558 | 558 | * @arg @ref HAL_RTC_TIMESTAMP_EVENT_CB_ID Timestamp Event Callback ID |
|
559 | default : |
559 | * @arg @ref HAL_RTC_WAKEUPTIMER_EVENT_CB_ID Wakeup Timer Event Callback ID |
560 | /* Return error status */ |
560 | * @arg @ref HAL_RTC_TAMPER1_EVENT_CB_ID Tamper 1 Callback ID |
561 | status = HAL_ERROR; |
561 | * @arg @ref HAL_RTC_TAMPER2_EVENT_CB_ID Tamper 2 Callback ID |
562 | break; |
562 | * @arg @ref HAL_RTC_TAMPER3_EVENT_CB_ID Tamper 3 Callback ID |
563 | } |
563 | * @arg @ref HAL_RTC_MSPINIT_CB_ID Msp Init callback ID |
564 | } |
564 | * @arg @ref HAL_RTC_MSPDEINIT_CB_ID Msp DeInit callback ID |
565 | else |
565 | * @note HAL_RTC_TAMPER2_EVENT_CB_ID is not applicable to all devices. |
566 | { |
566 | * @note HAL_RTC_TAMPER3_EVENT_CB_ID is not applicable to all devices. |
567 | /* Return error status */ |
567 | * @retval HAL status |
568 | status = HAL_ERROR; |
568 | */ |
569 | } |
569 | HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID) |
570 | 570 | { |
|
571 | /* Release Lock */ |
571 | HAL_StatusTypeDef status = HAL_OK; |
572 | __HAL_UNLOCK(hrtc); |
572 | |
573 | 573 | /* Process locked */ |
|
574 | return status; |
574 | __HAL_LOCK(hrtc); |
575 | } |
575 | |
576 | 576 | if (HAL_RTC_STATE_READY == hrtc->State) |
|
577 | /** |
577 | { |
578 | * @brief Unregister an RTC Callback |
578 | switch (CallbackID) |
579 | * RTC callabck is redirected to the weak predefined callback |
579 | { |
580 | * @param hrtc RTC handle |
580 | case HAL_RTC_ALARM_A_EVENT_CB_ID : |
581 | * @param CallbackID ID of the callback to be unregistered |
581 | hrtc->AlarmAEventCallback = HAL_RTC_AlarmAEventCallback; /* Legacy weak AlarmAEventCallback */ |
582 | * This parameter can be one of the following values: |
582 | break; |
583 | * @arg @ref HAL_RTC_ALARM_A_EVENT_CB_ID Alarm A Event Callback ID |
583 | |
584 | * @arg @ref HAL_RTC_ALARM_B_EVENT_CB_ID Alarm B Event Callback ID |
584 | case HAL_RTC_ALARM_B_EVENT_CB_ID : |
585 | * @arg @ref HAL_RTC_TIMESTAMP_EVENT_CB_ID TimeStamp Event Callback ID |
585 | hrtc->AlarmBEventCallback = HAL_RTCEx_AlarmBEventCallback; /* Legacy weak AlarmBEventCallback */ |
586 | * @arg @ref HAL_RTC_WAKEUPTIMER_EVENT_CB_ID WakeUp Timer Event Callback ID |
586 | break; |
587 | * @arg @ref HAL_RTC_TAMPER1_EVENT_CB_ID Tamper 1 Callback ID |
587 | |
588 | * @arg @ref HAL_RTC_TAMPER2_EVENT_CB_ID Tamper 2 Callback ID |
588 | case HAL_RTC_TIMESTAMP_EVENT_CB_ID : |
589 | * @arg @ref HAL_RTC_TAMPER3_EVENT_CB_ID Tamper 3 Callback ID |
589 | hrtc->TimeStampEventCallback = HAL_RTCEx_TimeStampEventCallback; /* Legacy weak TimeStampEventCallback */ |
590 | * @arg @ref HAL_RTC_MSPINIT_CB_ID Msp Init callback ID |
590 | break; |
591 | * @arg @ref HAL_RTC_MSPDEINIT_CB_ID Msp DeInit callback ID |
591 | |
592 | * @retval HAL status |
592 | case HAL_RTC_WAKEUPTIMER_EVENT_CB_ID : |
593 | */ |
593 | hrtc->WakeUpTimerEventCallback = HAL_RTCEx_WakeUpTimerEventCallback; /* Legacy weak WakeUpTimerEventCallback */ |
594 | HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID) |
594 | break; |
595 | { |
595 | |
596 | HAL_StatusTypeDef status = HAL_OK; |
596 | case HAL_RTC_TAMPER1_EVENT_CB_ID : |
597 | 597 | hrtc->Tamper1EventCallback = HAL_RTCEx_Tamper1EventCallback; /* Legacy weak Tamper1EventCallback */ |
|
598 | /* Process locked */ |
598 | break; |
599 | __HAL_LOCK(hrtc); |
599 | |
600 | 600 | #if defined(RTC_TAMPER2_SUPPORT) |
|
601 | if (HAL_RTC_STATE_READY == hrtc->State) |
601 | case HAL_RTC_TAMPER2_EVENT_CB_ID : |
602 | { |
602 | hrtc->Tamper2EventCallback = HAL_RTCEx_Tamper2EventCallback; /* Legacy weak Tamper2EventCallback */ |
603 | switch (CallbackID) |
603 | break; |
604 | { |
604 | #endif /* RTC_TAMPER2_SUPPORT */ |
605 | case HAL_RTC_ALARM_A_EVENT_CB_ID : |
605 | |
606 | hrtc->AlarmAEventCallback = HAL_RTC_AlarmAEventCallback; /* Legacy weak AlarmAEventCallback */ |
606 | #if defined(RTC_TAMPER3_SUPPORT) |
607 | break; |
607 | case HAL_RTC_TAMPER3_EVENT_CB_ID : |
608 | 608 | hrtc->Tamper3EventCallback = HAL_RTCEx_Tamper3EventCallback; /* Legacy weak Tamper3EventCallback */ |
|
609 | case HAL_RTC_ALARM_B_EVENT_CB_ID : |
609 | break; |
610 | hrtc->AlarmBEventCallback = HAL_RTCEx_AlarmBEventCallback; /* Legacy weak AlarmBEventCallback */ |
610 | #endif /* RTC_TAMPER3_SUPPORT */ |
611 | break; |
611 | |
612 | 612 | case HAL_RTC_MSPINIT_CB_ID : |
|
613 | case HAL_RTC_TIMESTAMP_EVENT_CB_ID : |
613 | hrtc->MspInitCallback = HAL_RTC_MspInit; |
614 | hrtc->TimeStampEventCallback = HAL_RTCEx_TimeStampEventCallback; /* Legacy weak TimeStampEventCallback */ |
614 | break; |
615 | break; |
615 | |
616 | 616 | case HAL_RTC_MSPDEINIT_CB_ID : |
|
617 | case HAL_RTC_WAKEUPTIMER_EVENT_CB_ID : |
617 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
618 | hrtc->WakeUpTimerEventCallback = HAL_RTCEx_WakeUpTimerEventCallback; /* Legacy weak WakeUpTimerEventCallback */ |
618 | break; |
619 | break; |
619 | |
620 | 620 | default : |
|
621 | case HAL_RTC_TAMPER1_EVENT_CB_ID : |
621 | /* Return error status */ |
622 | hrtc->Tamper1EventCallback = HAL_RTCEx_Tamper1EventCallback; /* Legacy weak Tamper1EventCallback */ |
622 | status = HAL_ERROR; |
623 | break; |
623 | break; |
624 | 624 | } |
|
625 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
625 | } |
626 | case HAL_RTC_TAMPER2_EVENT_CB_ID : |
626 | else if (HAL_RTC_STATE_RESET == hrtc->State) |
627 | hrtc->Tamper2EventCallback = HAL_RTCEx_Tamper2EventCallback; /* Legacy weak Tamper2EventCallback */ |
627 | { |
628 | break; |
628 | switch (CallbackID) |
629 | 629 | { |
|
630 | case HAL_RTC_TAMPER3_EVENT_CB_ID : |
630 | case HAL_RTC_MSPINIT_CB_ID : |
631 | hrtc->Tamper3EventCallback = HAL_RTCEx_Tamper3EventCallback; /* Legacy weak Tamper3EventCallback */ |
631 | hrtc->MspInitCallback = HAL_RTC_MspInit; |
632 | break; |
632 | break; |
633 | #endif |
633 | |
634 | case HAL_RTC_MSPINIT_CB_ID : |
634 | case HAL_RTC_MSPDEINIT_CB_ID : |
635 | hrtc->MspInitCallback = HAL_RTC_MspInit; |
635 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
636 | break; |
636 | break; |
637 | 637 | ||
638 | case HAL_RTC_MSPDEINIT_CB_ID : |
638 | default : |
639 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
639 | /* Return error status */ |
640 | break; |
640 | status = HAL_ERROR; |
641 | 641 | break; |
|
642 | default : |
642 | } |
643 | /* Return error status */ |
643 | } |
644 | status = HAL_ERROR; |
644 | else |
645 | break; |
645 | { |
646 | } |
646 | /* Return error status */ |
647 | } |
647 | status = HAL_ERROR; |
648 | else if (HAL_RTC_STATE_RESET == hrtc->State) |
648 | } |
649 | { |
649 | |
650 | switch (CallbackID) |
650 | /* Release Lock */ |
651 | { |
651 | __HAL_UNLOCK(hrtc); |
652 | case HAL_RTC_MSPINIT_CB_ID : |
652 | |
653 | hrtc->MspInitCallback = HAL_RTC_MspInit; |
653 | return status; |
654 | break; |
654 | } |
655 | 655 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
|
656 | case HAL_RTC_MSPDEINIT_CB_ID : |
656 | |
657 | hrtc->MspDeInitCallback = HAL_RTC_MspDeInit; |
657 | /** |
658 | break; |
658 | * @brief Initializes the RTC MSP. |
659 | 659 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
|
660 | default : |
660 | * the configuration information for RTC. |
661 | /* Return error status */ |
661 | * @retval None |
662 | status = HAL_ERROR; |
662 | */ |
663 | break; |
663 | __weak void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) |
664 | } |
664 | { |
665 | } |
665 | /* Prevent unused argument(s) compilation warning */ |
666 | else |
666 | UNUSED(hrtc); |
667 | { |
667 | |
668 | /* Return error status */ |
668 | /* NOTE: This function should not be modified, when the callback is needed, |
669 | status = HAL_ERROR; |
669 | the HAL_RTC_MspInit could be implemented in the user file |
670 | } |
670 | */ |
671 | 671 | } |
|
672 | /* Release Lock */ |
672 | |
673 | __HAL_UNLOCK(hrtc); |
673 | /** |
674 | 674 | * @brief DeInitializes the RTC MSP. |
|
675 | return status; |
675 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
676 | } |
676 | * the configuration information for RTC. |
677 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
677 | * @retval None |
678 | 678 | */ |
|
679 | /** |
679 | __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc) |
680 | * @brief Initialize the RTC MSP. |
680 | { |
681 | * @param hrtc RTC handle |
681 | /* Prevent unused argument(s) compilation warning */ |
682 | * @retval None |
682 | UNUSED(hrtc); |
683 | */ |
683 | |
684 | __weak void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) |
684 | /* NOTE: This function should not be modified, when the callback is needed, |
685 | { |
685 | the HAL_RTC_MspDeInit could be implemented in the user file |
686 | /* Prevent unused argument(s) compilation warning */ |
686 | */ |
687 | UNUSED(hrtc); |
687 | } |
688 | 688 | ||
689 | /* NOTE : This function Should not be modified, when the callback is needed, |
689 | /** |
690 | the HAL_RTC_MspInit could be implemented in the user file |
690 | * @} |
691 | */ |
691 | */ |
692 | } |
692 | |
693 | 693 | /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions |
|
694 | /** |
694 | * @brief RTC Time and Date functions |
695 | * @brief DeInitialize the RTC MSP. |
695 | * |
696 | * @param hrtc RTC handle |
696 | @verbatim |
697 | * @retval None |
697 | =============================================================================== |
698 | */ |
698 | ##### RTC Time and Date functions ##### |
699 | __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc) |
699 | =============================================================================== |
700 | { |
700 | |
701 | /* Prevent unused argument(s) compilation warning */ |
701 | [..] This section provides functions allowing to configure Time and Date features |
702 | UNUSED(hrtc); |
702 | |
703 | 703 | @endverbatim |
|
704 | /* NOTE : This function Should not be modified, when the callback is needed, |
704 | * @{ |
705 | the HAL_RTC_MspDeInit could be implemented in the user file |
705 | */ |
706 | */ |
706 | |
707 | } |
707 | /** |
708 | 708 | * @brief Sets RTC current time. |
|
709 | /** |
709 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
710 | * @} |
710 | * the configuration information for RTC. |
711 | */ |
711 | * @param sTime Pointer to Time structure |
712 | 712 | * @note DayLightSaving and StoreOperation interfaces are deprecated. |
|
713 | /** @addtogroup RTC_Exported_Functions_Group2 |
713 | * To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions. |
714 | * @brief RTC Time and Date functions |
714 | * @param Format Specifies the format of the entered parameters. |
715 | * |
715 | * This parameter can be one of the following values: |
716 | @verbatim |
716 | * @arg RTC_FORMAT_BIN: Binary data format |
717 | =============================================================================== |
717 | * @arg RTC_FORMAT_BCD: BCD data format |
718 | ##### RTC Time and Date functions ##### |
718 | * @retval HAL status |
719 | =============================================================================== |
719 | */ |
720 | 720 | HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
|
721 | [..] This section provides functions allowing to configure Time and Date features |
721 | { |
722 | 722 | uint32_t tmpreg = 0U; |
|
723 | @endverbatim |
723 | HAL_StatusTypeDef status; |
724 | * @{ |
724 | |
725 | */ |
725 | /* Check the parameters */ |
726 | 726 | assert_param(IS_RTC_FORMAT(Format)); |
|
727 | /** |
727 | assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving)); |
728 | * @brief Set RTC current time. |
728 | assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation)); |
729 | * @param hrtc RTC handle |
729 | |
730 | * @param sTime Pointer to Time structure |
730 | /* Process Locked */ |
731 | * @param Format Specifies the format of the entered parameters. |
731 | __HAL_LOCK(hrtc); |
732 | * This parameter can be one of the following values: |
732 | |
733 | * @arg RTC_FORMAT_BIN: Binary data format |
733 | hrtc->State = HAL_RTC_STATE_BUSY; |
734 | * @arg RTC_FORMAT_BCD: BCD data format |
734 | |
735 | * @retval HAL status |
735 | if (Format == RTC_FORMAT_BIN) |
736 | */ |
736 | { |
737 | HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
737 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
738 | { |
738 | { |
739 | uint32_t tmpreg; |
739 | assert_param(IS_RTC_HOUR12(sTime->Hours)); |
740 | 740 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
|
741 | /* Check the parameters */ |
741 | } |
742 | assert_param(IS_RTC_FORMAT(Format)); |
742 | else |
743 | assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving)); |
743 | { |
744 | assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation)); |
744 | sTime->TimeFormat = 0x00U; |
745 | 745 | assert_param(IS_RTC_HOUR24(sTime->Hours)); |
|
746 | /* Process Locked */ |
746 | } |
747 | __HAL_LOCK(hrtc); |
747 | assert_param(IS_RTC_MINUTES(sTime->Minutes)); |
748 | 748 | assert_param(IS_RTC_SECONDS(sTime->Seconds)); |
|
749 | hrtc->State = HAL_RTC_STATE_BUSY; |
749 | |
750 | 750 | tmpreg = (uint32_t)(( (uint32_t)RTC_ByteToBcd2(sTime->Hours) << RTC_TR_HU_Pos) | \ |
|
751 | if (Format == RTC_FORMAT_BIN) |
751 | ( (uint32_t)RTC_ByteToBcd2(sTime->Minutes) << RTC_TR_MNU_Pos) | \ |
752 | { |
752 | ( (uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \ |
753 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
753 | (((uint32_t)sTime->TimeFormat) << RTC_TR_PM_Pos)); |
754 | { |
754 | } |
755 | assert_param(IS_RTC_HOUR12(sTime->Hours)); |
755 | else |
756 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
756 | { |
757 | } |
757 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
758 | else |
758 | { |
759 | { |
759 | assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sTime->Hours))); |
760 | sTime->TimeFormat = 0x00U; |
760 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
761 | assert_param(IS_RTC_HOUR24(sTime->Hours)); |
761 | } |
762 | } |
762 | else |
763 | assert_param(IS_RTC_MINUTES(sTime->Minutes)); |
763 | { |
764 | assert_param(IS_RTC_SECONDS(sTime->Seconds)); |
764 | sTime->TimeFormat = 0x00U; |
765 | 765 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours))); |
|
766 | tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16U) | \ |
766 | } |
767 | ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8U) | \ |
767 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes))); |
768 | ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \ |
768 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds))); |
769 | (((uint32_t)sTime->TimeFormat) << 16U)); |
769 | tmpreg = (((uint32_t)(sTime->Hours) << RTC_TR_HU_Pos) | \ |
770 | } |
770 | ((uint32_t)(sTime->Minutes) << RTC_TR_MNU_Pos) | \ |
771 | else |
771 | ((uint32_t) sTime->Seconds) | \ |
772 | { |
772 | ((uint32_t)(sTime->TimeFormat) << RTC_TR_PM_Pos)); |
773 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
773 | } |
774 | { |
774 | |
775 | assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sTime->Hours))); |
775 | /* Disable the write protection for RTC registers */ |
776 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
776 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
777 | } |
777 | |
778 | else |
778 | /* Enter Initialization mode */ |
779 | { |
779 | status = RTC_EnterInitMode(hrtc); |
780 | sTime->TimeFormat = 0x00U; |
780 | |
781 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours))); |
781 | if (status == HAL_OK) |
782 | } |
782 | { |
783 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes))); |
783 | /* Set the RTC_TR register */ |
784 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds))); |
784 | hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); |
785 | tmpreg = (((uint32_t)(sTime->Hours) << 16U) | \ |
785 | |
786 | ((uint32_t)(sTime->Minutes) << 8U) | \ |
786 | /* Clear the bits to be configured (Deprecated. Use HAL_RTC_DST_xxx functions instead) */ |
787 | ((uint32_t)sTime->Seconds) | \ |
787 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_BKP; |
788 | ((uint32_t)(sTime->TimeFormat) << 16U)); |
788 | |
789 | } |
789 | /* Configure the RTC_CR register (Deprecated. Use HAL_RTC_DST_xxx functions instead) */ |
790 | UNUSED(tmpreg); |
790 | hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation); |
791 | /* Disable the write protection for RTC registers */ |
791 | |
792 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
792 | /* Exit Initialization mode */ |
793 | 793 | status = RTC_ExitInitMode(hrtc); |
|
794 | /* Set Initialization mode */ |
794 | } |
795 | if (RTC_EnterInitMode(hrtc) != HAL_OK) |
795 | |
796 | { |
796 | if (status == HAL_OK) |
797 | /* Enable the write protection for RTC registers */ |
797 | { |
798 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
798 | hrtc->State = HAL_RTC_STATE_READY; |
799 | 799 | } |
|
800 | /* Set RTC state */ |
800 | |
801 | hrtc->State = HAL_RTC_STATE_ERROR; |
801 | /* Enable the write protection for RTC registers */ |
802 | 802 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
|
803 | /* Process Unlocked */ |
803 | |
804 | __HAL_UNLOCK(hrtc); |
804 | /* Process Unlocked */ |
805 | 805 | __HAL_UNLOCK(hrtc); |
|
806 | return HAL_ERROR; |
806 | |
807 | } |
807 | return status; |
808 | else |
808 | } |
809 | { |
809 | |
810 | /* Set the RTC_TR register */ |
810 | /** |
811 | hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); |
811 | * @brief Gets RTC current time. |
812 | 812 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
|
813 | /* Clear the bits to be configured (Deprecated. Use HAL_RTC_DST_xxx functions instead) */ |
813 | * the configuration information for RTC. |
814 | hrtc->Instance->CR &= ((uint32_t)~RTC_CR_BKP); |
814 | * @param sTime Pointer to Time structure |
815 | 815 | * @param Format Specifies the format of the entered parameters. |
|
816 | /* Configure the RTC_CR register (Deprecated. Use HAL_RTC_DST_xxx functions instead) */ |
816 | * This parameter can be one of the following values: |
817 | hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation); |
817 | * @arg RTC_FORMAT_BIN: Binary data format |
818 | 818 | * @arg RTC_FORMAT_BCD: BCD data format |
|
819 | /* Exit Initialization mode */ |
819 | * @note You can use SubSeconds and SecondFraction (sTime structure fields |
820 | hrtc->Instance->ISR &= ((uint32_t)~RTC_ISR_INIT); |
820 | * returned) to convert SubSeconds value in second fraction ratio with |
821 | 821 | * time unit following generic formula: |
|
822 | /* Wait for synchro */ |
822 | * Second fraction ratio * time_unit = |
823 | if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
823 | * [(SecondFraction - SubSeconds) / (SecondFraction + 1)] * time_unit |
824 | { |
824 | * This conversion can be performed only if no shift operation is pending |
825 | /* Enable the write protection for RTC registers */ |
825 | * (ie. SHFP=0) when PREDIV_S >= SS |
826 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
826 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the |
827 | 827 | * values in the higher-order calendar shadow registers to ensure |
|
828 | hrtc->State = HAL_RTC_STATE_ERROR; |
828 | * consistency between the time and date values. |
829 | 829 | * Reading RTC current time locks the values in calendar shadow registers |
|
830 | /* Process Unlocked */ |
830 | * until current date is read to ensure consistency between the time and |
831 | __HAL_UNLOCK(hrtc); |
831 | * date values. |
832 | 832 | * @retval HAL status |
|
833 | return HAL_ERROR; |
833 | */ |
834 | } |
834 | HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
835 | 835 | { |
|
836 | /* Enable the write protection for RTC registers */ |
836 | uint32_t tmpreg = 0U; |
837 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
837 | |
838 | 838 | /* Check the parameters */ |
|
839 | hrtc->State = HAL_RTC_STATE_READY; |
839 | assert_param(IS_RTC_FORMAT(Format)); |
840 | 840 | ||
841 | __HAL_UNLOCK(hrtc); |
841 | #if defined(RTC_SUBSECOND_SUPPORT) |
842 | 842 | /* Get subseconds value from the corresponding register */ |
|
843 | return HAL_OK; |
843 | sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR); |
844 | } |
844 | |
845 | } |
845 | /* Get SecondFraction structure field from the corresponding register field*/ |
846 | 846 | sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S); |
|
847 | /** |
847 | #endif /* RTC_SUBSECOND_SUPPORT */ |
848 | * @brief Get RTC current time. |
848 | |
849 | * @param hrtc RTC handle |
849 | /* Get the TR register */ |
850 | * @param sTime Pointer to Time structure with Hours, Minutes and Seconds fields returned |
850 | tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK); |
851 | * with input format (BIN or BCD), also SubSeconds field (if availabale) returning the |
851 | |
852 | * RTC_SSR register content and SecondFraction field the Synchronous pre-scaler |
852 | /* Fill the structure fields with the read parameters */ |
853 | * factor to be used for second fraction ratio computation. |
853 | sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> RTC_TR_HU_Pos); |
854 | * @param Format Specifies the format of the entered parameters. |
854 | sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> RTC_TR_MNU_Pos); |
855 | * This parameter can be one of the following values: |
855 | sTime->Seconds = (uint8_t)( tmpreg & (RTC_TR_ST | RTC_TR_SU)); |
856 | * @arg RTC_FORMAT_BIN: Binary data format |
856 | sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> RTC_TR_PM_Pos); |
857 | * @arg RTC_FORMAT_BCD: BCD data format |
857 | |
858 | * @note If available, you can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds |
858 | /* Check the input parameters format */ |
859 | * value in second fraction ratio with time unit following generic formula: |
859 | if (Format == RTC_FORMAT_BIN) |
860 | * Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit |
860 | { |
861 | * This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS |
861 | /* Convert the time structure parameters to Binary format */ |
862 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
862 | sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); |
863 | * in the higher-order calendar shadow registers to ensure consistency between the time and date values. |
863 | sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); |
864 | * Reading RTC current time locks the values in calendar shadow registers until Current date is read |
864 | sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); |
865 | * to ensure consistency between the time and date values. |
865 | } |
866 | * @retval HAL status |
866 | |
867 | */ |
867 | return HAL_OK; |
868 | HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
868 | } |
869 | { |
869 | |
870 | uint32_t tmpreg; |
870 | /** |
871 | 871 | * @brief Sets RTC current date. |
|
872 | /* Check the parameters */ |
872 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
873 | assert_param(IS_RTC_FORMAT(Format)); |
873 | * the configuration information for RTC. |
874 | 874 | * @param sDate Pointer to date structure |
|
875 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
875 | * @param Format specifies the format of the entered parameters. |
876 | /* Get subseconds structure field from the corresponding register*/ |
876 | * This parameter can be one of the following values: |
877 | sTime->SubSeconds = (uint32_t)((hrtc->Instance->SSR) & RTC_SSR_SS); |
877 | * @arg RTC_FORMAT_BIN: Binary data format |
878 | 878 | * @arg RTC_FORMAT_BCD: BCD data format |
|
879 | /* Get SecondFraction structure field from the corresponding register field*/ |
879 | * @retval HAL status |
880 | sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S); |
880 | */ |
881 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
881 | HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
882 | 882 | { |
|
883 | /* Get the TR register */ |
883 | uint32_t datetmpreg = 0U; |
884 | tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK); |
884 | HAL_StatusTypeDef status; |
885 | 885 | ||
886 | /* Fill the structure fields with the read parameters */ |
886 | /* Check the parameters */ |
887 | sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16U); |
887 | assert_param(IS_RTC_FORMAT(Format)); |
888 | sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> 8U); |
888 | |
889 | sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); |
889 | /* Process Locked */ |
890 | sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16U); |
890 | __HAL_LOCK(hrtc); |
891 | 891 | ||
892 | /* Check the input parameters format */ |
892 | hrtc->State = HAL_RTC_STATE_BUSY; |
893 | if (Format == RTC_FORMAT_BIN) |
893 | |
894 | { |
894 | if ((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10U) == 0x10U)) |
895 | /* Convert the time structure parameters to Binary format */ |
895 | { |
896 | sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); |
896 | sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU); |
897 | sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); |
897 | } |
898 | sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); |
898 | |
899 | } |
899 | assert_param(IS_RTC_WEEKDAY(sDate->WeekDay)); |
900 | 900 | ||
901 | return HAL_OK; |
901 | if (Format == RTC_FORMAT_BIN) |
902 | } |
902 | { |
903 | 903 | assert_param(IS_RTC_YEAR(sDate->Year)); |
|
904 | /** |
904 | assert_param(IS_RTC_MONTH(sDate->Month)); |
905 | * @brief Set RTC current date. |
905 | assert_param(IS_RTC_DATE(sDate->Date)); |
906 | * @param hrtc RTC handle |
906 | |
907 | * @param sDate Pointer to date structure |
907 | datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << RTC_DR_YU_Pos) | \ |
908 | * @param Format specifies the format of the entered parameters. |
908 | ((uint32_t)RTC_ByteToBcd2(sDate->Month) << RTC_DR_MU_Pos) | \ |
909 | * This parameter can be one of the following values: |
909 | ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \ |
910 | * @arg RTC_FORMAT_BIN: Binary data format |
910 | ((uint32_t)sDate->WeekDay << RTC_DR_WDU_Pos)); |
911 | * @arg RTC_FORMAT_BCD: BCD data format |
911 | } |
912 | * @retval HAL status |
912 | else |
913 | */ |
913 | { |
914 | HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
914 | assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year))); |
915 | { |
915 | assert_param(IS_RTC_MONTH(RTC_Bcd2ToByte(sDate->Month))); |
916 | uint32_t datetmpreg; |
916 | assert_param(IS_RTC_DATE(RTC_Bcd2ToByte(sDate->Date))); |
917 | 917 | ||
918 | /* Check the parameters */ |
918 | datetmpreg = ((((uint32_t)sDate->Year) << RTC_DR_YU_Pos) | \ |
919 | assert_param(IS_RTC_FORMAT(Format)); |
919 | (((uint32_t)sDate->Month) << RTC_DR_MU_Pos) | \ |
920 | 920 | ((uint32_t) sDate->Date) | \ |
|
921 | /* Process Locked */ |
921 | (((uint32_t)sDate->WeekDay) << RTC_DR_WDU_Pos)); |
922 | __HAL_LOCK(hrtc); |
922 | } |
923 | 923 | ||
924 | hrtc->State = HAL_RTC_STATE_BUSY; |
924 | /* Disable the write protection for RTC registers */ |
925 | 925 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
|
926 | if ((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10U) == 0x10U)) |
926 | |
927 | { |
927 | /* Enter Initialization mode */ |
928 | sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU); |
928 | status = RTC_EnterInitMode(hrtc); |
929 | } |
929 | |
930 | 930 | if (status == HAL_OK) |
|
931 | assert_param(IS_RTC_WEEKDAY(sDate->WeekDay)); |
931 | { |
932 | 932 | /* Set the RTC_DR register */ |
|
933 | if (Format == RTC_FORMAT_BIN) |
933 | hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); |
934 | { |
934 | |
935 | assert_param(IS_RTC_YEAR(sDate->Year)); |
935 | /* Exit Initialization mode */ |
936 | assert_param(IS_RTC_MONTH(sDate->Month)); |
936 | status = RTC_ExitInitMode(hrtc); |
937 | assert_param(IS_RTC_DATE(sDate->Date)); |
937 | } |
938 | 938 | ||
939 | datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16U) | \ |
939 | if (status == HAL_OK) |
940 | ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8U) | \ |
940 | { |
941 | ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \ |
941 | hrtc->State = HAL_RTC_STATE_READY; |
942 | ((uint32_t)sDate->WeekDay << 13U)); |
942 | } |
943 | } |
943 | |
944 | else |
944 | /* Enable the write protection for RTC registers */ |
945 | { |
945 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
946 | assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year))); |
946 | |
947 | assert_param(IS_RTC_MONTH(RTC_Bcd2ToByte(sDate->Month))); |
947 | /* Process Unlocked */ |
948 | assert_param(IS_RTC_DATE(RTC_Bcd2ToByte(sDate->Date))); |
948 | __HAL_UNLOCK(hrtc); |
949 | 949 | ||
950 | datetmpreg = ((((uint32_t)sDate->Year) << 16U) | \ |
950 | return status; |
951 | (((uint32_t)sDate->Month) << 8U) | \ |
951 | } |
952 | ((uint32_t)sDate->Date) | \ |
952 | |
953 | (((uint32_t)sDate->WeekDay) << 13U)); |
953 | /** |
954 | } |
954 | * @brief Gets RTC current date. |
955 | 955 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
|
956 | /* Disable the write protection for RTC registers */ |
956 | * the configuration information for RTC. |
957 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
957 | * @param sDate Pointer to Date structure |
958 | 958 | * @param Format Specifies the format of the entered parameters. |
|
959 | /* Set Initialization mode */ |
959 | * This parameter can be one of the following values: |
960 | if (RTC_EnterInitMode(hrtc) != HAL_OK) |
960 | * @arg RTC_FORMAT_BIN: Binary data format |
961 | { |
961 | * @arg RTC_FORMAT_BCD: BCD data format |
962 | /* Enable the write protection for RTC registers */ |
962 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the |
963 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
963 | * values in the higher-order calendar shadow registers to ensure |
964 | 964 | * consistency between the time and date values. |
|
965 | /* Set RTC state*/ |
965 | * Reading RTC current time locks the values in calendar shadow registers |
966 | hrtc->State = HAL_RTC_STATE_ERROR; |
966 | * until current date is read to ensure consistency between the time and |
967 | 967 | * date values. |
|
968 | /* Process Unlocked */ |
968 | * @retval HAL status |
969 | __HAL_UNLOCK(hrtc); |
969 | */ |
970 | 970 | HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
|
971 | return HAL_ERROR; |
971 | { |
972 | } |
972 | uint32_t datetmpreg = 0U; |
973 | else |
973 | |
974 | { |
974 | /* Check the parameters */ |
975 | /* Set the RTC_DR register */ |
975 | assert_param(IS_RTC_FORMAT(Format)); |
976 | hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); |
976 | |
977 | 977 | /* Get the DR register */ |
|
978 | /* Exit Initialization mode */ |
978 | datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK); |
979 | hrtc->Instance->ISR &= ((uint32_t)~RTC_ISR_INIT); |
979 | |
980 | 980 | /* Fill the structure fields with the read parameters */ |
|
981 | /* Wait for synchro */ |
981 | sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> RTC_DR_YU_Pos); |
982 | if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
982 | sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> RTC_DR_MU_Pos); |
983 | { |
983 | sDate->Date = (uint8_t) (datetmpreg & (RTC_DR_DT | RTC_DR_DU)); |
984 | /* Enable the write protection for RTC registers */ |
984 | sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> RTC_DR_WDU_Pos); |
985 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
985 | |
986 | 986 | /* Check the input parameters format */ |
|
987 | hrtc->State = HAL_RTC_STATE_ERROR; |
987 | if (Format == RTC_FORMAT_BIN) |
988 | 988 | { |
|
989 | /* Process Unlocked */ |
989 | /* Convert the date structure parameters to Binary format */ |
990 | __HAL_UNLOCK(hrtc); |
990 | sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); |
991 | 991 | sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); |
|
992 | return HAL_ERROR; |
992 | sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); |
993 | } |
993 | } |
994 | 994 | return HAL_OK; |
|
995 | /* Enable the write protection for RTC registers */ |
995 | } |
996 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
996 | |
997 | 997 | /** |
|
998 | hrtc->State = HAL_RTC_STATE_READY ; |
998 | * @} |
999 | 999 | */ |
|
1000 | /* Process Unlocked */ |
1000 | |
1001 | __HAL_UNLOCK(hrtc); |
1001 | /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions |
1002 | 1002 | * @brief RTC Alarm functions |
|
1003 | return HAL_OK; |
1003 | * |
1004 | } |
1004 | @verbatim |
1005 | } |
1005 | =============================================================================== |
1006 | 1006 | ##### RTC Alarm functions ##### |
|
1007 | /** |
1007 | =============================================================================== |
1008 | * @brief Get RTC current date. |
1008 | |
1009 | * @param hrtc RTC handle |
1009 | [..] This section provides functions allowing to configure Alarm feature |
1010 | * @param sDate Pointer to Date structure |
1010 | |
1011 | * @param Format Specifies the format of the entered parameters. |
1011 | @endverbatim |
1012 | * This parameter can be one of the following values: |
1012 | * @{ |
1013 | * @arg RTC_FORMAT_BIN: Binary data format |
1013 | */ |
1014 | * @arg RTC_FORMAT_BCD: BCD data format |
1014 | /** |
1015 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
1015 | * @brief Sets the specified RTC Alarm. |
1016 | * in the higher-order calendar shadow registers to ensure consistency between the time and date values. |
1016 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1017 | * Reading RTC current time locks the values in calendar shadow registers until Current date is read. |
1017 | * the configuration information for RTC. |
1018 | * @retval HAL status |
1018 | * @param sAlarm Pointer to Alarm structure |
1019 | */ |
1019 | * @param Format Specifies the format of the entered parameters. |
1020 | HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
1020 | * This parameter can be one of the following values: |
1021 | { |
1021 | * @arg RTC_FORMAT_BIN: Binary data format |
1022 | uint32_t datetmpreg; |
1022 | * @arg RTC_FORMAT_BCD: BCD data format |
1023 | 1023 | * @note The Alarm register can only be written when the corresponding Alarm |
|
1024 | /* Check the parameters */ |
1024 | * is disabled (Use the HAL_RTC_DeactivateAlarm()). |
1025 | assert_param(IS_RTC_FORMAT(Format)); |
1025 | * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature. |
1026 | 1026 | * @retval HAL status |
|
1027 | /* Get the DR register */ |
1027 | */ |
1028 | datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK); |
1028 | HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
1029 | 1029 | { |
|
1030 | /* Fill the structure fields with the read parameters */ |
1030 | uint32_t tickstart = 0U; |
1031 | sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16U); |
1031 | uint32_t tmpreg = 0U; |
1032 | sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8U); |
1032 | #if defined(RTC_SUBSECOND_SUPPORT) |
1033 | sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); |
1033 | uint32_t subsecondtmpreg = 0U; |
1034 | sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13U); |
1034 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1035 | 1035 | ||
1036 | /* Check the input parameters format */ |
1036 | /* Check the parameters */ |
1037 | if (Format == RTC_FORMAT_BIN) |
1037 | assert_param(IS_RTC_FORMAT(Format)); |
1038 | { |
1038 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
1039 | /* Convert the date structure parameters to Binary format */ |
1039 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
1040 | sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); |
1040 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
1041 | sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); |
1041 | #if defined(RTC_SUBSECOND_SUPPORT) |
1042 | sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); |
1042 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
1043 | } |
1043 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
1044 | return HAL_OK; |
1044 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1045 | } |
1045 | |
1046 | 1046 | /* Process Locked */ |
|
1047 | /** |
1047 | __HAL_LOCK(hrtc); |
1048 | * @brief Daylight Saving Time, adda one hour to the calendar in one |
1048 | |
1049 | * single operation without going through the initialization procedure. |
1049 | /* Change RTC state to BUSY */ |
1050 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1050 | hrtc->State = HAL_RTC_STATE_BUSY; |
1051 | * the configuration information for RTC. |
1051 | |
1052 | * @retval None |
1052 | /* Check the data format (binary or BCD) and store the Alarm time and date |
1053 | */ |
1053 | configuration accordingly */ |
1054 | void HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc) |
1054 | if (Format == RTC_FORMAT_BIN) |
1055 | { |
1055 | { |
1056 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1056 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
1057 | SET_BIT(hrtc->Instance->CR, RTC_CR_ADD1H); |
1057 | { |
1058 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1058 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
1059 | } |
1059 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1060 | 1060 | } |
|
1061 | /** |
1061 | else |
1062 | * @brief Daylight Saving Time, subtracts one hour from the calendar in one |
1062 | { |
1063 | * single operation without going through the initialization procedure. |
1063 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1064 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1064 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
1065 | * the configuration information for RTC. |
1065 | } |
1066 | * @retval None |
1066 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
1067 | */ |
1067 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
1068 | void HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc) |
1068 | |
1069 | { |
1069 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
1070 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1070 | { |
1071 | SET_BIT(hrtc->Instance->CR, RTC_CR_SUB1H); |
1071 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
1072 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1072 | } |
1073 | } |
1073 | else |
1074 | 1074 | { |
|
1075 | /** |
1075 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
1076 | * @brief Daylight Saving Time, sets the store operation bit. |
1076 | } |
1077 | * @note It can be used by the software in order to memorize the DST status. |
1077 | |
1078 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1078 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \ |
1079 | * the configuration information for RTC. |
1079 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \ |
1080 | * @retval None |
1080 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
1081 | */ |
1081 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_TR_PM_Pos) | \ |
1082 | void HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc) |
1082 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \ |
1083 | { |
1083 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
1084 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1084 | ((uint32_t)sAlarm->AlarmMask)); |
1085 | SET_BIT(hrtc->Instance->CR, RTC_CR_BKP); |
1085 | } |
1086 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1086 | else |
1087 | } |
1087 | { |
1088 | 1088 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
|
1089 | /** |
1089 | { |
1090 | * @brief Daylight Saving Time, clears the store operation bit. |
1090 | assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
1091 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1091 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1092 | * the configuration information for RTC. |
1092 | } |
1093 | * @retval None |
1093 | else |
1094 | */ |
1094 | { |
1095 | void HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc) |
1095 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1096 | { |
1096 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
1097 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1097 | } |
1098 | CLEAR_BIT(hrtc->Instance->CR, RTC_CR_BKP); |
1098 | |
1099 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1099 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
1100 | } |
1100 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
1101 | 1101 | ||
1102 | /** |
1102 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
1103 | * @brief Daylight Saving Time, reads the store operation bit. |
1103 | { |
1104 | * @param hrtc RTC handle |
1104 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
1105 | * @retval operation see RTC_StoreOperation_Definitions |
1105 | } |
1106 | */ |
1106 | else |
1107 | uint32_t HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc) |
1107 | { |
1108 | { |
1108 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
1109 | return READ_BIT(hrtc->Instance->CR, RTC_CR_BKP); |
1109 | } |
1110 | } |
1110 | |
1111 | 1111 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \ |
|
1112 | /** |
1112 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \ |
1113 | * @} |
1113 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
1114 | */ |
1114 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_TR_PM_Pos) | \ |
1115 | 1115 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \ |
|
1116 | /** @addtogroup RTC_Exported_Functions_Group3 |
1116 | ((uint32_t) sAlarm->AlarmDateWeekDaySel) | \ |
1117 | * @brief RTC Alarm functions |
1117 | ((uint32_t) sAlarm->AlarmMask)); |
1118 | * |
1118 | } |
1119 | @verbatim |
1119 | |
1120 | =============================================================================== |
1120 | #if defined(RTC_SUBSECOND_SUPPORT) |
1121 | ##### RTC Alarm functions ##### |
1121 | /* Store the Alarm subseconds configuration */ |
1122 | =============================================================================== |
1122 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | \ |
1123 | 1123 | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
|
1124 | [..] This section provides functions allowing to configure Alarm feature |
1124 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1125 | 1125 | ||
1126 | @endverbatim |
1126 | /* Disable the write protection for RTC registers */ |
1127 | * @{ |
1127 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1128 | */ |
1128 | |
1129 | /** |
1129 | /* Configure the Alarm register */ |
1130 | * @brief Set the specified RTC Alarm. |
1130 | if (sAlarm->Alarm == RTC_ALARM_A) |
1131 | * @param hrtc RTC handle |
1131 | { |
1132 | * @param sAlarm Pointer to Alarm structure |
1132 | /* Disable the Alarm A */ |
1133 | * @param Format Specifies the format of the entered parameters. |
1133 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
1134 | * This parameter can be one of the following values: |
1134 | |
1135 | * @arg RTC_FORMAT_BIN: Binary data format |
1135 | /* In case interrupt mode is used, the interrupt source must be disabled */ |
1136 | * @arg RTC_FORMAT_BCD: BCD data format |
1136 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
1137 | * @retval HAL status |
1137 | |
1138 | */ |
1138 | /* Clear the Alarm flag */ |
1139 | HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
1139 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
1140 | { |
1140 | |
1141 | uint32_t tickstart; |
1141 | /* Get tick */ |
1142 | uint32_t tmpreg; |
1142 | tickstart = HAL_GetTick(); |
1143 | 1143 | ||
1144 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1144 | /* Wait till RTC ALRAWF flag is set and if timeout is reached exit */ |
1145 | uint32_t subsecondtmpreg = 0; |
1145 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U) |
1146 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1146 | { |
1147 | 1147 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
|
1148 | /* Check the parameters */ |
1148 | { |
1149 | assert_param(IS_RTC_FORMAT(Format)); |
1149 | /* Enable the write protection for RTC registers */ |
1150 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
1150 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1151 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
1151 | |
1152 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
1152 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1153 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1153 | |
1154 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
1154 | /* Process Unlocked */ |
1155 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
1155 | __HAL_UNLOCK(hrtc); |
1156 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1156 | |
1157 | 1157 | return HAL_TIMEOUT; |
|
1158 | /* Process Locked */ |
1158 | } |
1159 | __HAL_LOCK(hrtc); |
1159 | } |
1160 | 1160 | ||
1161 | hrtc->State = HAL_RTC_STATE_BUSY; |
1161 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
1162 | 1162 | #if defined(RTC_SUBSECOND_SUPPORT) |
|
1163 | if (Format == RTC_FORMAT_BIN) |
1163 | /* Configure the Alarm A Subseconds register */ |
1164 | { |
1164 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
1165 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
1165 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1166 | { |
1166 | /* Configure the Alarm state: Enable Alarm */ |
1167 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
1167 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
1168 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1168 | } |
1169 | } |
1169 | else |
1170 | else |
1170 | { |
1171 | { |
1171 | /* Disable the Alarm B */ |
1172 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1172 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
1173 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
1173 | |
1174 | } |
1174 | /* In case interrupt mode is used, the interrupt source must be disabled */ |
1175 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
1175 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
1176 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
1176 | |
1177 | 1177 | /* Clear the Alarm flag */ |
|
1178 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
1178 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
1179 | { |
1179 | |
1180 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
1180 | /* Get tick */ |
1181 | } |
1181 | tickstart = HAL_GetTick(); |
1182 | else |
1182 | |
1183 | { |
1183 | /* Wait till RTC ALRBWF flag is set and if timeout is reached exit */ |
1184 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
1184 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U) |
1185 | } |
1185 | { |
1186 | 1186 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
|
1187 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16U) | \ |
1187 | { |
1188 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8U) | \ |
1188 | /* Enable the write protection for RTC registers */ |
1189 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
1189 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1190 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
1190 | |
1191 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24U) | \ |
1191 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1192 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
1192 | |
1193 | ((uint32_t)sAlarm->AlarmMask)); |
1193 | /* Process Unlocked */ |
1194 | } |
1194 | __HAL_UNLOCK(hrtc); |
1195 | else |
1195 | |
1196 | { |
1196 | return HAL_TIMEOUT; |
1197 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
1197 | } |
1198 | { |
1198 | } |
1199 | assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
1199 | |
1200 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1200 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
1201 | } |
1201 | #if defined(RTC_SUBSECOND_SUPPORT) |
1202 | else |
1202 | /* Configure the Alarm B Subseconds register */ |
1203 | { |
1203 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
1204 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1204 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1205 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
1205 | /* Configure the Alarm state: Enable Alarm */ |
1206 | } |
1206 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
1207 | 1207 | } |
|
1208 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
1208 | |
1209 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
1209 | /* Enable the write protection for RTC registers */ |
1210 | 1210 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
|
1211 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
1211 | |
1212 | { |
1212 | /* Change RTC state back to READY */ |
1213 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
1213 | hrtc->State = HAL_RTC_STATE_READY; |
1214 | } |
1214 | |
1215 | else |
1215 | /* Process Unlocked */ |
1216 | { |
1216 | __HAL_UNLOCK(hrtc); |
1217 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
1217 | |
1218 | } |
1218 | return HAL_OK; |
1219 | 1219 | } |
|
1220 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16U) | \ |
1220 | |
1221 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8U) | \ |
1221 | /** |
1222 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
1222 | * @brief Sets the specified RTC Alarm with Interrupt. |
1223 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
1223 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1224 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24U) | \ |
1224 | * the configuration information for RTC. |
1225 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
1225 | * @param sAlarm Pointer to Alarm structure |
1226 | ((uint32_t)sAlarm->AlarmMask)); |
1226 | * @param Format Specifies the format of the entered parameters. |
1227 | } |
1227 | * This parameter can be one of the following values: |
1228 | 1228 | * @arg RTC_FORMAT_BIN: Binary data format |
|
1229 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1229 | * @arg RTC_FORMAT_BCD: BCD data format |
1230 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
1230 | * @note The Alarm register can only be written when the corresponding Alarm |
1231 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
1231 | * is disabled (Use the HAL_RTC_DeactivateAlarm()). |
1232 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1232 | * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature. |
1233 | 1233 | * @retval HAL status |
|
1234 | /* Disable the write protection for RTC registers */ |
1234 | */ |
1235 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1235 | HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
1236 | 1236 | { |
|
1237 | /* Configure the Alarm register */ |
1237 | __IO uint32_t count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U); |
1238 | if (sAlarm->Alarm == RTC_ALARM_A) |
1238 | uint32_t tmpreg = 0U; |
1239 | { |
1239 | #if defined(RTC_SUBSECOND_SUPPORT) |
1240 | /* Disable the Alarm A interrupt */ |
1240 | uint32_t subsecondtmpreg = 0U; |
1241 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
1241 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1242 | 1242 | ||
1243 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
1243 | /* Check the parameters */ |
1244 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
1244 | assert_param(IS_RTC_FORMAT(Format)); |
1245 | 1245 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
|
1246 | tickstart = HAL_GetTick(); |
1246 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
1247 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
1247 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
1248 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U) |
1248 | #if defined(RTC_SUBSECOND_SUPPORT) |
1249 | { |
1249 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
1250 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1250 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
1251 | { |
1251 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1252 | /* Enable the write protection for RTC registers */ |
1252 | |
1253 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1253 | /* Process Locked */ |
1254 | 1254 | __HAL_LOCK(hrtc); |
|
1255 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1255 | |
1256 | 1256 | /* Change RTC state to BUSY */ |
|
1257 | /* Process Unlocked */ |
1257 | hrtc->State = HAL_RTC_STATE_BUSY; |
1258 | __HAL_UNLOCK(hrtc); |
1258 | |
1259 | 1259 | /* Check the data format (binary or BCD) and store the Alarm time and date |
|
1260 | return HAL_TIMEOUT; |
1260 | configuration accordingly */ |
1261 | } |
1261 | if (Format == RTC_FORMAT_BIN) |
1262 | } |
1262 | { |
1263 | 1263 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
|
1264 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
1264 | { |
1265 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1265 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
1266 | /* Configure the Alarm A Sub Second register */ |
1266 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1267 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
1267 | } |
1268 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1268 | else |
1269 | /* Configure the Alarm state: Enable Alarm */ |
1269 | { |
1270 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
1270 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1271 | } |
1271 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
1272 | else |
1272 | } |
1273 | { |
1273 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
1274 | /* Disable the Alarm B interrupt */ |
1274 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
1275 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
1275 | |
1276 | 1276 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
|
1277 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
1277 | { |
1278 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
1278 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
1279 | 1279 | } |
|
1280 | tickstart = HAL_GetTick(); |
1280 | else |
1281 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
1281 | { |
1282 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U) |
1282 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
1283 | { |
1283 | } |
1284 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1284 | |
1285 | { |
1285 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \ |
1286 | /* Enable the write protection for RTC registers */ |
1286 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \ |
1287 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1287 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
1288 | 1288 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_TR_PM_Pos) | \ |
|
1289 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1289 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \ |
1290 | 1290 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
|
1291 | /* Process Unlocked */ |
1291 | ((uint32_t)sAlarm->AlarmMask)); |
1292 | __HAL_UNLOCK(hrtc); |
1292 | } |
1293 | 1293 | else |
|
1294 | return HAL_TIMEOUT; |
1294 | { |
1295 | } |
1295 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
1296 | } |
1296 | { |
1297 | 1297 | assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
|
1298 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
1298 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1299 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1299 | } |
1300 | /* Configure the Alarm B Sub Second register */ |
1300 | else |
1301 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
1301 | { |
1302 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1302 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1303 | /* Configure the Alarm state: Enable Alarm */ |
1303 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
1304 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
1304 | } |
1305 | } |
1305 | |
1306 | 1306 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
|
1307 | /* Enable the write protection for RTC registers */ |
1307 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
1308 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1308 | |
1309 | 1309 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
|
1310 | /* Change RTC state */ |
1310 | { |
1311 | hrtc->State = HAL_RTC_STATE_READY; |
1311 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
1312 | 1312 | } |
|
1313 | /* Process Unlocked */ |
1313 | else |
1314 | __HAL_UNLOCK(hrtc); |
1314 | { |
1315 | 1315 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
|
1316 | return HAL_OK; |
1316 | } |
1317 | } |
1317 | |
1318 | 1318 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << RTC_ALRMAR_HU_Pos) | \ |
|
1319 | /** |
1319 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << RTC_ALRMAR_MNU_Pos) | \ |
1320 | * @brief Set the specified RTC Alarm with Interrupt. |
1320 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
1321 | * @param hrtc RTC handle |
1321 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << RTC_TR_PM_Pos) | \ |
1322 | * @param sAlarm Pointer to Alarm structure |
1322 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << RTC_ALRMAR_DU_Pos) | \ |
1323 | * @param Format Specifies the format of the entered parameters. |
1323 | ((uint32_t) sAlarm->AlarmDateWeekDaySel) | \ |
1324 | * This parameter can be one of the following values: |
1324 | ((uint32_t) sAlarm->AlarmMask)); |
1325 | * @arg RTC_FORMAT_BIN: Binary data format |
1325 | } |
1326 | * @arg RTC_FORMAT_BCD: BCD data format |
1326 | |
1327 | * @note The Alarm register can only be written when the corresponding Alarm |
1327 | #if defined(RTC_SUBSECOND_SUPPORT) |
1328 | * is disabled (Use the HAL_RTC_DeactivateAlarm()). |
1328 | /* Store the Alarm subseconds configuration */ |
1329 | * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature. |
1329 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | \ |
1330 | * @retval HAL status |
1330 | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
1331 | */ |
1331 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1332 | HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
1332 | |
1333 | { |
1333 | /* Disable the write protection for RTC registers */ |
1334 | uint32_t tickstart = 0; |
1334 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1335 | uint32_t tmpreg = 0; |
1335 | |
1336 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1336 | /* Configure the Alarm register */ |
1337 | uint32_t subsecondtmpreg = 0; |
1337 | if (sAlarm->Alarm == RTC_ALARM_A) |
1338 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1338 | { |
1339 | 1339 | /* Disable the Alarm A */ |
|
1340 | /* Check the parameters */ |
1340 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
1341 | assert_param(IS_RTC_FORMAT(Format)); |
1341 | |
1342 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
1342 | /* Clear the Alarm flag */ |
1343 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
1343 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
1344 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
1344 | |
1345 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1345 | /* Wait till RTC ALRAWF flag is set and if timeout is reached exit */ |
1346 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
1346 | do |
1347 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
1347 | { |
1348 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1348 | count = count - 1U; |
1349 | 1349 | if (count == 0U) |
|
1350 | /* Process Locked */ |
1350 | { |
1351 | __HAL_LOCK(hrtc); |
1351 | /* Enable the write protection for RTC registers */ |
1352 | 1352 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
|
1353 | hrtc->State = HAL_RTC_STATE_BUSY; |
1353 | |
1354 | 1354 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
|
1355 | if (Format == RTC_FORMAT_BIN) |
1355 | |
1356 | { |
1356 | /* Process Unlocked */ |
1357 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
1357 | __HAL_UNLOCK(hrtc); |
1358 | { |
1358 | |
1359 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
1359 | return HAL_TIMEOUT; |
1360 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1360 | } |
1361 | } |
1361 | } while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U); |
1362 | else |
1362 | |
1363 | { |
1363 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
1364 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1364 | #if defined(RTC_SUBSECOND_SUPPORT) |
1365 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
1365 | /* Configure the Alarm A Subseconds register */ |
1366 | } |
1366 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
1367 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
1367 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1368 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
1368 | /* Configure the Alarm state: Enable Alarm */ |
1369 | 1369 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
|
1370 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
1370 | /* Configure the Alarm interrupt */ |
1371 | { |
1371 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRA); |
1372 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
1372 | } |
1373 | } |
1373 | else |
1374 | else |
1374 | { |
1375 | { |
1375 | /* Disable the Alarm B */ |
1376 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
1376 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
1377 | } |
1377 | |
1378 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16U) | \ |
1378 | /* Clear the Alarm flag */ |
1379 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8U) | \ |
1379 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
1380 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
1380 | |
1381 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
1381 | /* Reload the counter */ |
1382 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24U) | \ |
1382 | count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U); |
1383 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
1383 | |
1384 | ((uint32_t)sAlarm->AlarmMask)); |
1384 | /* Wait till RTC ALRBWF flag is set and if timeout is reached exit */ |
1385 | } |
1385 | do |
1386 | else |
1386 | { |
1387 | { |
1387 | count = count - 1U; |
1388 | if ((hrtc->Instance->CR & RTC_CR_FMT) != 0U) |
1388 | if (count == 0U) |
1389 | { |
1389 | { |
1390 | assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
1390 | /* Enable the write protection for RTC registers */ |
1391 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
1391 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1392 | } |
1392 | |
1393 | else |
1393 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1394 | { |
1394 | |
1395 | sAlarm->AlarmTime.TimeFormat = 0x00U; |
1395 | /* Process Unlocked */ |
1396 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
1396 | __HAL_UNLOCK(hrtc); |
1397 | } |
1397 | |
1398 | 1398 | return HAL_TIMEOUT; |
|
1399 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
1399 | } |
1400 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
1400 | } while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U); |
1401 | 1401 | ||
1402 | if (sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
1402 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
1403 | { |
1403 | #if defined(RTC_SUBSECOND_SUPPORT) |
1404 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
1404 | /* Configure the Alarm B Subseconds register */ |
1405 | } |
1405 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
1406 | else |
1406 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1407 | { |
1407 | /* Configure the Alarm state: Enable Alarm */ |
1408 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay))); |
1408 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
1409 | } |
1409 | /* Configure the Alarm interrupt */ |
1410 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16U) | \ |
1410 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB); |
1411 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8U) | \ |
1411 | } |
1412 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
1412 | |
1413 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16U) | \ |
1413 | /* RTC Alarm Interrupt Configuration: EXTI configuration */ |
1414 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24U) | \ |
1414 | __HAL_RTC_ALARM_EXTI_ENABLE_IT(); |
1415 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
1415 | __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); |
1416 | ((uint32_t)sAlarm->AlarmMask)); |
1416 | |
1417 | } |
1417 | /* Enable the write protection for RTC registers */ |
1418 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1418 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1419 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
1419 | |
1420 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
1420 | /* Change RTC state back to READY */ |
1421 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1421 | hrtc->State = HAL_RTC_STATE_READY; |
1422 | 1422 | ||
1423 | /* Disable the write protection for RTC registers */ |
1423 | /* Process Unlocked */ |
1424 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1424 | __HAL_UNLOCK(hrtc); |
1425 | 1425 | ||
1426 | /* Configure the Alarm register */ |
1426 | return HAL_OK; |
1427 | if (sAlarm->Alarm == RTC_ALARM_A) |
1427 | } |
1428 | { |
1428 | |
1429 | /* Disable the Alarm A interrupt */ |
1429 | /** |
1430 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
1430 | * @brief Deactivates the specified RTC Alarm. |
1431 | 1431 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
|
1432 | /* Clear flag alarm A */ |
1432 | * the configuration information for RTC. |
1433 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
1433 | * @param Alarm Specifies the Alarm. |
1434 | 1434 | * This parameter can be one of the following values: |
|
1435 | tickstart = HAL_GetTick(); |
1435 | * @arg RTC_ALARM_A: Alarm A |
1436 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
1436 | * @arg RTC_ALARM_B: Alarm B |
1437 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U) |
1437 | * @retval HAL status |
1438 | { |
1438 | */ |
1439 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1439 | HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm) |
1440 | { |
1440 | { |
1441 | /* Enable the write protection for RTC registers */ |
1441 | uint32_t tickstart = 0U; |
1442 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1442 | |
1443 | 1443 | /* Check the parameters */ |
|
1444 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1444 | assert_param(IS_RTC_ALARM(Alarm)); |
1445 | 1445 | ||
1446 | /* Process Unlocked */ |
1446 | /* Process Locked */ |
1447 | __HAL_UNLOCK(hrtc); |
1447 | __HAL_LOCK(hrtc); |
1448 | 1448 | ||
1449 | return HAL_TIMEOUT; |
1449 | hrtc->State = HAL_RTC_STATE_BUSY; |
1450 | } |
1450 | |
1451 | } |
1451 | /* Disable the write protection for RTC registers */ |
1452 | 1452 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
|
1453 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
1453 | |
1454 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1454 | if (Alarm == RTC_ALARM_A) |
1455 | /* Configure the Alarm A Sub Second register */ |
1455 | { |
1456 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
1456 | /* Disable Alarm A */ |
1457 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1457 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
1458 | /* Configure the Alarm state: Enable Alarm */ |
1458 | |
1459 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
1459 | /* In case interrupt mode is used, the interrupt source must be disabled */ |
1460 | /* Configure the Alarm interrupt */ |
1460 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
1461 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRA); |
1461 | |
1462 | } |
1462 | /* Get tick */ |
1463 | else |
1463 | tickstart = HAL_GetTick(); |
1464 | { |
1464 | |
1465 | /* Disable the Alarm B interrupt */ |
1465 | /* Wait till RTC ALRxWF flag is set and if timeout is reached exit */ |
1466 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
1466 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U) |
1467 | 1467 | { |
|
1468 | /* Clear flag alarm B */ |
1468 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1469 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
1469 | { |
1470 | 1470 | /* Enable the write protection for RTC registers */ |
|
1471 | tickstart = HAL_GetTick(); |
1471 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1472 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
1472 | |
1473 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U) |
1473 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1474 | { |
1474 | |
1475 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1475 | /* Process Unlocked */ |
1476 | { |
1476 | __HAL_UNLOCK(hrtc); |
1477 | /* Enable the write protection for RTC registers */ |
1477 | |
1478 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1478 | return HAL_TIMEOUT; |
1479 | 1479 | } |
|
1480 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1480 | } |
1481 | 1481 | } |
|
1482 | /* Process Unlocked */ |
1482 | else |
1483 | __HAL_UNLOCK(hrtc); |
1483 | { |
1484 | 1484 | /* Disable Alarm B */ |
|
1485 | return HAL_TIMEOUT; |
1485 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
1486 | } |
1486 | |
1487 | } |
1487 | /* In case interrupt mode is used, the interrupt source must be disabled */ |
1488 | 1488 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
|
1489 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
1489 | |
1490 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1490 | /* Get tick */ |
1491 | /* Configure the Alarm B Sub Second register */ |
1491 | tickstart = HAL_GetTick(); |
1492 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
1492 | |
1493 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1493 | /* Wait till RTC ALRxWF flag is set and if timeout is reached exit */ |
1494 | /* Configure the Alarm state: Enable Alarm */ |
1494 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U) |
1495 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
1495 | { |
1496 | /* Configure the Alarm interrupt */ |
1496 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1497 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB); |
1497 | { |
1498 | } |
1498 | /* Enable the write protection for RTC registers */ |
1499 | 1499 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
|
1500 | /* RTC Alarm Interrupt Configuration: EXTI configuration */ |
1500 | |
1501 | __HAL_RTC_ALARM_EXTI_ENABLE_IT(); |
1501 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1502 | 1502 | ||
1503 | __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); |
1503 | /* Process Unlocked */ |
1504 | 1504 | __HAL_UNLOCK(hrtc); |
|
1505 | /* Enable the write protection for RTC registers */ |
1505 | |
1506 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1506 | return HAL_TIMEOUT; |
1507 | 1507 | } |
|
1508 | hrtc->State = HAL_RTC_STATE_READY; |
1508 | } |
1509 | 1509 | } |
|
1510 | /* Process Unlocked */ |
1510 | |
1511 | __HAL_UNLOCK(hrtc); |
1511 | /* Enable the write protection for RTC registers */ |
1512 | 1512 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
|
1513 | return HAL_OK; |
1513 | |
1514 | } |
1514 | hrtc->State = HAL_RTC_STATE_READY; |
1515 | 1515 | ||
1516 | /** |
1516 | /* Process Unlocked */ |
1517 | * @brief Deactivate the specified RTC Alarm. |
1517 | __HAL_UNLOCK(hrtc); |
1518 | * @param hrtc RTC handle |
1518 | |
1519 | * @param Alarm Specifies the Alarm. |
1519 | return HAL_OK; |
1520 | * This parameter can be one of the following values: |
1520 | } |
1521 | * @arg RTC_ALARM_A: AlarmA |
1521 | |
1522 | * @arg RTC_ALARM_B: AlarmB |
1522 | /** |
1523 | * @retval HAL status |
1523 | * @brief Gets the RTC Alarm value and masks. |
1524 | */ |
1524 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1525 | HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm) |
1525 | * the configuration information for RTC. |
1526 | { |
1526 | * @param sAlarm Pointer to Date structure |
1527 | uint32_t tickstart; |
1527 | * @param Alarm Specifies the Alarm. |
1528 | 1528 | * This parameter can be one of the following values: |
|
1529 | /* Check the parameters */ |
1529 | * @arg RTC_ALARM_A: Alarm A |
1530 | assert_param(IS_RTC_ALARM(Alarm)); |
1530 | * @arg RTC_ALARM_B: Alarm B |
1531 | 1531 | * @param Format Specifies the format of the entered parameters. |
|
1532 | /* Process Locked */ |
1532 | * This parameter can be one of the following values: |
1533 | __HAL_LOCK(hrtc); |
1533 | * @arg RTC_FORMAT_BIN: Binary data format |
1534 | 1534 | * @arg RTC_FORMAT_BCD: BCD data format |
|
1535 | hrtc->State = HAL_RTC_STATE_BUSY; |
1535 | * @retval HAL status |
1536 | 1536 | */ |
|
1537 | /* Disable the write protection for RTC registers */ |
1537 | HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format) |
1538 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1538 | { |
1539 | 1539 | uint32_t tmpreg = 0U; |
|
1540 | if (Alarm == RTC_ALARM_A) |
1540 | #if defined(RTC_SUBSECOND_SUPPORT) |
1541 | { |
1541 | uint32_t subsecondtmpreg = 0U; |
1542 | /* AlarmA */ |
1542 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1543 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
1543 | |
1544 | 1544 | /* Check the parameters */ |
|
1545 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
1545 | assert_param(IS_RTC_FORMAT(Format)); |
1546 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
1546 | assert_param(IS_RTC_ALARM(Alarm)); |
1547 | 1547 | ||
1548 | tickstart = HAL_GetTick(); |
1548 | if (Alarm == RTC_ALARM_A) |
1549 | 1549 | { |
|
1550 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
1550 | sAlarm->Alarm = RTC_ALARM_A; |
1551 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == 0U) |
1551 | |
1552 | { |
1552 | tmpreg = (uint32_t)(hrtc->Instance->ALRMAR); |
1553 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1553 | #if defined(RTC_SUBSECOND_SUPPORT) |
1554 | { |
1554 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR) & RTC_ALRMASSR_SS); |
1555 | /* Enable the write protection for RTC registers */ |
1555 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1556 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1556 | } |
1557 | 1557 | else |
|
1558 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1558 | { |
1559 | 1559 | sAlarm->Alarm = RTC_ALARM_B; |
|
1560 | /* Process Unlocked */ |
1560 | |
1561 | __HAL_UNLOCK(hrtc); |
1561 | tmpreg = (uint32_t)(hrtc->Instance->ALRMBR); |
1562 | 1562 | #if defined(RTC_SUBSECOND_SUPPORT) |
|
1563 | return HAL_TIMEOUT; |
1563 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS); |
1564 | } |
1564 | #endif /* RTC_SUBSECOND_SUPPORT */ |
1565 | } |
1565 | } |
1566 | } |
1566 | |
1567 | else |
1567 | /* Fill the structure with the read parameters */ |
1568 | { |
1568 | sAlarm->AlarmTime.Hours = (uint8_t) ((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> RTC_ALRMAR_HU_Pos); |
1569 | /* AlarmB */ |
1569 | sAlarm->AlarmTime.Minutes = (uint8_t) ((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> RTC_ALRMAR_MNU_Pos); |
1570 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
1570 | sAlarm->AlarmTime.Seconds = (uint8_t) ( tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)); |
1571 | 1571 | sAlarm->AlarmTime.TimeFormat = (uint8_t) ((tmpreg & RTC_ALRMAR_PM) >> RTC_TR_PM_Pos); |
|
1572 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
1572 | #if defined(RTC_SUBSECOND_SUPPORT) |
1573 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
1573 | sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg; |
1574 | 1574 | #endif /* RTC_SUBSECOND_SUPPORT */ |
|
1575 | tickstart = HAL_GetTick(); |
1575 | sAlarm->AlarmDateWeekDay = (uint8_t) ((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> RTC_ALRMAR_DU_Pos); |
1576 | 1576 | sAlarm->AlarmDateWeekDaySel = (uint32_t) (tmpreg & RTC_ALRMAR_WDSEL); |
|
1577 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
1577 | sAlarm->AlarmMask = (uint32_t) (tmpreg & RTC_ALARMMASK_ALL); |
1578 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == 0U) |
1578 | |
1579 | { |
1579 | if (Format == RTC_FORMAT_BIN) |
1580 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1580 | { |
1581 | { |
1581 | sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
1582 | /* Enable the write protection for RTC registers */ |
1582 | sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes); |
1583 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1583 | sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds); |
1584 | 1584 | sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
|
1585 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1585 | } |
1586 | 1586 | ||
1587 | /* Process Unlocked */ |
1587 | return HAL_OK; |
1588 | __HAL_UNLOCK(hrtc); |
1588 | } |
1589 | 1589 | ||
1590 | return HAL_TIMEOUT; |
1590 | /** |
1591 | } |
1591 | * @brief Handles Alarm interrupt request. |
1592 | } |
1592 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1593 | } |
1593 | * the configuration information for RTC. |
1594 | /* Enable the write protection for RTC registers */ |
1594 | * @retval None |
1595 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1595 | */ |
1596 | 1596 | void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc) |
|
1597 | hrtc->State = HAL_RTC_STATE_READY; |
1597 | { |
1598 | 1598 | /* Clear the EXTI's line Flag for RTC Alarm */ |
|
1599 | /* Process Unlocked */ |
1599 | __HAL_RTC_ALARM_EXTI_CLEAR_FLAG(); |
1600 | __HAL_UNLOCK(hrtc); |
1600 | |
1601 | 1601 | /* Get the Alarm A interrupt source enable status */ |
|
1602 | return HAL_OK; |
1602 | if (__HAL_RTC_ALARM_GET_IT_SOURCE(hrtc, RTC_IT_ALRA) != 0U) |
1603 | } |
1603 | { |
1604 | 1604 | /* Get the pending status of the Alarm A Interrupt */ |
|
1605 | /** |
1605 | if (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) != 0U) |
1606 | * @brief Get the RTC Alarm value and masks. |
1606 | { |
1607 | * @param hrtc RTC handle |
1607 | /* Clear the Alarm A interrupt pending bit */ |
1608 | * @param sAlarm Pointer to Date structure |
1608 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
1609 | * @param Alarm Specifies the Alarm. |
1609 | |
1610 | * This parameter can be one of the following values: |
1610 | /* Alarm A callback */ |
1611 | * @arg RTC_ALARM_A: AlarmA |
1611 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
1612 | * @arg RTC_ALARM_B: AlarmB |
1612 | hrtc->AlarmAEventCallback(hrtc); |
1613 | * @param Format Specifies the format of the entered parameters. |
1613 | #else |
1614 | * This parameter can be one of the following values: |
1614 | HAL_RTC_AlarmAEventCallback(hrtc); |
1615 | * @arg RTC_FORMAT_BIN: Binary data format |
1615 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
1616 | * @arg RTC_FORMAT_BCD: BCD data format |
1616 | } |
1617 | * @retval HAL status |
1617 | } |
1618 | */ |
1618 | |
1619 | HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format) |
1619 | /* Get the Alarm B interrupt source enable status */ |
1620 | { |
1620 | if (__HAL_RTC_ALARM_GET_IT_SOURCE(hrtc, RTC_IT_ALRB) != 0U) |
1621 | uint32_t tmpreg; |
1621 | { |
1622 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1622 | /* Get the pending status of the Alarm B Interrupt */ |
1623 | uint32_t subsecondtmpreg; |
1623 | if (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) != 0U) |
1624 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1624 | { |
1625 | 1625 | /* Clear the Alarm B interrupt pending bit */ |
|
1626 | /* Check the parameters */ |
1626 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
1627 | assert_param(IS_RTC_FORMAT(Format)); |
1627 | |
1628 | assert_param(IS_RTC_ALARM(Alarm)); |
1628 | /* Alarm B callback */ |
1629 | 1629 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
|
1630 | if (Alarm == RTC_ALARM_A) |
1630 | hrtc->AlarmBEventCallback(hrtc); |
1631 | { |
1631 | #else |
1632 | /* AlarmA */ |
1632 | HAL_RTCEx_AlarmBEventCallback(hrtc); |
1633 | sAlarm->Alarm = RTC_ALARM_A; |
1633 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
1634 | 1634 | } |
|
1635 | tmpreg = (uint32_t)(hrtc->Instance->ALRMAR); |
1635 | } |
1636 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1636 | |
1637 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR) & RTC_ALRMASSR_SS); |
1637 | /* Change RTC state */ |
1638 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1638 | hrtc->State = HAL_RTC_STATE_READY; |
1639 | } |
1639 | } |
1640 | else |
1640 | |
1641 | { |
1641 | /** |
1642 | sAlarm->Alarm = RTC_ALARM_B; |
1642 | * @brief Alarm A callback. |
1643 | 1643 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
|
1644 | tmpreg = (uint32_t)(hrtc->Instance->ALRMBR); |
1644 | * the configuration information for RTC. |
1645 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1645 | * @retval None |
1646 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS); |
1646 | */ |
1647 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1647 | __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) |
1648 | } |
1648 | { |
1649 | 1649 | /* Prevent unused argument(s) compilation warning */ |
|
1650 | /* Fill the structure with the read parameters */ |
1650 | UNUSED(hrtc); |
1651 | sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16U); |
1651 | |
1652 | sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8U); |
1652 | /* NOTE: This function should not be modified, when the callback is needed, |
1653 | sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)); |
1653 | the HAL_RTC_AlarmAEventCallback could be implemented in the user file |
1654 | sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16U); |
1654 | */ |
1655 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
1655 | } |
1656 | sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg; |
1656 | |
1657 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
1657 | /** |
1658 | sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24); |
1658 | * @brief Handles Alarm A Polling request. |
1659 | sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL); |
1659 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1660 | sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL); |
1660 | * the configuration information for RTC. |
1661 | 1661 | * @param Timeout Timeout duration |
|
1662 | if (Format == RTC_FORMAT_BIN) |
1662 | * @retval HAL status |
1663 | { |
1663 | */ |
1664 | sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
1664 | HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
1665 | sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes); |
1665 | { |
1666 | sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds); |
1666 | uint32_t tickstart = 0U; |
1667 | sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
1667 | |
1668 | } |
1668 | /* Get tick */ |
1669 | 1669 | tickstart = HAL_GetTick(); |
|
1670 | return HAL_OK; |
1670 | |
1671 | } |
1671 | /* Wait till RTC ALRAF flag is set and if timeout is reached exit */ |
1672 | 1672 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == 0U) |
|
1673 | /** |
1673 | { |
1674 | * @brief Handle Alarm interrupt request. |
1674 | if (Timeout != HAL_MAX_DELAY) |
1675 | * @param hrtc RTC handle |
1675 | { |
1676 | * @retval None |
1676 | if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) |
1677 | */ |
1677 | { |
1678 | void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc) |
1678 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1679 | { |
1679 | return HAL_TIMEOUT; |
1680 | /* Get the AlarmA interrupt source enable status */ |
1680 | } |
1681 | if (__HAL_RTC_ALARM_GET_IT_SOURCE(hrtc, RTC_IT_ALRA) != 0U) |
1681 | } |
1682 | { |
1682 | } |
1683 | /* Get the pending status of the AlarmA Interrupt */ |
1683 | |
1684 | if (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) != 0U) |
1684 | /* Clear the Alarm flag */ |
1685 | { |
1685 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
1686 | /* AlarmA callback */ |
1686 | |
1687 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
1687 | /* Change RTC state */ |
1688 | hrtc->AlarmAEventCallback(hrtc); |
1688 | hrtc->State = HAL_RTC_STATE_READY; |
1689 | #else |
1689 | |
1690 | HAL_RTC_AlarmAEventCallback(hrtc); |
1690 | return HAL_OK; |
1691 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
1691 | } |
1692 | 1692 | ||
1693 | /* Clear the AlarmA interrupt pending bit */ |
1693 | /** |
1694 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
1694 | * @} |
1695 | } |
1695 | */ |
1696 | } |
1696 | |
1697 | 1697 | /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions |
|
1698 | /* Get the AlarmB interrupt source enable status */ |
1698 | * @brief Peripheral Control functions |
1699 | if (__HAL_RTC_ALARM_GET_IT_SOURCE(hrtc, RTC_IT_ALRB) != 0U) |
1699 | * |
1700 | { |
1700 | @verbatim |
1701 | /* Get the pending status of the AlarmB Interrupt */ |
1701 | =============================================================================== |
1702 | if (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) != 0U) |
1702 | ##### Peripheral Control functions ##### |
1703 | { |
1703 | =============================================================================== |
1704 | /* AlarmB callback */ |
1704 | [..] |
1705 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
1705 | This subsection provides functions allowing to |
1706 | hrtc->AlarmBEventCallback(hrtc); |
1706 | (+) Wait for RTC Time and Date Synchronization |
1707 | #else |
1707 | (+) Manage RTC Summer or Winter time change |
1708 | HAL_RTCEx_AlarmBEventCallback(hrtc); |
1708 | |
1709 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
1709 | @endverbatim |
1710 | 1710 | * @{ |
|
1711 | /* Clear the AlarmB interrupt pending bit */ |
1711 | */ |
1712 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
1712 | |
1713 | } |
1713 | /** |
1714 | } |
1714 | * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are |
1715 | /* Clear the EXTI's line Flag for RTC Alarm */ |
1715 | * synchronized with RTC APB clock. |
1716 | __HAL_RTC_ALARM_EXTI_CLEAR_FLAG(); |
1716 | * @note The RTC Resynchronization mode is write protected, use the |
1717 | 1717 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
|
1718 | /* Change RTC state */ |
1718 | * @note To read the calendar through the shadow registers after Calendar |
1719 | hrtc->State = HAL_RTC_STATE_READY; |
1719 | * initialization, calendar update or after wakeup from low power modes |
1720 | } |
1720 | * the software must first clear the RSF flag. |
1721 | 1721 | * The software must then wait until it is set again before reading |
|
1722 | /** |
1722 | * the calendar, which means that the calendar registers have been |
1723 | * @brief Alarm A callback. |
1723 | * correctly copied into the RTC_TR and RTC_DR shadow registers. |
1724 | * @param hrtc RTC handle |
1724 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1725 | * @retval None |
1725 | * the configuration information for RTC. |
1726 | */ |
1726 | * @retval HAL status |
1727 | __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) |
1727 | */ |
1728 | { |
1728 | HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc) |
1729 | /* Prevent unused argument(s) compilation warning */ |
1729 | { |
1730 | UNUSED(hrtc); |
1730 | uint32_t tickstart = 0U; |
1731 | 1731 | ||
1732 | /* NOTE : This function Should not be modified, when the callback is needed, |
1732 | /* Clear RSF flag, keep reserved bits at reset values (setting other flags has no effect) */ |
1733 | the HAL_RTC_AlarmAEventCallback could be implemented in the user file |
1733 | hrtc->Instance->ISR = ((uint32_t)(RTC_RSF_MASK & RTC_ISR_RESERVED_MASK)); |
1734 | */ |
1734 | |
1735 | } |
1735 | /* Get tick */ |
1736 | 1736 | tickstart = HAL_GetTick(); |
|
1737 | /** |
1737 | |
1738 | * @brief Handle AlarmA Polling request. |
1738 | /* Wait the registers to be synchronised */ |
1739 | * @param hrtc RTC handle |
1739 | while ((hrtc->Instance->ISR & RTC_ISR_RSF) == 0U) |
1740 | * @param Timeout Timeout duration |
1740 | { |
1741 | * @retval HAL status |
1741 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1742 | */ |
1742 | { |
1743 | HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
1743 | return HAL_TIMEOUT; |
1744 | { |
1744 | } |
1745 | 1745 | } |
|
1746 | uint32_t tickstart = HAL_GetTick(); |
1746 | |
1747 | 1747 | return HAL_OK; |
|
1748 | while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == 0U) |
1748 | } |
1749 | { |
1749 | |
1750 | if (Timeout != HAL_MAX_DELAY) |
1750 | /** |
1751 | { |
1751 | * @brief Daylight Saving Time, adds one hour to the calendar in one |
1752 | if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) |
1752 | * single operation without going through the initialization procedure. |
1753 | { |
1753 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1754 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
1754 | * the configuration information for RTC. |
1755 | return HAL_TIMEOUT; |
1755 | * @retval None |
1756 | } |
1756 | */ |
1757 | } |
1757 | void HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc) |
1758 | } |
1758 | { |
1759 | 1759 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
|
1760 | /* Clear the Alarm interrupt pending bit */ |
1760 | SET_BIT(hrtc->Instance->CR, RTC_CR_ADD1H); |
1761 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
1761 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1762 | 1762 | } |
|
1763 | /* Change RTC state */ |
1763 | |
1764 | hrtc->State = HAL_RTC_STATE_READY; |
1764 | /** |
1765 | 1765 | * @brief Daylight Saving Time, subtracts one hour from the calendar in one |
|
1766 | return HAL_OK; |
1766 | * single operation without going through the initialization procedure. |
1767 | } |
1767 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1768 | 1768 | * the configuration information for RTC. |
|
1769 | /** |
1769 | * @retval None |
1770 | * @} |
1770 | */ |
1771 | */ |
1771 | void HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc) |
1772 | 1772 | { |
|
1773 | /** @addtogroup RTC_Exported_Functions_Group4 |
1773 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1774 | * @brief Peripheral Control functions |
1774 | SET_BIT(hrtc->Instance->CR, RTC_CR_SUB1H); |
1775 | * |
1775 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1776 | @verbatim |
1776 | } |
1777 | =============================================================================== |
1777 | |
1778 | ##### Peripheral Control functions ##### |
1778 | /** |
1779 | =============================================================================== |
1779 | * @brief Daylight Saving Time, sets the store operation bit. |
1780 | [..] |
1780 | * @note It can be used by the software in order to memorize the DST status. |
1781 | This subsection provides functions allowing to |
1781 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1782 | (+) Wait for RTC Time and Date Synchronization |
1782 | * the configuration information for RTC. |
1783 | 1783 | * @retval None |
|
1784 | @endverbatim |
1784 | */ |
1785 | * @{ |
1785 | void HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc) |
1786 | */ |
1786 | { |
1787 | 1787 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
|
1788 | /** |
1788 | SET_BIT(hrtc->Instance->CR, RTC_CR_BKP); |
1789 | * @brief Wait until the RTC Time and Date registers (RTC_TR and RTC_DR) are |
1789 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1790 | * synchronized with RTC APB clock. |
1790 | } |
1791 | * @note The RTC Resynchronization mode is write protected, use the |
1791 | |
1792 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
1792 | /** |
1793 | * @note To read the calendar through the shadow registers after Calendar |
1793 | * @brief Daylight Saving Time, clears the store operation bit. |
1794 | * initialization, calendar update or after wakeup from low power modes |
1794 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1795 | * the software must first clear the RSF flag. |
1795 | * the configuration information for RTC. |
1796 | * The software must then wait until it is set again before reading |
1796 | * @retval None |
1797 | * the calendar, which means that the calendar registers have been |
1797 | */ |
1798 | * correctly copied into the RTC_TR and RTC_DR shadow registers. |
1798 | void HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc) |
1799 | * @param hrtc RTC handle |
1799 | { |
1800 | * @retval HAL status |
1800 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
1801 | */ |
1801 | CLEAR_BIT(hrtc->Instance->CR, RTC_CR_BKP); |
1802 | HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc) |
1802 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
1803 | { |
1803 | } |
1804 | uint32_t tickstart; |
1804 | |
1805 | 1805 | /** |
|
1806 | #if defined (RTC_CR_BYPSHAD) |
1806 | * @brief Daylight Saving Time, reads the store operation bit. |
1807 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
1807 | * @param hrtc RTC handle |
1808 | if ((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
1808 | * @retval operation see RTC_StoreOperation_Definitions |
1809 | #endif /* RTC_CR_BYPSHAD */ |
1809 | */ |
1810 | { |
1810 | uint32_t HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc) |
1811 | /* Clear RSF flag */ |
1811 | { |
1812 | hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK; |
1812 | return READ_BIT(hrtc->Instance->CR, RTC_CR_BKP); |
1813 | 1813 | } |
|
1814 | tickstart = HAL_GetTick(); |
1814 | |
1815 | 1815 | /** |
|
1816 | /* Wait the registers to be synchronised */ |
1816 | * @} |
1817 | while ((hrtc->Instance->ISR & RTC_ISR_RSF) == 0U) |
1817 | */ |
1818 | { |
1818 | |
1819 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1819 | /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions |
1820 | { |
1820 | * @brief Peripheral State functions |
1821 | return HAL_TIMEOUT; |
1821 | * |
1822 | } |
1822 | @verbatim |
1823 | } |
1823 | =============================================================================== |
1824 | } |
1824 | ##### Peripheral State functions ##### |
1825 | 1825 | =============================================================================== |
|
1826 | return HAL_OK; |
1826 | [..] |
1827 | } |
1827 | This subsection provides functions allowing to |
1828 | 1828 | (+) Get RTC state |
|
1829 | /** |
1829 | |
1830 | * @} |
1830 | @endverbatim |
1831 | */ |
1831 | * @{ |
1832 | 1832 | */ |
|
1833 | /** @addtogroup RTC_Exported_Functions_Group5 |
1833 | /** |
1834 | * @brief Peripheral State functions |
1834 | * @brief Returns the RTC state. |
1835 | * |
1835 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1836 | @verbatim |
1836 | * the configuration information for RTC. |
1837 | =============================================================================== |
1837 | * @retval HAL state |
1838 | ##### Peripheral State functions ##### |
1838 | */ |
1839 | =============================================================================== |
1839 | HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc) |
1840 | [..] |
1840 | { |
1841 | This subsection provides functions allowing to |
1841 | return hrtc->State; |
1842 | (+) Get RTC state |
1842 | } |
1843 | 1843 | ||
1844 | @endverbatim |
1844 | /** |
1845 | * @{ |
1845 | * @} |
1846 | */ |
1846 | */ |
1847 | /** |
1847 | |
1848 | * @brief Return the RTC handle state. |
1848 | |
1849 | * @param hrtc RTC handle |
1849 | /** |
1850 | * @retval HAL state |
1850 | * @} |
1851 | */ |
1851 | */ |
1852 | HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc) |
1852 | |
1853 | { |
1853 | /** @addtogroup RTC_Private_Functions |
1854 | /* Return RTC handle state */ |
1854 | * @{ |
1855 | return hrtc->State; |
1855 | */ |
1856 | } |
1856 | |
1857 | 1857 | /** |
|
1858 | /** |
1858 | * @brief Enters the RTC Initialization mode. |
1859 | * @} |
1859 | * @note The RTC Initialization mode is write protected, use the |
1860 | */ |
1860 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
1861 | /** |
1861 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1862 | * @} |
1862 | * the configuration information for RTC. |
1863 | */ |
1863 | * @retval HAL status |
1864 | 1864 | */ |
|
1865 | /** @addtogroup RTC_Private_Functions |
1865 | HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc) |
1866 | * @{ |
1866 | { |
1867 | */ |
1867 | uint32_t tickstart = 0U; |
1868 | /** |
1868 | HAL_StatusTypeDef status = HAL_OK; |
1869 | * @brief Enter the RTC Initialization mode. |
1869 | |
1870 | * @note The RTC Initialization mode is write protected, use the |
1870 | /* Check that Initialization mode is not already set */ |
1871 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
1871 | if (READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U) |
1872 | * @param hrtc RTC handle |
1872 | { |
1873 | * @retval HAL status |
1873 | /* Set INIT bit to enter Initialization mode */ |
1874 | */ |
1874 | SET_BIT(hrtc->Instance->ISR, RTC_ISR_INIT); |
1875 | HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc) |
1875 | |
1876 | { |
1876 | /* Get tick */ |
1877 | uint32_t tickstart; |
1877 | tickstart = HAL_GetTick(); |
1878 | 1878 | ||
1879 | /* Check if the Initialization mode is set */ |
1879 | /* Wait till RTC is in INIT state and if timeout is reached exit */ |
1880 | if ((hrtc->Instance->ISR & RTC_ISR_INITF) == 0U) |
1880 | while ((READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U) && (status != HAL_ERROR)) |
1881 | { |
1881 | { |
1882 | /* Set the Initialization mode */ |
1882 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1883 | hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK; |
1883 | { |
1884 | 1884 | /* Set RTC state */ |
|
1885 | tickstart = HAL_GetTick(); |
1885 | hrtc->State = HAL_RTC_STATE_ERROR; |
1886 | /* Wait till RTC is in INIT state and if Time out is reached exit */ |
1886 | status = HAL_ERROR; |
1887 | while ((hrtc->Instance->ISR & RTC_ISR_INITF) == 0U) |
1887 | } |
1888 | { |
1888 | } |
1889 | if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
1889 | } |
1890 | { |
1890 | |
1891 | return HAL_TIMEOUT; |
1891 | return status; |
1892 | } |
1892 | } |
1893 | } |
1893 | |
1894 | } |
1894 | /** |
1895 | 1895 | * @brief Exits the RTC Initialization mode. |
|
1896 | return HAL_OK; |
1896 | * @param hrtc pointer to a RTC_HandleTypeDef structure that contains |
1897 | } |
1897 | * the configuration information for RTC. |
1898 | 1898 | * @retval HAL status |
|
1899 | 1899 | */ |
|
1900 | /** |
1900 | HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc) |
1901 | * @brief Convert a 2 digit decimal to BCD format. |
1901 | { |
1902 | * @param Value Byte to be converted |
1902 | HAL_StatusTypeDef status = HAL_OK; |
1903 | * @retval Converted byte |
1903 | |
1904 | */ |
1904 | /* Clear INIT bit to exit Initialization mode */ |
1905 | uint8_t RTC_ByteToBcd2(uint8_t Value) |
1905 | CLEAR_BIT(hrtc->Instance->ISR, RTC_ISR_INIT); |
1906 | { |
1906 | |
1907 | uint32_t bcdhigh = 0U; |
1907 | #if defined(RTC_CR_BYPSHAD) |
1908 | uint8_t Param = Value; |
1908 | /* If CR_BYPSHAD bit = 0, wait for synchro */ |
1909 | 1909 | if (READ_BIT(hrtc->Instance->CR, RTC_CR_BYPSHAD) == 0U) |
|
1910 | while (Param >= 10U) |
1910 | { |
1911 | { |
1911 | if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
1912 | bcdhigh++; |
1912 | { |
1913 | Param -= 10U; |
1913 | /* Set RTC state */ |
1914 | } |
1914 | hrtc->State = HAL_RTC_STATE_ERROR; |
1915 | 1915 | status = HAL_ERROR; |
|
1916 | return ((uint8_t)(bcdhigh << 4U) | Param); |
1916 | } |
1917 | } |
1917 | } |
1918 | 1918 | #else /* RTC_CR_BYPSHAD */ |
|
1919 | /** |
1919 | if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
1920 | * @brief Convert from 2 digit BCD to Binary. |
1920 | { |
1921 | * @param Value BCD value to be converted |
1921 | /* Set RTC state */ |
1922 | * @retval Converted word |
1922 | hrtc->State = HAL_RTC_STATE_ERROR; |
1923 | */ |
1923 | status = HAL_ERROR; |
1924 | uint8_t RTC_Bcd2ToByte(uint8_t Value) |
1924 | } |
1925 | { |
1925 | #endif /* RTC_CR_BYPSHAD */ |
1926 | uint32_t tmp; |
1926 | |
1927 | tmp = (((uint32_t)Value & 0xF0U) >> 4U) * 10U; |
1927 | return status; |
1928 | return (uint8_t)(tmp + ((uint32_t)Value & 0x0FU)); |
1928 | } |
1929 | } |
1929 | |
1930 | 1930 | /** |
|
1931 | /** |
1931 | * @brief Converts a 2-digit number from decimal to BCD format. |
1932 | * @} |
1932 | * @param number decimal-formatted number (from 0 to 99) to be converted |
1933 | */ |
1933 | * @retval Converted byte |
1934 | 1934 | */ |
|
1935 | #endif /* HAL_RTC_MODULE_ENABLED */ |
1935 | uint8_t RTC_ByteToBcd2(uint8_t number) |
1936 | /** |
1936 | { |
1937 | * @} |
1937 | uint32_t bcdhigh = 0U; |
1938 | */ |
1938 | |
1939 | 1939 | while (number >= 10U) |
|
1940 | /** |
1940 | { |
1941 | * @} |
1941 | bcdhigh++; |
1942 | */ |
1942 | number -= 10U; |
1943 | 1943 | } |
|
1944 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
1944 | |
- | 1945 | return ((uint8_t)(bcdhigh << 4U) | number); |
|
- | 1946 | } |
|
- | 1947 | ||
- | 1948 | /** |
|
- | 1949 | * @brief Converts a 2-digit number from BCD to decimal format. |
|
- | 1950 | * @param number BCD-formatted number (from 00 to 99) to be converted |
|
- | 1951 | * @retval Converted word |
|
- | 1952 | */ |
|
- | 1953 | uint8_t RTC_Bcd2ToByte(uint8_t number) |
|
- | 1954 | { |
|
- | 1955 | uint32_t tens = 0U; |
|
- | 1956 | tens = (((uint32_t)number & 0xF0U) >> 4U) * 10U; |
|
- | 1957 | return (uint8_t)(tens + ((uint32_t)number & 0x0FU)); |
|
- | 1958 | } |
|
- | 1959 | ||
- | 1960 | /** |
|
- | 1961 | * @} |
|
- | 1962 | */ |
|
- | 1963 | ||
- | 1964 | #endif /* HAL_RTC_MODULE_ENABLED */ |
|
- | 1965 | /** |
|
- | 1966 | * @} |
|
- | 1967 | */ |
|
- | 1968 | ||
- | 1969 | /** |
|
- | 1970 | * @} |
|
- | 1971 | */ |