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