annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_rtc.c @ 69:1eeab3e09f4d

1.3.8 forum release
author heinrichsweikamp
date Thu, 30 Aug 2018 21:48:21 +0200
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_rtc.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief RTC HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Real Time Clock (RTC) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + RTC Time and Date functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + RTC Alarm functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 * + Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ##### Backup Domain Operating Condition #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 [..] The real-time clock (RTC), the RTC backup registers, and the backup
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 SRAM (BKP SRAM) can be powered from the VBAT voltage when the main
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 VDD supply is powered off.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 To retain the content of the RTC backup registers, backup SRAM, and supply
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 the RTC when VDD is turned off, VBAT pin can be connected to an optional
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 standby voltage supplied by a battery or by another source.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 [..] To allow the RTC operating even when the main digital supply (VDD) is turned
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 off, the VBAT pin powers the following blocks:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (#) The RTC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 (#) The LSE oscillator
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (#) The backup SRAM when the low power backup regulator is enabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 (#) PC13 to PC15 I/Os, plus PI8 I/O (when available)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 [..] When the backup domain is supplied by VDD (analog switch connected to VDD),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 the following pins are available:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 (#) PC14 and PC15 can be used as either GPIO or LSE pins
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (#) PC13 can be used as a GPIO or as the RTC_AF1 pin
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 (#) PI8 can be used as a GPIO or as the RTC_AF2 pin
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 because VDD is not present), the following pins are available:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 (#) PC14 and PC15 can be used as LSE pins only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 (#) PC13 can be used as the RTC_AF1 pin
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 (#) PI8 can be used as the RTC_AF2 pin
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 ##### Backup Domain Reset #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 ==================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 [..] The backup domain reset sets all RTC registers and the RCC_BDCR register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 to their reset values. The BKPSRAM is not affected by this reset. The only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 way to reset the BKPSRAM is through the Flash interface by requesting
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 a protection level change from 1 to 0.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 [..] A backup domain reset is generated when one of the following events occurs:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 (#) Software reset, triggered by setting the BDRST bit in the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 RCC Backup domain control register (RCC_BDCR).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 (#) VDD or VBAT power on, if both supplies have previously been powered off.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 ##### Backup Domain Access #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 ==================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 [..] After reset, the backup domain (RTC registers, RTC backup data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 registers and backup SRAM) is protected against possible unwanted write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 accesses.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 [..] To enable access to the RTC Domain and RTC registers, proceed as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 (+) Enable the Power Controller (PWR) APB1 interface clock using the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 __HAL_RCC_PWR_CLK_ENABLE() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 ==================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 (+) Enable the RTC domain access (see description in the section above).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 format using the HAL_RTC_Init() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 *** Time and Date configuration ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 ===================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 and HAL_RTC_SetDate() functions.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 *** Alarm configuration ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 ===========================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 ##### RTC and low power modes #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 ==================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 [..] The MCU can be woken up from a low power mode by an RTC alternate
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 RTC wake-up, RTC tamper event detection and RTC time stamp event detection.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 These RTC alternate functions can wake up the system from the Stop and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 Standby low power modes.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 [..] The system can also wake up from low power modes without depending
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 on an external interrupt (Auto-wake-up mode), by using the RTC alarm
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 or the RTC wake-up events.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 [..] The RTC provides a programmable time base for waking up from the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 Stop or Standby mode at regular intervals.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 Wake-up from STOP and STANDBY modes is possible only when the RTC clock source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 is LSE or LSI.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 /** @defgroup RTC RTC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * @brief RTC HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 #ifdef HAL_RTC_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 /** @defgroup RTC_Exported_Functions RTC Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 [..] This section provides functions allowing to initialize and configure the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 RTC registers Write protection, enter and exit the RTC initialization mode,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 RTC registers synchronization check and reference clock detection enable.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 It is split into 2 programmable prescalers to minimize power consumption.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 (++) A 7-bit asynchronous prescaler and a 13-bit synchronous prescaler.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 (++) When both prescalers are used, it is recommended to configure the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 asynchronous prescaler to a high value to minimize power consumption.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 (#) All RTC registers are Write protected. Writing to the RTC registers
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 is enabled by writing a key into the Write Protection register, RTC_WPR.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 (#) To configure the RTC Calendar, user application should enter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 initialization mode. In this mode, the calendar counter is stopped
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 and its value can be updated. When the initialization sequence is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 complete, the calendar restarts counting after 4 RTCCLK cycles.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 (#) To read the calendar through the shadow registers after Calendar
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 initialization, calendar update or after wake-up from low power modes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 the software must first clear the RSF flag. The software must then
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 wait until it is set again before reading the calendar, which means
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 that the calendar registers have been correctly copied into the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 implements the above software sequence (RSF clear and RSF check).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 * @brief Initializes the RTC peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 /* Check the RTC peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 if(hrtc == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 assert_param (IS_RTC_OUTPUT(hrtc->Init.OutPut));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 assert_param (IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 if(hrtc->State == HAL_RTC_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 /* Initialize RTC MSP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 HAL_RTC_MspInit(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 /* Set RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 /* Set RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 /* Clear RTC_CR FMT, OSEL and POL Bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 /* Set RTC_CR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 /* Configure the RTC PRER */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 /* Exit Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 /* Set RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 * @brief DeInitializes the RTC peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 * @note This function doesn't reset the RTC Backup Data registers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 /* Set RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 /* Set RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 /* Reset TR, DR and CR registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 hrtc->Instance->TR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 hrtc->Instance->DR = (uint32_t)0x00002101;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 /* Reset All CR bits except CR[2:0] */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 hrtc->Instance->CR &= (uint32_t)0x00000007;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 /* Wait till WUTWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 /* Set RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 /* Reset all RTC CR register bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 hrtc->Instance->CR &= (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 hrtc->Instance->WUTR = (uint32_t)0x0000FFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 hrtc->Instance->PRER = (uint32_t)0x007F00FF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 hrtc->Instance->CALIBR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 hrtc->Instance->ALRMAR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 hrtc->Instance->ALRMBR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 hrtc->Instance->SHIFTR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 hrtc->Instance->CALR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 hrtc->Instance->ALRMASSR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 hrtc->Instance->ALRMBSSR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 /* Reset ISR register and exit initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 hrtc->Instance->ISR = (uint32_t)0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 /* Reset Tamper and alternate functions configuration register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 hrtc->Instance->TAFCR = 0x00000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 /* De-Initialize RTC MSP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 HAL_RTC_MspDeInit(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 hrtc->State = HAL_RTC_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 /* Release Lock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 * @brief Initializes the RTC MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 __weak void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 the HAL_RTC_MspInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 * @brief DeInitializes the RTC MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 the HAL_RTC_MspDeInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 * @brief RTC Time and Date functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 ##### RTC Time and Date functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 [..] This section provides functions allowing to configure Time and Date features
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 * @brief Sets RTC current time.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 * @param sTime: Pointer to Time structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 * @param Format: Specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 * @arg RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 * @arg RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 assert_param(IS_RTC_HOUR12(sTime->Hours));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 sTime->TimeFormat = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 assert_param(IS_RTC_HOUR24(sTime->Hours));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 assert_param(IS_RTC_MINUTES(sTime->Minutes));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 assert_param(IS_RTC_SECONDS(sTime->Seconds));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 (((uint32_t)sTime->TimeFormat) << 16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 tmpreg = RTC_Bcd2ToByte(sTime->Hours);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 assert_param(IS_RTC_HOUR12(tmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 sTime->TimeFormat = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 tmpreg = (((uint32_t)(sTime->Hours) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 ((uint32_t)(sTime->Minutes) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 ((uint32_t)sTime->Seconds) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 ((uint32_t)(sTime->TimeFormat) << 16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 /* Set RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 /* Set the RTC_TR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 /* Clear the bits to be configured */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 /* Configure the RTC_CR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 /* Exit Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 * @brief Gets RTC current time.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 * @param sTime: Pointer to Time structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 * @param Format: Specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 * @arg RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 * @arg RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 * Reading RTC current time locks the values in calendar shadow registers until Current date is read.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 /* Get subseconds values from the correspondent registers*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 /* Get the TR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 /* Fill the structure fields with the read parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 /* Check the input parameters format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 /* Convert the time structure parameters to Binary format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 * @brief Sets RTC current date.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 * @param sDate: Pointer to date structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 * @param Format: specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 * @arg RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 * @arg RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 uint32_t datetmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 if((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10) == 0x10))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10)) + (uint8_t)0x0A);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 assert_param(IS_RTC_WEEKDAY(sDate->WeekDay));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 assert_param(IS_RTC_YEAR(sDate->Year));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 assert_param(IS_RTC_MONTH(sDate->Month));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 assert_param(IS_RTC_DATE(sDate->Date));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 ((uint32_t)sDate->WeekDay << 13));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 datetmpreg = RTC_Bcd2ToByte(sDate->Month);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 assert_param(IS_RTC_MONTH(datetmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 datetmpreg = RTC_Bcd2ToByte(sDate->Date);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 assert_param(IS_RTC_DATE(datetmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 datetmpreg = ((((uint32_t)sDate->Year) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 (((uint32_t)sDate->Month) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 ((uint32_t)sDate->Date) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 (((uint32_t)sDate->WeekDay) << 13));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 /* Set Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 if(RTC_EnterInitMode(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 /* Set RTC state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 /* Set the RTC_DR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 /* Exit Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 hrtc->State = HAL_RTC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 hrtc->State = HAL_RTC_STATE_READY ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 * @brief Gets RTC current date.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 * @param sDate: Pointer to Date structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 * @param Format: Specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 * @arg RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 * @arg RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 * Reading RTC current time locks the values in calendar shadow registers until Current date is read.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 uint32_t datetmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 /* Get the DR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 /* Fill the structure fields with the read parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 /* Check the input parameters format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 /* Convert the date structure parameters to Binary format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 * @brief RTC Alarm functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 ##### RTC Alarm functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 [..] This section provides functions allowing to configure Alarm feature
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 * @brief Sets the specified RTC Alarm.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 * @param sAlarm: Pointer to Alarm structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 * @param Format: Specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 * @arg RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 * @arg RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 uint32_t tmpreg = 0, subsecondtmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 sAlarm->AlarmTime.TimeFormat = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 ((uint32_t)sAlarm->AlarmMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 assert_param(IS_RTC_HOUR12(tmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 sAlarm->AlarmTime.TimeFormat = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 ((uint32_t)sAlarm->AlarmMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 /* Configure the Alarm A or Alarm B Sub Second registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 /* Configure the Alarm register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 if(sAlarm->Alarm == RTC_ALARM_A)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 /* Disable the Alarm A interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 __HAL_RTC_ALARMA_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 /* In case of interrupt mode is used, the interrupt source must disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 /* Configure the Alarm A Sub Second register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 hrtc->Instance->ALRMASSR = subsecondtmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 /* Configure the Alarm state: Enable Alarm */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 __HAL_RTC_ALARMA_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 /* Disable the Alarm B interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 __HAL_RTC_ALARMB_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 /* In case of interrupt mode is used, the interrupt source must disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 /* Configure the Alarm B Sub Second register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 /* Configure the Alarm state: Enable Alarm */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 __HAL_RTC_ALARMB_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 * @brief Sets the specified RTC Alarm with Interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 * @param sAlarm: Pointer to Alarm structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 * @param Format: Specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 * @arg RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 * @arg RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 uint32_t tmpreg = 0, subsecondtmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 sAlarm->AlarmTime.TimeFormat = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 ((uint32_t)sAlarm->AlarmMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 assert_param(IS_RTC_HOUR12(tmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 sAlarm->AlarmTime.TimeFormat = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 ((uint32_t)sAlarm->AlarmMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 /* Configure the Alarm A or Alarm B Sub Second registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 /* Configure the Alarm register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 if(sAlarm->Alarm == RTC_ALARM_A)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 /* Disable the Alarm A interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 __HAL_RTC_ALARMA_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 /* Clear flag alarm A */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 /* Configure the Alarm A Sub Second register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 hrtc->Instance->ALRMASSR = subsecondtmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 /* Configure the Alarm state: Enable Alarm */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 __HAL_RTC_ALARMA_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 /* Configure the Alarm interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 /* Disable the Alarm B interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 __HAL_RTC_ALARMB_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 /* Clear flag alarm B */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 /* Configure the Alarm B Sub Second register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 /* Configure the Alarm state: Enable Alarm */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 __HAL_RTC_ALARMB_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 /* Configure the Alarm interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 /* RTC Alarm Interrupt Configuration: EXTI configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 __HAL_RTC_ALARM_EXTI_ENABLE_IT();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 * @brief Deactive the specified RTC Alarm
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 * @param Alarm: Specifies the Alarm.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 * @arg RTC_ALARM_A: AlarmA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 * @arg RTC_ALARM_B: AlarmB
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 assert_param(IS_RTC_ALARM(Alarm));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 __HAL_LOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 hrtc->State = HAL_RTC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 /* Disable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 if(Alarm == RTC_ALARM_A)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 /* AlarmA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 __HAL_RTC_ALARMA_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 /* In case of interrupt mode is used, the interrupt source must disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 /* AlarmB */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 __HAL_RTC_ALARMB_DISABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 /* In case of interrupt mode is used, the interrupt source must disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 /* Enable the write protection for RTC registers */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 __HAL_UNLOCK(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 * @brief Gets the RTC Alarm value and masks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 * @param sAlarm: Pointer to Date structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 * @param Alarm: Specifies the Alarm.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 * @arg RTC_ALARM_A: AlarmA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 * @arg RTC_ALARM_B: AlarmB
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 * @param Format: Specifies the format of the entered parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 * @arg RTC_FORMAT_BIN: Binary data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 * @arg RTC_FORMAT_BCD: BCD data format
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 uint32_t tmpreg = 0, subsecondtmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 assert_param(IS_RTC_FORMAT(Format));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 assert_param(IS_RTC_ALARM(Alarm));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 if(Alarm == RTC_ALARM_A)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 /* AlarmA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 sAlarm->Alarm = RTC_ALARM_A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 tmpreg = (uint32_t)(hrtc->Instance->ALRMAR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR ) & RTC_ALRMASSR_SS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 sAlarm->Alarm = RTC_ALARM_B;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 tmpreg = (uint32_t)(hrtc->Instance->ALRMBR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 /* Fill the structure with the read parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 if(Format == RTC_FORMAT_BIN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 * @brief This function handles Alarm interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 /* AlarmA callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 HAL_RTC_AlarmAEventCallback(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 /* Clear the Alarm interrupt pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 /* Get the status of the Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 /* AlarmB callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 HAL_RTCEx_AlarmBEventCallback(hrtc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 /* Clear the Alarm interrupt pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 /* Clear the EXTI's line Flag for RTC Alarm */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 * @brief Alarm A callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 the HAL_RTC_AlarmAEventCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 * @brief This function handles AlarmA Polling request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 hrtc->State = HAL_RTC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 /* Clear the Alarm interrupt pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 /* Change RTC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 hrtc->State = HAL_RTC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 * @brief Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 This subsection provides functions allowing to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382 (+) Wait for RTC Time and Date Synchronization
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 * synchronized with RTC APB clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 * @note The RTC Resynchronization mode is write protected, use the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 * @note To read the calendar through the shadow registers after Calendar
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 * initialization, calendar update or after wake-up from low power modes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 * the software must first clear the RSF flag.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 * The software must then wait until it is set again before reading
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 * the calendar, which means that the calendar registers have been
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398 * correctly copied into the RTC_TR and RTC_DR shadow registers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407 /* Clear RSF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408 hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 /* Wait the registers to be synchronised */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430 * @brief Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 ##### Peripheral State functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437 This subsection provides functions allowing to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 (+) Get RTC state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444 * @brief Returns the RTC state.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 return hrtc->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 * @brief Enters the RTC Initialization mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 * @note The RTC Initialization mode is write protected, use the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 * the configuration information for RTC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 /* Check if the Initialization mode is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473 /* Set the Initialization mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479 /* Wait till RTC is in INIT state and if Time out is reached exit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 * @brief Converts a 2 digit decimal to BCD format.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 * @param Value: Byte to be converted
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 * @retval Converted byte
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 uint8_t RTC_ByteToBcd2(uint8_t Value)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500 uint32_t bcdhigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502 while(Value >= 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 bcdhigh++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 Value -= 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508 return ((uint8_t)(bcdhigh << 4) | Value);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 * @brief Converts from 2 digit BCD to Binary.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 * @param Value: BCD value to be converted
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514 * @retval Converted word
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 uint8_t RTC_Bcd2ToByte(uint8_t Value)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 return (tmp + (Value & (uint8_t)0x0F));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 #endif /* HAL_RTC_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/