mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_hal_rtc_ex.c@393:17d2d502961d, 2014-11-07 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Nov 07 12:00:11 2014 +0000
- Revision:
- 393:17d2d502961d
- Parent:
- 354:e67efb2aab0e
Synchronized with git revision 78a3d4f2301aad7367e924e8231b4411d11038ea
Full URL: https://github.com/mbedmicro/mbed/commit/78a3d4f2301aad7367e924e8231b4411d11038ea/
Toolchain: NUCLEO_F0 - Add missing files for IAR exporter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 354:e67efb2aab0e | 1 | /** |
mbed_official | 354:e67efb2aab0e | 2 | ****************************************************************************** |
mbed_official | 354:e67efb2aab0e | 3 | * @file stm32l1xx_hal_rtc_ex.c |
mbed_official | 354:e67efb2aab0e | 4 | * @author MCD Application Team |
mbed_official | 354:e67efb2aab0e | 5 | * @version V1.0.0 |
mbed_official | 354:e67efb2aab0e | 6 | * @date 5-September-2014 |
mbed_official | 354:e67efb2aab0e | 7 | * @brief Extended RTC HAL module driver. |
mbed_official | 354:e67efb2aab0e | 8 | * This file provides firmware functions to manage the following |
mbed_official | 354:e67efb2aab0e | 9 | * functionalities of the Real Time Clock (RTC) Extension peripheral: |
mbed_official | 354:e67efb2aab0e | 10 | * + RTC Time Stamp functions |
mbed_official | 354:e67efb2aab0e | 11 | * + RTC Tamper functions |
mbed_official | 354:e67efb2aab0e | 12 | * + RTC Wake-up functions |
mbed_official | 354:e67efb2aab0e | 13 | * + Extension Control functions |
mbed_official | 354:e67efb2aab0e | 14 | * + Extension RTC features functions |
mbed_official | 354:e67efb2aab0e | 15 | * |
mbed_official | 354:e67efb2aab0e | 16 | @verbatim |
mbed_official | 354:e67efb2aab0e | 17 | ============================================================================== |
mbed_official | 354:e67efb2aab0e | 18 | ##### How to use this driver ##### |
mbed_official | 354:e67efb2aab0e | 19 | ============================================================================== |
mbed_official | 354:e67efb2aab0e | 20 | [..] |
mbed_official | 354:e67efb2aab0e | 21 | (+) Enable the RTC domain access. |
mbed_official | 354:e67efb2aab0e | 22 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
mbed_official | 354:e67efb2aab0e | 23 | format using the HAL_RTC_Init() function. |
mbed_official | 354:e67efb2aab0e | 24 | |
mbed_official | 354:e67efb2aab0e | 25 | *** RTC Wakeup configuration *** |
mbed_official | 354:e67efb2aab0e | 26 | ================================ |
mbed_official | 354:e67efb2aab0e | 27 | [..] |
mbed_official | 354:e67efb2aab0e | 28 | (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer() |
mbed_official | 354:e67efb2aab0e | 29 | function. You can also configure the RTC Wakeup timer with interrupt mode |
mbed_official | 354:e67efb2aab0e | 30 | using the HAL_RTCEx_SetWakeUpTimer_IT() function. |
mbed_official | 354:e67efb2aab0e | 31 | (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer() |
mbed_official | 354:e67efb2aab0e | 32 | function. |
mbed_official | 354:e67efb2aab0e | 33 | |
mbed_official | 354:e67efb2aab0e | 34 | *** TimeStamp configuration *** |
mbed_official | 354:e67efb2aab0e | 35 | =============================== |
mbed_official | 354:e67efb2aab0e | 36 | [..] |
mbed_official | 354:e67efb2aab0e | 37 | (+) Configure the RTC_AFx trigger and enable the RTC TimeStamp using the |
mbed_official | 354:e67efb2aab0e | 38 | HAL_RTCEx_SetTimeStamp() function. You can also configure the RTC TimeStamp with |
mbed_official | 354:e67efb2aab0e | 39 | interrupt mode using the HAL_RTCEx_SetTimeStamp_IT() function. |
mbed_official | 354:e67efb2aab0e | 40 | (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() |
mbed_official | 354:e67efb2aab0e | 41 | function. |
mbed_official | 354:e67efb2aab0e | 42 | (+) The TIMESTAMP alternate function can be mapped to RTC_AF1 (PC13). |
mbed_official | 354:e67efb2aab0e | 43 | |
mbed_official | 354:e67efb2aab0e | 44 | *** Tamper configuration *** |
mbed_official | 354:e67efb2aab0e | 45 | ============================ |
mbed_official | 354:e67efb2aab0e | 46 | [..] |
mbed_official | 354:e67efb2aab0e | 47 | (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge |
mbed_official | 354:e67efb2aab0e | 48 | or Level according to the Tamper filter (if equal to 0 Edge else Level) |
mbed_official | 354:e67efb2aab0e | 49 | value, sampling frequency, precharge or discharge and Pull-UP using the |
mbed_official | 354:e67efb2aab0e | 50 | HAL_RTCEx_SetTamper() function. You can configure RTC Tamper with interrupt |
mbed_official | 354:e67efb2aab0e | 51 | mode using HAL_RTCEx_SetTamper_IT() function. |
mbed_official | 354:e67efb2aab0e | 52 | (+) The TAMPER1 alternate function can be mapped to RTC_AF1 (PC13). |
mbed_official | 354:e67efb2aab0e | 53 | |
mbed_official | 354:e67efb2aab0e | 54 | *** Backup Data Registers configuration *** |
mbed_official | 354:e67efb2aab0e | 55 | =========================================== |
mbed_official | 354:e67efb2aab0e | 56 | [..] |
mbed_official | 354:e67efb2aab0e | 57 | (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite() |
mbed_official | 354:e67efb2aab0e | 58 | function. |
mbed_official | 354:e67efb2aab0e | 59 | (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead() |
mbed_official | 354:e67efb2aab0e | 60 | function. |
mbed_official | 354:e67efb2aab0e | 61 | |
mbed_official | 354:e67efb2aab0e | 62 | @endverbatim |
mbed_official | 354:e67efb2aab0e | 63 | ****************************************************************************** |
mbed_official | 354:e67efb2aab0e | 64 | * @attention |
mbed_official | 354:e67efb2aab0e | 65 | * |
mbed_official | 354:e67efb2aab0e | 66 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 354:e67efb2aab0e | 67 | * |
mbed_official | 354:e67efb2aab0e | 68 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 354:e67efb2aab0e | 69 | * are permitted provided that the following conditions are met: |
mbed_official | 354:e67efb2aab0e | 70 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 354:e67efb2aab0e | 71 | * this list of conditions and the following disclaimer. |
mbed_official | 354:e67efb2aab0e | 72 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 354:e67efb2aab0e | 73 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 354:e67efb2aab0e | 74 | * and/or other materials provided with the distribution. |
mbed_official | 354:e67efb2aab0e | 75 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 354:e67efb2aab0e | 76 | * may be used to endorse or promote products derived from this software |
mbed_official | 354:e67efb2aab0e | 77 | * without specific prior written permission. |
mbed_official | 354:e67efb2aab0e | 78 | * |
mbed_official | 354:e67efb2aab0e | 79 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 354:e67efb2aab0e | 80 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 354:e67efb2aab0e | 81 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 354:e67efb2aab0e | 82 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 354:e67efb2aab0e | 83 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 354:e67efb2aab0e | 84 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 354:e67efb2aab0e | 85 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 354:e67efb2aab0e | 86 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 354:e67efb2aab0e | 87 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 354:e67efb2aab0e | 88 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 354:e67efb2aab0e | 89 | * |
mbed_official | 354:e67efb2aab0e | 90 | ****************************************************************************** |
mbed_official | 354:e67efb2aab0e | 91 | */ |
mbed_official | 354:e67efb2aab0e | 92 | |
mbed_official | 354:e67efb2aab0e | 93 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 354:e67efb2aab0e | 94 | #include "stm32l1xx_hal.h" |
mbed_official | 354:e67efb2aab0e | 95 | |
mbed_official | 354:e67efb2aab0e | 96 | /** @addtogroup STM32L1xx_HAL_Driver |
mbed_official | 354:e67efb2aab0e | 97 | * @{ |
mbed_official | 354:e67efb2aab0e | 98 | */ |
mbed_official | 354:e67efb2aab0e | 99 | |
mbed_official | 354:e67efb2aab0e | 100 | /** @addtogroup RTC |
mbed_official | 354:e67efb2aab0e | 101 | * @{ |
mbed_official | 354:e67efb2aab0e | 102 | */ |
mbed_official | 354:e67efb2aab0e | 103 | |
mbed_official | 354:e67efb2aab0e | 104 | #ifdef HAL_RTC_MODULE_ENABLED |
mbed_official | 354:e67efb2aab0e | 105 | |
mbed_official | 354:e67efb2aab0e | 106 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 354:e67efb2aab0e | 107 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 354:e67efb2aab0e | 108 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 354:e67efb2aab0e | 109 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 354:e67efb2aab0e | 110 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 354:e67efb2aab0e | 111 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 354:e67efb2aab0e | 112 | |
mbed_official | 354:e67efb2aab0e | 113 | /** @addtogroup RTC_Exported_Functions |
mbed_official | 354:e67efb2aab0e | 114 | * @{ |
mbed_official | 354:e67efb2aab0e | 115 | */ |
mbed_official | 354:e67efb2aab0e | 116 | |
mbed_official | 354:e67efb2aab0e | 117 | |
mbed_official | 354:e67efb2aab0e | 118 | /** @addtogroup RTC_Exported_Functions_Group1 |
mbed_official | 354:e67efb2aab0e | 119 | * @{ |
mbed_official | 354:e67efb2aab0e | 120 | */ |
mbed_official | 354:e67efb2aab0e | 121 | |
mbed_official | 354:e67efb2aab0e | 122 | /** |
mbed_official | 354:e67efb2aab0e | 123 | * @brief DeInitializes the RTC peripheral |
mbed_official | 354:e67efb2aab0e | 124 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 125 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 126 | * @note This function does not reset the RTC Backup Data registers. |
mbed_official | 354:e67efb2aab0e | 127 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 128 | */ |
mbed_official | 354:e67efb2aab0e | 129 | HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 130 | { |
mbed_official | 354:e67efb2aab0e | 131 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 132 | |
mbed_official | 354:e67efb2aab0e | 133 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 134 | assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance)); |
mbed_official | 354:e67efb2aab0e | 135 | |
mbed_official | 354:e67efb2aab0e | 136 | /* Set RTC state */ |
mbed_official | 354:e67efb2aab0e | 137 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 138 | |
mbed_official | 354:e67efb2aab0e | 139 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 140 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 141 | |
mbed_official | 354:e67efb2aab0e | 142 | /* Set Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 143 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 354:e67efb2aab0e | 144 | { |
mbed_official | 354:e67efb2aab0e | 145 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 146 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 147 | |
mbed_official | 354:e67efb2aab0e | 148 | /* Set RTC state */ |
mbed_official | 354:e67efb2aab0e | 149 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 150 | |
mbed_official | 354:e67efb2aab0e | 151 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 152 | } |
mbed_official | 354:e67efb2aab0e | 153 | else |
mbed_official | 354:e67efb2aab0e | 154 | { |
mbed_official | 354:e67efb2aab0e | 155 | /* Reset TR, DR and CR registers */ |
mbed_official | 354:e67efb2aab0e | 156 | hrtc->Instance->TR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 157 | hrtc->Instance->DR = (uint32_t)0x00002101; |
mbed_official | 354:e67efb2aab0e | 158 | /* Reset All CR bits except CR[2:0] */ |
mbed_official | 354:e67efb2aab0e | 159 | hrtc->Instance->CR &= (uint32_t)0x00000007; |
mbed_official | 354:e67efb2aab0e | 160 | |
mbed_official | 354:e67efb2aab0e | 161 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 162 | |
mbed_official | 354:e67efb2aab0e | 163 | /* Wait till WUTWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 164 | while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 165 | { |
mbed_official | 354:e67efb2aab0e | 166 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 167 | { |
mbed_official | 354:e67efb2aab0e | 168 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 169 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 170 | |
mbed_official | 354:e67efb2aab0e | 171 | /* Set RTC state */ |
mbed_official | 354:e67efb2aab0e | 172 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 173 | |
mbed_official | 354:e67efb2aab0e | 174 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 175 | } |
mbed_official | 354:e67efb2aab0e | 176 | } |
mbed_official | 354:e67efb2aab0e | 177 | |
mbed_official | 354:e67efb2aab0e | 178 | /* Reset all RTC CR register bits */ |
mbed_official | 354:e67efb2aab0e | 179 | hrtc->Instance->CR &= (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 180 | hrtc->Instance->WUTR = (uint32_t)0x0000FFFF; |
mbed_official | 354:e67efb2aab0e | 181 | hrtc->Instance->PRER = (uint32_t)0x007F00FF; |
mbed_official | 354:e67efb2aab0e | 182 | hrtc->Instance->CALIBR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 183 | hrtc->Instance->ALRMAR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 184 | hrtc->Instance->ALRMBR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 185 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 186 | hrtc->Instance->SHIFTR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 187 | hrtc->Instance->CALR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 188 | hrtc->Instance->ALRMASSR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 189 | hrtc->Instance->ALRMBSSR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 190 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 191 | /* Reset ISR register and exit initialization mode */ |
mbed_official | 354:e67efb2aab0e | 192 | hrtc->Instance->ISR = (uint32_t)0x00000000; |
mbed_official | 354:e67efb2aab0e | 193 | |
mbed_official | 354:e67efb2aab0e | 194 | /* Reset Tamper and alternate functions configuration register */ |
mbed_official | 354:e67efb2aab0e | 195 | hrtc->Instance->TAFCR = 0x00000000; |
mbed_official | 354:e67efb2aab0e | 196 | |
mbed_official | 354:e67efb2aab0e | 197 | /* Wait for synchro */ |
mbed_official | 354:e67efb2aab0e | 198 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
mbed_official | 354:e67efb2aab0e | 199 | { |
mbed_official | 354:e67efb2aab0e | 200 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 201 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 202 | |
mbed_official | 354:e67efb2aab0e | 203 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 204 | |
mbed_official | 354:e67efb2aab0e | 205 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 206 | } |
mbed_official | 354:e67efb2aab0e | 207 | } |
mbed_official | 354:e67efb2aab0e | 208 | |
mbed_official | 354:e67efb2aab0e | 209 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 210 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 211 | |
mbed_official | 354:e67efb2aab0e | 212 | /* De-Initialize RTC MSP */ |
mbed_official | 354:e67efb2aab0e | 213 | HAL_RTC_MspDeInit(hrtc); |
mbed_official | 354:e67efb2aab0e | 214 | |
mbed_official | 354:e67efb2aab0e | 215 | hrtc->State = HAL_RTC_STATE_RESET; |
mbed_official | 354:e67efb2aab0e | 216 | |
mbed_official | 354:e67efb2aab0e | 217 | /* Release Lock */ |
mbed_official | 354:e67efb2aab0e | 218 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 219 | |
mbed_official | 354:e67efb2aab0e | 220 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 221 | } |
mbed_official | 354:e67efb2aab0e | 222 | |
mbed_official | 354:e67efb2aab0e | 223 | /** |
mbed_official | 354:e67efb2aab0e | 224 | * @} |
mbed_official | 354:e67efb2aab0e | 225 | */ |
mbed_official | 354:e67efb2aab0e | 226 | |
mbed_official | 354:e67efb2aab0e | 227 | /** @addtogroup RTC_Exported_Functions_Group2 |
mbed_official | 354:e67efb2aab0e | 228 | * @{ |
mbed_official | 354:e67efb2aab0e | 229 | */ |
mbed_official | 354:e67efb2aab0e | 230 | |
mbed_official | 354:e67efb2aab0e | 231 | /** |
mbed_official | 354:e67efb2aab0e | 232 | * @brief Gets RTC current time. |
mbed_official | 354:e67efb2aab0e | 233 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 234 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 235 | * @param sTime: Pointer to Time structure |
mbed_official | 354:e67efb2aab0e | 236 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 354:e67efb2aab0e | 237 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 238 | * @arg FORMAT_BIN: Binary data format |
mbed_official | 354:e67efb2aab0e | 239 | * @arg FORMAT_BCD: BCD data format |
mbed_official | 354:e67efb2aab0e | 240 | * @note Call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
mbed_official | 354:e67efb2aab0e | 241 | * in the higher-order calendar shadow registers. |
mbed_official | 354:e67efb2aab0e | 242 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 243 | */ |
mbed_official | 354:e67efb2aab0e | 244 | HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
mbed_official | 354:e67efb2aab0e | 245 | { |
mbed_official | 354:e67efb2aab0e | 246 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 247 | |
mbed_official | 354:e67efb2aab0e | 248 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 249 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 354:e67efb2aab0e | 250 | |
mbed_official | 354:e67efb2aab0e | 251 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 252 | /* Get subseconds values from the correspondent registers*/ |
mbed_official | 354:e67efb2aab0e | 253 | sTime->SubSeconds = (uint32_t)((hrtc->Instance->SSR) & RTC_SSR_SS); |
mbed_official | 354:e67efb2aab0e | 254 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 255 | |
mbed_official | 354:e67efb2aab0e | 256 | /* Get the TR register */ |
mbed_official | 354:e67efb2aab0e | 257 | tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK); |
mbed_official | 354:e67efb2aab0e | 258 | |
mbed_official | 354:e67efb2aab0e | 259 | /* Fill the structure fields with the read parameters */ |
mbed_official | 354:e67efb2aab0e | 260 | sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16); |
mbed_official | 354:e67efb2aab0e | 261 | sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8); |
mbed_official | 354:e67efb2aab0e | 262 | sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); |
mbed_official | 354:e67efb2aab0e | 263 | sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16); |
mbed_official | 354:e67efb2aab0e | 264 | |
mbed_official | 354:e67efb2aab0e | 265 | /* Check the input parameters format */ |
mbed_official | 354:e67efb2aab0e | 266 | if(Format == FORMAT_BIN) |
mbed_official | 354:e67efb2aab0e | 267 | { |
mbed_official | 354:e67efb2aab0e | 268 | /* Convert the time structure parameters to Binary format */ |
mbed_official | 354:e67efb2aab0e | 269 | sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); |
mbed_official | 354:e67efb2aab0e | 270 | sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); |
mbed_official | 354:e67efb2aab0e | 271 | sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); |
mbed_official | 354:e67efb2aab0e | 272 | } |
mbed_official | 354:e67efb2aab0e | 273 | |
mbed_official | 354:e67efb2aab0e | 274 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 275 | } |
mbed_official | 354:e67efb2aab0e | 276 | |
mbed_official | 354:e67efb2aab0e | 277 | /** |
mbed_official | 354:e67efb2aab0e | 278 | * @} |
mbed_official | 354:e67efb2aab0e | 279 | */ |
mbed_official | 354:e67efb2aab0e | 280 | |
mbed_official | 354:e67efb2aab0e | 281 | /** @addtogroup RTC_Exported_Functions_Group3 |
mbed_official | 354:e67efb2aab0e | 282 | * @{ |
mbed_official | 354:e67efb2aab0e | 283 | */ |
mbed_official | 354:e67efb2aab0e | 284 | |
mbed_official | 354:e67efb2aab0e | 285 | /** |
mbed_official | 354:e67efb2aab0e | 286 | * @brief Sets the specified RTC Alarm. |
mbed_official | 354:e67efb2aab0e | 287 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 288 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 289 | * @param sAlarm: Pointer to Alarm structure |
mbed_official | 354:e67efb2aab0e | 290 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 354:e67efb2aab0e | 291 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 292 | * @arg FORMAT_BIN: Binary data format |
mbed_official | 354:e67efb2aab0e | 293 | * @arg FORMAT_BCD: BCD data format |
mbed_official | 354:e67efb2aab0e | 294 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 295 | */ |
mbed_official | 354:e67efb2aab0e | 296 | HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
mbed_official | 354:e67efb2aab0e | 297 | { |
mbed_official | 354:e67efb2aab0e | 298 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 299 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 300 | |
mbed_official | 354:e67efb2aab0e | 301 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 302 | uint32_t subsecondtmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 303 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 304 | |
mbed_official | 354:e67efb2aab0e | 305 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 306 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 354:e67efb2aab0e | 307 | assert_param(IS_ALARM(sAlarm->Alarm)); |
mbed_official | 354:e67efb2aab0e | 308 | assert_param(IS_ALARM_MASK(sAlarm->AlarmMask)); |
mbed_official | 354:e67efb2aab0e | 309 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
mbed_official | 354:e67efb2aab0e | 310 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 311 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
mbed_official | 354:e67efb2aab0e | 312 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
mbed_official | 354:e67efb2aab0e | 313 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 314 | |
mbed_official | 354:e67efb2aab0e | 315 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 316 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 317 | |
mbed_official | 354:e67efb2aab0e | 318 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 319 | |
mbed_official | 354:e67efb2aab0e | 320 | if(Format == FORMAT_BIN) |
mbed_official | 354:e67efb2aab0e | 321 | { |
mbed_official | 354:e67efb2aab0e | 322 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 323 | { |
mbed_official | 354:e67efb2aab0e | 324 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
mbed_official | 354:e67efb2aab0e | 325 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 354:e67efb2aab0e | 326 | } |
mbed_official | 354:e67efb2aab0e | 327 | else |
mbed_official | 354:e67efb2aab0e | 328 | { |
mbed_official | 354:e67efb2aab0e | 329 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 354:e67efb2aab0e | 330 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
mbed_official | 354:e67efb2aab0e | 331 | } |
mbed_official | 354:e67efb2aab0e | 332 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
mbed_official | 354:e67efb2aab0e | 333 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
mbed_official | 354:e67efb2aab0e | 334 | |
mbed_official | 354:e67efb2aab0e | 335 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 354:e67efb2aab0e | 336 | { |
mbed_official | 354:e67efb2aab0e | 337 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
mbed_official | 354:e67efb2aab0e | 338 | } |
mbed_official | 354:e67efb2aab0e | 339 | else |
mbed_official | 354:e67efb2aab0e | 340 | { |
mbed_official | 354:e67efb2aab0e | 341 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
mbed_official | 354:e67efb2aab0e | 342 | } |
mbed_official | 354:e67efb2aab0e | 343 | |
mbed_official | 354:e67efb2aab0e | 344 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 345 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 354:e67efb2aab0e | 346 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
mbed_official | 354:e67efb2aab0e | 347 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 348 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 354:e67efb2aab0e | 349 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 354:e67efb2aab0e | 350 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 354:e67efb2aab0e | 351 | } |
mbed_official | 354:e67efb2aab0e | 352 | else |
mbed_official | 354:e67efb2aab0e | 353 | { |
mbed_official | 354:e67efb2aab0e | 354 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 355 | { |
mbed_official | 354:e67efb2aab0e | 356 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
mbed_official | 354:e67efb2aab0e | 357 | assert_param(IS_RTC_HOUR12(tmpreg)); |
mbed_official | 354:e67efb2aab0e | 358 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 354:e67efb2aab0e | 359 | } |
mbed_official | 354:e67efb2aab0e | 360 | else |
mbed_official | 354:e67efb2aab0e | 361 | { |
mbed_official | 354:e67efb2aab0e | 362 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 354:e67efb2aab0e | 363 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
mbed_official | 354:e67efb2aab0e | 364 | } |
mbed_official | 354:e67efb2aab0e | 365 | |
mbed_official | 354:e67efb2aab0e | 366 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
mbed_official | 354:e67efb2aab0e | 367 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
mbed_official | 354:e67efb2aab0e | 368 | |
mbed_official | 354:e67efb2aab0e | 369 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 354:e67efb2aab0e | 370 | { |
mbed_official | 354:e67efb2aab0e | 371 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 354:e67efb2aab0e | 372 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
mbed_official | 354:e67efb2aab0e | 373 | } |
mbed_official | 354:e67efb2aab0e | 374 | else |
mbed_official | 354:e67efb2aab0e | 375 | { |
mbed_official | 354:e67efb2aab0e | 376 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 354:e67efb2aab0e | 377 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
mbed_official | 354:e67efb2aab0e | 378 | } |
mbed_official | 354:e67efb2aab0e | 379 | |
mbed_official | 354:e67efb2aab0e | 380 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 381 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 354:e67efb2aab0e | 382 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
mbed_official | 354:e67efb2aab0e | 383 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 384 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 354:e67efb2aab0e | 385 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 354:e67efb2aab0e | 386 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 354:e67efb2aab0e | 387 | } |
mbed_official | 354:e67efb2aab0e | 388 | |
mbed_official | 354:e67efb2aab0e | 389 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 390 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
mbed_official | 354:e67efb2aab0e | 391 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
mbed_official | 354:e67efb2aab0e | 392 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 393 | |
mbed_official | 354:e67efb2aab0e | 394 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 395 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 396 | |
mbed_official | 354:e67efb2aab0e | 397 | /* Configure the Alarm register */ |
mbed_official | 354:e67efb2aab0e | 398 | if(sAlarm->Alarm == RTC_ALARM_A) |
mbed_official | 354:e67efb2aab0e | 399 | { |
mbed_official | 354:e67efb2aab0e | 400 | /* Disable the Alarm A interrupt */ |
mbed_official | 354:e67efb2aab0e | 401 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 402 | |
mbed_official | 354:e67efb2aab0e | 403 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 354:e67efb2aab0e | 404 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
mbed_official | 354:e67efb2aab0e | 405 | |
mbed_official | 354:e67efb2aab0e | 406 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 407 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 408 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
mbed_official | 354:e67efb2aab0e | 409 | { |
mbed_official | 354:e67efb2aab0e | 410 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 411 | { |
mbed_official | 354:e67efb2aab0e | 412 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 413 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 414 | |
mbed_official | 354:e67efb2aab0e | 415 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 416 | |
mbed_official | 354:e67efb2aab0e | 417 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 418 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 419 | |
mbed_official | 354:e67efb2aab0e | 420 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 421 | } |
mbed_official | 354:e67efb2aab0e | 422 | } |
mbed_official | 354:e67efb2aab0e | 423 | |
mbed_official | 354:e67efb2aab0e | 424 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
mbed_official | 354:e67efb2aab0e | 425 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 426 | /* Configure the Alarm A Sub Second register */ |
mbed_official | 354:e67efb2aab0e | 427 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
mbed_official | 354:e67efb2aab0e | 428 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 429 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 354:e67efb2aab0e | 430 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 431 | } |
mbed_official | 354:e67efb2aab0e | 432 | else |
mbed_official | 354:e67efb2aab0e | 433 | { |
mbed_official | 354:e67efb2aab0e | 434 | /* Disable the Alarm B interrupt */ |
mbed_official | 354:e67efb2aab0e | 435 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 436 | |
mbed_official | 354:e67efb2aab0e | 437 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 354:e67efb2aab0e | 438 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
mbed_official | 354:e67efb2aab0e | 439 | |
mbed_official | 354:e67efb2aab0e | 440 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 441 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 442 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
mbed_official | 354:e67efb2aab0e | 443 | { |
mbed_official | 354:e67efb2aab0e | 444 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 445 | { |
mbed_official | 354:e67efb2aab0e | 446 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 447 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 448 | |
mbed_official | 354:e67efb2aab0e | 449 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 450 | |
mbed_official | 354:e67efb2aab0e | 451 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 452 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 453 | |
mbed_official | 354:e67efb2aab0e | 454 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 455 | } |
mbed_official | 354:e67efb2aab0e | 456 | } |
mbed_official | 354:e67efb2aab0e | 457 | |
mbed_official | 354:e67efb2aab0e | 458 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
mbed_official | 354:e67efb2aab0e | 459 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 460 | /* Configure the Alarm B Sub Second register */ |
mbed_official | 354:e67efb2aab0e | 461 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
mbed_official | 354:e67efb2aab0e | 462 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 463 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 354:e67efb2aab0e | 464 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 465 | } |
mbed_official | 354:e67efb2aab0e | 466 | |
mbed_official | 354:e67efb2aab0e | 467 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 468 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 469 | |
mbed_official | 354:e67efb2aab0e | 470 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 471 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 472 | |
mbed_official | 354:e67efb2aab0e | 473 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 474 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 475 | |
mbed_official | 354:e67efb2aab0e | 476 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 477 | } |
mbed_official | 354:e67efb2aab0e | 478 | |
mbed_official | 354:e67efb2aab0e | 479 | /** |
mbed_official | 354:e67efb2aab0e | 480 | * @brief Sets the specified RTC Alarm with Interrupt |
mbed_official | 354:e67efb2aab0e | 481 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 482 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 483 | * @param sAlarm: Pointer to Alarm structure |
mbed_official | 354:e67efb2aab0e | 484 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 354:e67efb2aab0e | 485 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 486 | * @arg FORMAT_BIN: Binary data format |
mbed_official | 354:e67efb2aab0e | 487 | * @arg FORMAT_BCD: BCD data format |
mbed_official | 354:e67efb2aab0e | 488 | * @note The Alarm register can only be written when the corresponding Alarm |
mbed_official | 354:e67efb2aab0e | 489 | * is disabled (Use the HAL_RTC_DeactivateAlarm()). |
mbed_official | 354:e67efb2aab0e | 490 | * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature. |
mbed_official | 354:e67efb2aab0e | 491 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 492 | */ |
mbed_official | 354:e67efb2aab0e | 493 | HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
mbed_official | 354:e67efb2aab0e | 494 | { |
mbed_official | 354:e67efb2aab0e | 495 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 496 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 497 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 498 | uint32_t subsecondtmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 499 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 500 | |
mbed_official | 354:e67efb2aab0e | 501 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 502 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 354:e67efb2aab0e | 503 | assert_param(IS_ALARM(sAlarm->Alarm)); |
mbed_official | 354:e67efb2aab0e | 504 | assert_param(IS_ALARM_MASK(sAlarm->AlarmMask)); |
mbed_official | 354:e67efb2aab0e | 505 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
mbed_official | 354:e67efb2aab0e | 506 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 507 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
mbed_official | 354:e67efb2aab0e | 508 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
mbed_official | 354:e67efb2aab0e | 509 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 510 | |
mbed_official | 354:e67efb2aab0e | 511 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 512 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 513 | |
mbed_official | 354:e67efb2aab0e | 514 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 515 | |
mbed_official | 354:e67efb2aab0e | 516 | if(Format == FORMAT_BIN) |
mbed_official | 354:e67efb2aab0e | 517 | { |
mbed_official | 354:e67efb2aab0e | 518 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 519 | { |
mbed_official | 354:e67efb2aab0e | 520 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
mbed_official | 354:e67efb2aab0e | 521 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 354:e67efb2aab0e | 522 | } |
mbed_official | 354:e67efb2aab0e | 523 | else |
mbed_official | 354:e67efb2aab0e | 524 | { |
mbed_official | 354:e67efb2aab0e | 525 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 354:e67efb2aab0e | 526 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
mbed_official | 354:e67efb2aab0e | 527 | } |
mbed_official | 354:e67efb2aab0e | 528 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
mbed_official | 354:e67efb2aab0e | 529 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
mbed_official | 354:e67efb2aab0e | 530 | |
mbed_official | 354:e67efb2aab0e | 531 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 354:e67efb2aab0e | 532 | { |
mbed_official | 354:e67efb2aab0e | 533 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
mbed_official | 354:e67efb2aab0e | 534 | } |
mbed_official | 354:e67efb2aab0e | 535 | else |
mbed_official | 354:e67efb2aab0e | 536 | { |
mbed_official | 354:e67efb2aab0e | 537 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
mbed_official | 354:e67efb2aab0e | 538 | } |
mbed_official | 354:e67efb2aab0e | 539 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 540 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 354:e67efb2aab0e | 541 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
mbed_official | 354:e67efb2aab0e | 542 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 543 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 354:e67efb2aab0e | 544 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 354:e67efb2aab0e | 545 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 354:e67efb2aab0e | 546 | } |
mbed_official | 354:e67efb2aab0e | 547 | else |
mbed_official | 354:e67efb2aab0e | 548 | { |
mbed_official | 354:e67efb2aab0e | 549 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 550 | { |
mbed_official | 354:e67efb2aab0e | 551 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
mbed_official | 354:e67efb2aab0e | 552 | assert_param(IS_RTC_HOUR12(tmpreg)); |
mbed_official | 354:e67efb2aab0e | 553 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 354:e67efb2aab0e | 554 | } |
mbed_official | 354:e67efb2aab0e | 555 | else |
mbed_official | 354:e67efb2aab0e | 556 | { |
mbed_official | 354:e67efb2aab0e | 557 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 354:e67efb2aab0e | 558 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
mbed_official | 354:e67efb2aab0e | 559 | } |
mbed_official | 354:e67efb2aab0e | 560 | |
mbed_official | 354:e67efb2aab0e | 561 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
mbed_official | 354:e67efb2aab0e | 562 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
mbed_official | 354:e67efb2aab0e | 563 | |
mbed_official | 354:e67efb2aab0e | 564 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 354:e67efb2aab0e | 565 | { |
mbed_official | 354:e67efb2aab0e | 566 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 354:e67efb2aab0e | 567 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
mbed_official | 354:e67efb2aab0e | 568 | } |
mbed_official | 354:e67efb2aab0e | 569 | else |
mbed_official | 354:e67efb2aab0e | 570 | { |
mbed_official | 354:e67efb2aab0e | 571 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 354:e67efb2aab0e | 572 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
mbed_official | 354:e67efb2aab0e | 573 | } |
mbed_official | 354:e67efb2aab0e | 574 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 575 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 354:e67efb2aab0e | 576 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
mbed_official | 354:e67efb2aab0e | 577 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 354:e67efb2aab0e | 578 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 354:e67efb2aab0e | 579 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 354:e67efb2aab0e | 580 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 354:e67efb2aab0e | 581 | } |
mbed_official | 354:e67efb2aab0e | 582 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 583 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
mbed_official | 354:e67efb2aab0e | 584 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
mbed_official | 354:e67efb2aab0e | 585 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 586 | |
mbed_official | 354:e67efb2aab0e | 587 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 588 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 589 | |
mbed_official | 354:e67efb2aab0e | 590 | /* Configure the Alarm register */ |
mbed_official | 354:e67efb2aab0e | 591 | if(sAlarm->Alarm == RTC_ALARM_A) |
mbed_official | 354:e67efb2aab0e | 592 | { |
mbed_official | 354:e67efb2aab0e | 593 | /* Disable the Alarm A interrupt */ |
mbed_official | 354:e67efb2aab0e | 594 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 595 | |
mbed_official | 354:e67efb2aab0e | 596 | /* Clear flag alarm A */ |
mbed_official | 354:e67efb2aab0e | 597 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
mbed_official | 354:e67efb2aab0e | 598 | |
mbed_official | 354:e67efb2aab0e | 599 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 600 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 601 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
mbed_official | 354:e67efb2aab0e | 602 | { |
mbed_official | 354:e67efb2aab0e | 603 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 604 | { |
mbed_official | 354:e67efb2aab0e | 605 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 606 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 607 | |
mbed_official | 354:e67efb2aab0e | 608 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 609 | |
mbed_official | 354:e67efb2aab0e | 610 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 611 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 612 | |
mbed_official | 354:e67efb2aab0e | 613 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 614 | } |
mbed_official | 354:e67efb2aab0e | 615 | } |
mbed_official | 354:e67efb2aab0e | 616 | |
mbed_official | 354:e67efb2aab0e | 617 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
mbed_official | 354:e67efb2aab0e | 618 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 619 | /* Configure the Alarm A Sub Second register */ |
mbed_official | 354:e67efb2aab0e | 620 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
mbed_official | 354:e67efb2aab0e | 621 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 622 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 354:e67efb2aab0e | 623 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 624 | /* Configure the Alarm interrupt */ |
mbed_official | 354:e67efb2aab0e | 625 | __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA); |
mbed_official | 354:e67efb2aab0e | 626 | } |
mbed_official | 354:e67efb2aab0e | 627 | else |
mbed_official | 354:e67efb2aab0e | 628 | { |
mbed_official | 354:e67efb2aab0e | 629 | /* Disable the Alarm B interrupt */ |
mbed_official | 354:e67efb2aab0e | 630 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 631 | |
mbed_official | 354:e67efb2aab0e | 632 | /* Clear flag alarm B */ |
mbed_official | 354:e67efb2aab0e | 633 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
mbed_official | 354:e67efb2aab0e | 634 | |
mbed_official | 354:e67efb2aab0e | 635 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 636 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 637 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
mbed_official | 354:e67efb2aab0e | 638 | { |
mbed_official | 354:e67efb2aab0e | 639 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 640 | { |
mbed_official | 354:e67efb2aab0e | 641 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 642 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 643 | |
mbed_official | 354:e67efb2aab0e | 644 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 645 | |
mbed_official | 354:e67efb2aab0e | 646 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 647 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 648 | |
mbed_official | 354:e67efb2aab0e | 649 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 650 | } |
mbed_official | 354:e67efb2aab0e | 651 | } |
mbed_official | 354:e67efb2aab0e | 652 | |
mbed_official | 354:e67efb2aab0e | 653 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
mbed_official | 354:e67efb2aab0e | 654 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 655 | /* Configure the Alarm B Sub Second register */ |
mbed_official | 354:e67efb2aab0e | 656 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
mbed_official | 354:e67efb2aab0e | 657 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 658 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 354:e67efb2aab0e | 659 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 660 | /* Configure the Alarm interrupt */ |
mbed_official | 354:e67efb2aab0e | 661 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB); |
mbed_official | 354:e67efb2aab0e | 662 | } |
mbed_official | 354:e67efb2aab0e | 663 | |
mbed_official | 354:e67efb2aab0e | 664 | /* RTC Alarm Interrupt Configuration: EXTI configuration */ |
mbed_official | 354:e67efb2aab0e | 665 | __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_ALARM_EVENT); |
mbed_official | 354:e67efb2aab0e | 666 | |
mbed_official | 354:e67efb2aab0e | 667 | EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT; |
mbed_official | 354:e67efb2aab0e | 668 | |
mbed_official | 354:e67efb2aab0e | 669 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 670 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 671 | |
mbed_official | 354:e67efb2aab0e | 672 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 673 | |
mbed_official | 354:e67efb2aab0e | 674 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 675 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 676 | |
mbed_official | 354:e67efb2aab0e | 677 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 678 | } |
mbed_official | 354:e67efb2aab0e | 679 | |
mbed_official | 354:e67efb2aab0e | 680 | /** |
mbed_official | 354:e67efb2aab0e | 681 | * @brief Gets the RTC Alarm value and masks. |
mbed_official | 354:e67efb2aab0e | 682 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 683 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 684 | * @param sAlarm: Pointer to Date structure |
mbed_official | 354:e67efb2aab0e | 685 | * @param Alarm: Specifies the Alarm. |
mbed_official | 354:e67efb2aab0e | 686 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 687 | * @arg RTC_ALARM_A: AlarmA |
mbed_official | 354:e67efb2aab0e | 688 | * @arg RTC_ALARM_B: AlarmB |
mbed_official | 354:e67efb2aab0e | 689 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 354:e67efb2aab0e | 690 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 691 | * @arg FORMAT_BIN: Binary data format |
mbed_official | 354:e67efb2aab0e | 692 | * @arg FORMAT_BCD: BCD data format |
mbed_official | 354:e67efb2aab0e | 693 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 694 | */ |
mbed_official | 354:e67efb2aab0e | 695 | HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format) |
mbed_official | 354:e67efb2aab0e | 696 | { |
mbed_official | 354:e67efb2aab0e | 697 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 698 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 699 | uint32_t subsecondtmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 700 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 701 | |
mbed_official | 354:e67efb2aab0e | 702 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 703 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 354:e67efb2aab0e | 704 | assert_param(IS_ALARM(Alarm)); |
mbed_official | 354:e67efb2aab0e | 705 | |
mbed_official | 354:e67efb2aab0e | 706 | if(Alarm == RTC_ALARM_A) |
mbed_official | 354:e67efb2aab0e | 707 | { |
mbed_official | 354:e67efb2aab0e | 708 | /* AlarmA */ |
mbed_official | 354:e67efb2aab0e | 709 | sAlarm->Alarm = RTC_ALARM_A; |
mbed_official | 354:e67efb2aab0e | 710 | |
mbed_official | 354:e67efb2aab0e | 711 | tmpreg = (uint32_t)(hrtc->Instance->ALRMAR); |
mbed_official | 354:e67efb2aab0e | 712 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 713 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR) & RTC_ALRMASSR_SS); |
mbed_official | 354:e67efb2aab0e | 714 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 715 | } |
mbed_official | 354:e67efb2aab0e | 716 | else |
mbed_official | 354:e67efb2aab0e | 717 | { |
mbed_official | 354:e67efb2aab0e | 718 | sAlarm->Alarm = RTC_ALARM_B; |
mbed_official | 354:e67efb2aab0e | 719 | |
mbed_official | 354:e67efb2aab0e | 720 | tmpreg = (uint32_t)(hrtc->Instance->ALRMBR); |
mbed_official | 354:e67efb2aab0e | 721 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 722 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS); |
mbed_official | 354:e67efb2aab0e | 723 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 724 | } |
mbed_official | 354:e67efb2aab0e | 725 | |
mbed_official | 354:e67efb2aab0e | 726 | /* Fill the structure with the read parameters */ |
mbed_official | 354:e67efb2aab0e | 727 | sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16); |
mbed_official | 354:e67efb2aab0e | 728 | sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8); |
mbed_official | 354:e67efb2aab0e | 729 | sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)); |
mbed_official | 354:e67efb2aab0e | 730 | sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16); |
mbed_official | 354:e67efb2aab0e | 731 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 732 | sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg; |
mbed_official | 354:e67efb2aab0e | 733 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 734 | sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24); |
mbed_official | 354:e67efb2aab0e | 735 | sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL); |
mbed_official | 354:e67efb2aab0e | 736 | sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL); |
mbed_official | 354:e67efb2aab0e | 737 | |
mbed_official | 354:e67efb2aab0e | 738 | if(Format == FORMAT_BIN) |
mbed_official | 354:e67efb2aab0e | 739 | { |
mbed_official | 354:e67efb2aab0e | 740 | sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
mbed_official | 354:e67efb2aab0e | 741 | sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes); |
mbed_official | 354:e67efb2aab0e | 742 | sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds); |
mbed_official | 354:e67efb2aab0e | 743 | sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 354:e67efb2aab0e | 744 | } |
mbed_official | 354:e67efb2aab0e | 745 | |
mbed_official | 354:e67efb2aab0e | 746 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 747 | } |
mbed_official | 354:e67efb2aab0e | 748 | |
mbed_official | 354:e67efb2aab0e | 749 | /** |
mbed_official | 354:e67efb2aab0e | 750 | * @} |
mbed_official | 354:e67efb2aab0e | 751 | */ |
mbed_official | 354:e67efb2aab0e | 752 | |
mbed_official | 354:e67efb2aab0e | 753 | |
mbed_official | 354:e67efb2aab0e | 754 | /** @defgroup RTC_Exported_Functions_Group6 Peripheral Control functions |
mbed_official | 354:e67efb2aab0e | 755 | * @brief Peripheral Control functions |
mbed_official | 354:e67efb2aab0e | 756 | * |
mbed_official | 354:e67efb2aab0e | 757 | @verbatim |
mbed_official | 354:e67efb2aab0e | 758 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 759 | ##### Peripheral Control functions ##### |
mbed_official | 354:e67efb2aab0e | 760 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 761 | [..] |
mbed_official | 354:e67efb2aab0e | 762 | This subsection provides functions allowing to |
mbed_official | 354:e67efb2aab0e | 763 | (+) Wait for RTC Time and Date Synchronization |
mbed_official | 354:e67efb2aab0e | 764 | |
mbed_official | 354:e67efb2aab0e | 765 | @endverbatim |
mbed_official | 354:e67efb2aab0e | 766 | * @{ |
mbed_official | 354:e67efb2aab0e | 767 | */ |
mbed_official | 354:e67efb2aab0e | 768 | |
mbed_official | 354:e67efb2aab0e | 769 | /** |
mbed_official | 354:e67efb2aab0e | 770 | * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are |
mbed_official | 354:e67efb2aab0e | 771 | * synchronized with RTC APB clock. |
mbed_official | 354:e67efb2aab0e | 772 | * @note The RTC Resynchronization mode is write protected, use the |
mbed_official | 354:e67efb2aab0e | 773 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
mbed_official | 354:e67efb2aab0e | 774 | * @note To read the calendar through the shadow registers after Calendar |
mbed_official | 354:e67efb2aab0e | 775 | * initialization, calendar update or after wakeup from low power modes |
mbed_official | 354:e67efb2aab0e | 776 | * the software must first clear the RSF flag. |
mbed_official | 354:e67efb2aab0e | 777 | * The software must then wait until it is set again before reading |
mbed_official | 354:e67efb2aab0e | 778 | * the calendar, which means that the calendar registers have been |
mbed_official | 354:e67efb2aab0e | 779 | * correctly copied into the RTC_TR and RTC_DR shadow registers. |
mbed_official | 354:e67efb2aab0e | 780 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 781 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 782 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 783 | */ |
mbed_official | 354:e67efb2aab0e | 784 | HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 785 | { |
mbed_official | 354:e67efb2aab0e | 786 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 787 | |
mbed_official | 354:e67efb2aab0e | 788 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 789 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
mbed_official | 354:e67efb2aab0e | 790 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
mbed_official | 354:e67efb2aab0e | 791 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 792 | { |
mbed_official | 354:e67efb2aab0e | 793 | /* Clear RSF flag */ |
mbed_official | 354:e67efb2aab0e | 794 | hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK; |
mbed_official | 354:e67efb2aab0e | 795 | |
mbed_official | 354:e67efb2aab0e | 796 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 797 | |
mbed_official | 354:e67efb2aab0e | 798 | /* Wait the registers to be synchronised */ |
mbed_official | 354:e67efb2aab0e | 799 | while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 800 | { |
mbed_official | 354:e67efb2aab0e | 801 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 802 | { |
mbed_official | 354:e67efb2aab0e | 803 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 804 | } |
mbed_official | 354:e67efb2aab0e | 805 | } |
mbed_official | 354:e67efb2aab0e | 806 | } |
mbed_official | 354:e67efb2aab0e | 807 | |
mbed_official | 354:e67efb2aab0e | 808 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 809 | } |
mbed_official | 354:e67efb2aab0e | 810 | |
mbed_official | 354:e67efb2aab0e | 811 | /** |
mbed_official | 354:e67efb2aab0e | 812 | * @} |
mbed_official | 354:e67efb2aab0e | 813 | */ |
mbed_official | 354:e67efb2aab0e | 814 | |
mbed_official | 354:e67efb2aab0e | 815 | /** |
mbed_official | 354:e67efb2aab0e | 816 | * @} |
mbed_official | 354:e67efb2aab0e | 817 | */ |
mbed_official | 354:e67efb2aab0e | 818 | |
mbed_official | 354:e67efb2aab0e | 819 | /** |
mbed_official | 354:e67efb2aab0e | 820 | * @} |
mbed_official | 354:e67efb2aab0e | 821 | */ |
mbed_official | 354:e67efb2aab0e | 822 | |
mbed_official | 354:e67efb2aab0e | 823 | /** @defgroup RTCEx RTCEx |
mbed_official | 354:e67efb2aab0e | 824 | * @brief RTC Extended HAL module driver |
mbed_official | 354:e67efb2aab0e | 825 | * @{ |
mbed_official | 354:e67efb2aab0e | 826 | */ |
mbed_official | 354:e67efb2aab0e | 827 | |
mbed_official | 354:e67efb2aab0e | 828 | /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions |
mbed_official | 354:e67efb2aab0e | 829 | * @{ |
mbed_official | 354:e67efb2aab0e | 830 | */ |
mbed_official | 354:e67efb2aab0e | 831 | |
mbed_official | 354:e67efb2aab0e | 832 | /** @defgroup RTCEx_Exported_Functions_Group4 RTC TimeStamp and Tamper functions |
mbed_official | 354:e67efb2aab0e | 833 | * @brief RTC TimeStamp and Tamper functions |
mbed_official | 354:e67efb2aab0e | 834 | * |
mbed_official | 354:e67efb2aab0e | 835 | @verbatim |
mbed_official | 354:e67efb2aab0e | 836 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 837 | ##### RTC TimeStamp and Tamper functions ##### |
mbed_official | 354:e67efb2aab0e | 838 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 839 | |
mbed_official | 354:e67efb2aab0e | 840 | [..] This section provides functions allowing to configure TimeStamp feature |
mbed_official | 354:e67efb2aab0e | 841 | |
mbed_official | 354:e67efb2aab0e | 842 | @endverbatim |
mbed_official | 354:e67efb2aab0e | 843 | * @{ |
mbed_official | 354:e67efb2aab0e | 844 | */ |
mbed_official | 354:e67efb2aab0e | 845 | |
mbed_official | 354:e67efb2aab0e | 846 | /** |
mbed_official | 354:e67efb2aab0e | 847 | * @brief Sets TimeStamp. |
mbed_official | 354:e67efb2aab0e | 848 | * @note This API must be called before enabling the TimeStamp feature. |
mbed_official | 354:e67efb2aab0e | 849 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 850 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 851 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
mbed_official | 354:e67efb2aab0e | 852 | * activated. |
mbed_official | 354:e67efb2aab0e | 853 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 854 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
mbed_official | 354:e67efb2aab0e | 855 | * rising edge of the related pin. |
mbed_official | 354:e67efb2aab0e | 856 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
mbed_official | 354:e67efb2aab0e | 857 | * falling edge of the related pin. |
mbed_official | 354:e67efb2aab0e | 858 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 859 | */ |
mbed_official | 354:e67efb2aab0e | 860 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge) |
mbed_official | 354:e67efb2aab0e | 861 | { |
mbed_official | 354:e67efb2aab0e | 862 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 863 | |
mbed_official | 354:e67efb2aab0e | 864 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 865 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
mbed_official | 354:e67efb2aab0e | 866 | |
mbed_official | 354:e67efb2aab0e | 867 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 868 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 869 | |
mbed_official | 354:e67efb2aab0e | 870 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 871 | |
mbed_official | 354:e67efb2aab0e | 872 | /* Get the RTC_CR register and clear the bits to be configured */ |
mbed_official | 354:e67efb2aab0e | 873 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
mbed_official | 354:e67efb2aab0e | 874 | |
mbed_official | 354:e67efb2aab0e | 875 | tmpreg|= TimeStampEdge; |
mbed_official | 354:e67efb2aab0e | 876 | |
mbed_official | 354:e67efb2aab0e | 877 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 878 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 879 | |
mbed_official | 354:e67efb2aab0e | 880 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
mbed_official | 354:e67efb2aab0e | 881 | hrtc->Instance->CR = (uint32_t)tmpreg; |
mbed_official | 354:e67efb2aab0e | 882 | |
mbed_official | 354:e67efb2aab0e | 883 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 884 | |
mbed_official | 354:e67efb2aab0e | 885 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 886 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 887 | |
mbed_official | 354:e67efb2aab0e | 888 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 889 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 890 | |
mbed_official | 354:e67efb2aab0e | 891 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 892 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 893 | |
mbed_official | 354:e67efb2aab0e | 894 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 895 | } |
mbed_official | 354:e67efb2aab0e | 896 | |
mbed_official | 354:e67efb2aab0e | 897 | /** |
mbed_official | 354:e67efb2aab0e | 898 | * @brief Sets TimeStamp with Interrupt. |
mbed_official | 354:e67efb2aab0e | 899 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 900 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 901 | * @note This API must be called before enabling the TimeStamp feature. |
mbed_official | 354:e67efb2aab0e | 902 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
mbed_official | 354:e67efb2aab0e | 903 | * activated. |
mbed_official | 354:e67efb2aab0e | 904 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 905 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
mbed_official | 354:e67efb2aab0e | 906 | * rising edge of the related pin. |
mbed_official | 354:e67efb2aab0e | 907 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
mbed_official | 354:e67efb2aab0e | 908 | * falling edge of the related pin. |
mbed_official | 354:e67efb2aab0e | 909 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 910 | */ |
mbed_official | 354:e67efb2aab0e | 911 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge) |
mbed_official | 354:e67efb2aab0e | 912 | { |
mbed_official | 354:e67efb2aab0e | 913 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 914 | |
mbed_official | 354:e67efb2aab0e | 915 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 916 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
mbed_official | 354:e67efb2aab0e | 917 | |
mbed_official | 354:e67efb2aab0e | 918 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 919 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 920 | |
mbed_official | 354:e67efb2aab0e | 921 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 922 | |
mbed_official | 354:e67efb2aab0e | 923 | /* Get the RTC_CR register and clear the bits to be configured */ |
mbed_official | 354:e67efb2aab0e | 924 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
mbed_official | 354:e67efb2aab0e | 925 | |
mbed_official | 354:e67efb2aab0e | 926 | tmpreg |= TimeStampEdge; |
mbed_official | 354:e67efb2aab0e | 927 | |
mbed_official | 354:e67efb2aab0e | 928 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 929 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 930 | |
mbed_official | 354:e67efb2aab0e | 931 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
mbed_official | 354:e67efb2aab0e | 932 | hrtc->Instance->CR = (uint32_t)tmpreg; |
mbed_official | 354:e67efb2aab0e | 933 | |
mbed_official | 354:e67efb2aab0e | 934 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 935 | |
mbed_official | 354:e67efb2aab0e | 936 | /* Enable IT timestamp */ |
mbed_official | 354:e67efb2aab0e | 937 | __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS); |
mbed_official | 354:e67efb2aab0e | 938 | |
mbed_official | 354:e67efb2aab0e | 939 | /* RTC timestamp Interrupt Configuration: EXTI configuration */ |
mbed_official | 354:e67efb2aab0e | 940 | __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT); |
mbed_official | 354:e67efb2aab0e | 941 | |
mbed_official | 354:e67efb2aab0e | 942 | EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT; |
mbed_official | 354:e67efb2aab0e | 943 | |
mbed_official | 354:e67efb2aab0e | 944 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 945 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 946 | |
mbed_official | 354:e67efb2aab0e | 947 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 948 | |
mbed_official | 354:e67efb2aab0e | 949 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 950 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 951 | |
mbed_official | 354:e67efb2aab0e | 952 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 953 | } |
mbed_official | 354:e67efb2aab0e | 954 | |
mbed_official | 354:e67efb2aab0e | 955 | /** |
mbed_official | 354:e67efb2aab0e | 956 | * @brief Deactivates TimeStamp. |
mbed_official | 354:e67efb2aab0e | 957 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 958 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 959 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 960 | */ |
mbed_official | 354:e67efb2aab0e | 961 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 962 | { |
mbed_official | 354:e67efb2aab0e | 963 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 964 | |
mbed_official | 354:e67efb2aab0e | 965 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 966 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 967 | |
mbed_official | 354:e67efb2aab0e | 968 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 969 | |
mbed_official | 354:e67efb2aab0e | 970 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 971 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 972 | |
mbed_official | 354:e67efb2aab0e | 973 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 354:e67efb2aab0e | 974 | __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS); |
mbed_official | 354:e67efb2aab0e | 975 | |
mbed_official | 354:e67efb2aab0e | 976 | /* Get the RTC_CR register and clear the bits to be configured */ |
mbed_official | 354:e67efb2aab0e | 977 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
mbed_official | 354:e67efb2aab0e | 978 | |
mbed_official | 354:e67efb2aab0e | 979 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
mbed_official | 354:e67efb2aab0e | 980 | hrtc->Instance->CR = (uint32_t)tmpreg; |
mbed_official | 354:e67efb2aab0e | 981 | |
mbed_official | 354:e67efb2aab0e | 982 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 983 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 984 | |
mbed_official | 354:e67efb2aab0e | 985 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 986 | |
mbed_official | 354:e67efb2aab0e | 987 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 988 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 989 | |
mbed_official | 354:e67efb2aab0e | 990 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 991 | } |
mbed_official | 354:e67efb2aab0e | 992 | |
mbed_official | 354:e67efb2aab0e | 993 | /** |
mbed_official | 354:e67efb2aab0e | 994 | * @brief Gets the RTC TimeStamp value. |
mbed_official | 354:e67efb2aab0e | 995 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 996 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 997 | * @param sTimeStamp: Pointer to Time structure |
mbed_official | 354:e67efb2aab0e | 998 | * @param sTimeStampDate: Pointer to Date structure |
mbed_official | 354:e67efb2aab0e | 999 | * @param Format: specifies the format of the entered parameters. |
mbed_official | 354:e67efb2aab0e | 1000 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 1001 | * FORMAT_BIN: Binary data format |
mbed_official | 354:e67efb2aab0e | 1002 | * FORMAT_BCD: BCD data format |
mbed_official | 354:e67efb2aab0e | 1003 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1004 | */ |
mbed_official | 354:e67efb2aab0e | 1005 | HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format) |
mbed_official | 354:e67efb2aab0e | 1006 | { |
mbed_official | 354:e67efb2aab0e | 1007 | uint32_t tmptime = 0, tmpdate = 0; |
mbed_official | 354:e67efb2aab0e | 1008 | |
mbed_official | 354:e67efb2aab0e | 1009 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1010 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 354:e67efb2aab0e | 1011 | |
mbed_official | 354:e67efb2aab0e | 1012 | /* Get the TimeStamp time and date registers values */ |
mbed_official | 354:e67efb2aab0e | 1013 | tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK); |
mbed_official | 354:e67efb2aab0e | 1014 | tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK); |
mbed_official | 354:e67efb2aab0e | 1015 | |
mbed_official | 354:e67efb2aab0e | 1016 | /* Fill the Time structure fields with the read parameters */ |
mbed_official | 354:e67efb2aab0e | 1017 | sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16); |
mbed_official | 354:e67efb2aab0e | 1018 | sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8); |
mbed_official | 354:e67efb2aab0e | 1019 | sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU)); |
mbed_official | 354:e67efb2aab0e | 1020 | sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16); |
mbed_official | 354:e67efb2aab0e | 1021 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1022 | sTimeStamp->SubSeconds = (uint32_t)((hrtc->Instance->TSSSR) & RTC_TSSSR_SS); |
mbed_official | 354:e67efb2aab0e | 1023 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1024 | |
mbed_official | 354:e67efb2aab0e | 1025 | /* Fill the Date structure fields with the read parameters */ |
mbed_official | 354:e67efb2aab0e | 1026 | sTimeStampDate->Year = 0; |
mbed_official | 354:e67efb2aab0e | 1027 | sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8); |
mbed_official | 354:e67efb2aab0e | 1028 | sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU)); |
mbed_official | 354:e67efb2aab0e | 1029 | sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13); |
mbed_official | 354:e67efb2aab0e | 1030 | |
mbed_official | 354:e67efb2aab0e | 1031 | /* Check the input parameters format */ |
mbed_official | 354:e67efb2aab0e | 1032 | if(Format == FORMAT_BIN) |
mbed_official | 354:e67efb2aab0e | 1033 | { |
mbed_official | 354:e67efb2aab0e | 1034 | /* Convert the TimeStamp structure parameters to Binary format */ |
mbed_official | 354:e67efb2aab0e | 1035 | sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours); |
mbed_official | 354:e67efb2aab0e | 1036 | sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes); |
mbed_official | 354:e67efb2aab0e | 1037 | sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds); |
mbed_official | 354:e67efb2aab0e | 1038 | |
mbed_official | 354:e67efb2aab0e | 1039 | /* Convert the DateTimeStamp structure parameters to Binary format */ |
mbed_official | 354:e67efb2aab0e | 1040 | sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month); |
mbed_official | 354:e67efb2aab0e | 1041 | sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date); |
mbed_official | 354:e67efb2aab0e | 1042 | sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay); |
mbed_official | 354:e67efb2aab0e | 1043 | } |
mbed_official | 354:e67efb2aab0e | 1044 | |
mbed_official | 354:e67efb2aab0e | 1045 | /* Clear the TIMESTAMP Flag */ |
mbed_official | 354:e67efb2aab0e | 1046 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); |
mbed_official | 354:e67efb2aab0e | 1047 | |
mbed_official | 354:e67efb2aab0e | 1048 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1049 | } |
mbed_official | 354:e67efb2aab0e | 1050 | |
mbed_official | 354:e67efb2aab0e | 1051 | /** |
mbed_official | 354:e67efb2aab0e | 1052 | * @brief Sets Tamper |
mbed_official | 354:e67efb2aab0e | 1053 | * @note By calling this API we disable the tamper interrupt for all tampers. |
mbed_official | 354:e67efb2aab0e | 1054 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1055 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1056 | * @param sTamper: Pointer to Tamper Structure. |
mbed_official | 354:e67efb2aab0e | 1057 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1058 | */ |
mbed_official | 354:e67efb2aab0e | 1059 | HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
mbed_official | 354:e67efb2aab0e | 1060 | { |
mbed_official | 354:e67efb2aab0e | 1061 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 1062 | |
mbed_official | 354:e67efb2aab0e | 1063 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1064 | assert_param(IS_TAMPER(sTamper->Tamper)); |
mbed_official | 354:e67efb2aab0e | 1065 | assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger)); |
mbed_official | 354:e67efb2aab0e | 1066 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1067 | assert_param(IS_TAMPER_FILTER(sTamper->Filter)); |
mbed_official | 354:e67efb2aab0e | 1068 | assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); |
mbed_official | 354:e67efb2aab0e | 1069 | assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); |
mbed_official | 354:e67efb2aab0e | 1070 | assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); |
mbed_official | 354:e67efb2aab0e | 1071 | assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); |
mbed_official | 354:e67efb2aab0e | 1072 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1073 | |
mbed_official | 354:e67efb2aab0e | 1074 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1075 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1076 | |
mbed_official | 354:e67efb2aab0e | 1077 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1078 | |
mbed_official | 354:e67efb2aab0e | 1079 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1080 | if((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE)) |
mbed_official | 354:e67efb2aab0e | 1081 | { |
mbed_official | 354:e67efb2aab0e | 1082 | /* Configure the RTC_TAFCR register */ |
mbed_official | 354:e67efb2aab0e | 1083 | sTamper->Trigger = RTC_TAMPERTRIGGER_RISINGEDGE; |
mbed_official | 354:e67efb2aab0e | 1084 | } |
mbed_official | 354:e67efb2aab0e | 1085 | else |
mbed_official | 354:e67efb2aab0e | 1086 | { |
mbed_official | 354:e67efb2aab0e | 1087 | sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1); |
mbed_official | 354:e67efb2aab0e | 1088 | } |
mbed_official | 354:e67efb2aab0e | 1089 | |
mbed_official | 354:e67efb2aab0e | 1090 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\ |
mbed_official | 354:e67efb2aab0e | 1091 | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\ |
mbed_official | 354:e67efb2aab0e | 1092 | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection); |
mbed_official | 354:e67efb2aab0e | 1093 | |
mbed_official | 354:e67efb2aab0e | 1094 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\ |
mbed_official | 354:e67efb2aab0e | 1095 | (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\ |
mbed_official | 354:e67efb2aab0e | 1096 | (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPIE); |
mbed_official | 354:e67efb2aab0e | 1097 | #else |
mbed_official | 354:e67efb2aab0e | 1098 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Trigger)); |
mbed_official | 354:e67efb2aab0e | 1099 | |
mbed_official | 354:e67efb2aab0e | 1100 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG); |
mbed_official | 354:e67efb2aab0e | 1101 | |
mbed_official | 354:e67efb2aab0e | 1102 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1103 | hrtc->Instance->TAFCR |= tmpreg; |
mbed_official | 354:e67efb2aab0e | 1104 | |
mbed_official | 354:e67efb2aab0e | 1105 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1106 | |
mbed_official | 354:e67efb2aab0e | 1107 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1108 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1109 | |
mbed_official | 354:e67efb2aab0e | 1110 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1111 | } |
mbed_official | 354:e67efb2aab0e | 1112 | |
mbed_official | 354:e67efb2aab0e | 1113 | /** |
mbed_official | 354:e67efb2aab0e | 1114 | * @brief Sets Tamper with interrupt. |
mbed_official | 354:e67efb2aab0e | 1115 | * @note By calling this API we force the tamper interrupt for all tampers. |
mbed_official | 354:e67efb2aab0e | 1116 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1117 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1118 | * @param sTamper: Pointer to RTC Tamper. |
mbed_official | 354:e67efb2aab0e | 1119 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1120 | */ |
mbed_official | 354:e67efb2aab0e | 1121 | HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
mbed_official | 354:e67efb2aab0e | 1122 | { |
mbed_official | 354:e67efb2aab0e | 1123 | uint32_t tmpreg = 0; |
mbed_official | 354:e67efb2aab0e | 1124 | |
mbed_official | 354:e67efb2aab0e | 1125 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1126 | assert_param(IS_TAMPER(sTamper->Tamper)); |
mbed_official | 354:e67efb2aab0e | 1127 | assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger)); |
mbed_official | 354:e67efb2aab0e | 1128 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1129 | assert_param(IS_TAMPER_FILTER(sTamper->Filter)); |
mbed_official | 354:e67efb2aab0e | 1130 | assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); |
mbed_official | 354:e67efb2aab0e | 1131 | assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); |
mbed_official | 354:e67efb2aab0e | 1132 | assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); |
mbed_official | 354:e67efb2aab0e | 1133 | assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); |
mbed_official | 354:e67efb2aab0e | 1134 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1135 | |
mbed_official | 354:e67efb2aab0e | 1136 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1137 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1138 | |
mbed_official | 354:e67efb2aab0e | 1139 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1140 | |
mbed_official | 354:e67efb2aab0e | 1141 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1142 | /* Configure the tamper trigger */ |
mbed_official | 354:e67efb2aab0e | 1143 | if((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE)) |
mbed_official | 354:e67efb2aab0e | 1144 | { |
mbed_official | 354:e67efb2aab0e | 1145 | sTamper->Trigger = RTC_TAMPERTRIGGER_RISINGEDGE; |
mbed_official | 354:e67efb2aab0e | 1146 | } |
mbed_official | 354:e67efb2aab0e | 1147 | else |
mbed_official | 354:e67efb2aab0e | 1148 | { |
mbed_official | 354:e67efb2aab0e | 1149 | sTamper->Trigger = (uint32_t) (sTamper->Tamper<<1); |
mbed_official | 354:e67efb2aab0e | 1150 | } |
mbed_official | 354:e67efb2aab0e | 1151 | |
mbed_official | 354:e67efb2aab0e | 1152 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\ |
mbed_official | 354:e67efb2aab0e | 1153 | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\ |
mbed_official | 354:e67efb2aab0e | 1154 | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection); |
mbed_official | 354:e67efb2aab0e | 1155 | |
mbed_official | 354:e67efb2aab0e | 1156 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\ |
mbed_official | 354:e67efb2aab0e | 1157 | (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\ |
mbed_official | 354:e67efb2aab0e | 1158 | (uint32_t)RTC_TAFCR_TAMPPUDIS); |
mbed_official | 354:e67efb2aab0e | 1159 | #else |
mbed_official | 354:e67efb2aab0e | 1160 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger); |
mbed_official | 354:e67efb2aab0e | 1161 | |
mbed_official | 354:e67efb2aab0e | 1162 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG | (uint32_t)RTC_TAFCR_TAMPIE); |
mbed_official | 354:e67efb2aab0e | 1163 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1164 | hrtc->Instance->TAFCR |= tmpreg; |
mbed_official | 354:e67efb2aab0e | 1165 | |
mbed_official | 354:e67efb2aab0e | 1166 | /* Configure the Tamper Interrupt in the RTC_TAFCR */ |
mbed_official | 354:e67efb2aab0e | 1167 | hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE; |
mbed_official | 354:e67efb2aab0e | 1168 | |
mbed_official | 354:e67efb2aab0e | 1169 | /* RTC Tamper Interrupt Configuration: EXTI configuration */ |
mbed_official | 354:e67efb2aab0e | 1170 | __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT); |
mbed_official | 354:e67efb2aab0e | 1171 | |
mbed_official | 354:e67efb2aab0e | 1172 | EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT; |
mbed_official | 354:e67efb2aab0e | 1173 | |
mbed_official | 354:e67efb2aab0e | 1174 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1175 | |
mbed_official | 354:e67efb2aab0e | 1176 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1177 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1178 | |
mbed_official | 354:e67efb2aab0e | 1179 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1180 | } |
mbed_official | 354:e67efb2aab0e | 1181 | |
mbed_official | 354:e67efb2aab0e | 1182 | /** |
mbed_official | 354:e67efb2aab0e | 1183 | * @brief Deactivates Tamper. |
mbed_official | 354:e67efb2aab0e | 1184 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1185 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1186 | * @param Tamper: Selected tamper pin. |
mbed_official | 354:e67efb2aab0e | 1187 | * This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions |
mbed_official | 354:e67efb2aab0e | 1188 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1189 | */ |
mbed_official | 354:e67efb2aab0e | 1190 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) |
mbed_official | 354:e67efb2aab0e | 1191 | { |
mbed_official | 354:e67efb2aab0e | 1192 | assert_param(IS_TAMPER(Tamper)); |
mbed_official | 354:e67efb2aab0e | 1193 | |
mbed_official | 354:e67efb2aab0e | 1194 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1195 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1196 | |
mbed_official | 354:e67efb2aab0e | 1197 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1198 | |
mbed_official | 354:e67efb2aab0e | 1199 | /* Disable the selected Tamper pin */ |
mbed_official | 354:e67efb2aab0e | 1200 | hrtc->Instance->TAFCR &= (uint32_t)~Tamper; |
mbed_official | 354:e67efb2aab0e | 1201 | |
mbed_official | 354:e67efb2aab0e | 1202 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1203 | |
mbed_official | 354:e67efb2aab0e | 1204 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1205 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1206 | |
mbed_official | 354:e67efb2aab0e | 1207 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1208 | } |
mbed_official | 354:e67efb2aab0e | 1209 | |
mbed_official | 354:e67efb2aab0e | 1210 | /** |
mbed_official | 354:e67efb2aab0e | 1211 | * @brief This function handles TimeStamp interrupt request. |
mbed_official | 354:e67efb2aab0e | 1212 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1213 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1214 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1215 | */ |
mbed_official | 354:e67efb2aab0e | 1216 | void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1217 | { |
mbed_official | 354:e67efb2aab0e | 1218 | if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS)) |
mbed_official | 354:e67efb2aab0e | 1219 | { |
mbed_official | 354:e67efb2aab0e | 1220 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1221 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 1222 | { |
mbed_official | 354:e67efb2aab0e | 1223 | /* TIMESTAMP callback */ |
mbed_official | 354:e67efb2aab0e | 1224 | HAL_RTCEx_TimeStampEventCallback(hrtc); |
mbed_official | 354:e67efb2aab0e | 1225 | |
mbed_official | 354:e67efb2aab0e | 1226 | /* Clear the TIMESTAMP interrupt pending bit */ |
mbed_official | 354:e67efb2aab0e | 1227 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF); |
mbed_official | 354:e67efb2aab0e | 1228 | } |
mbed_official | 354:e67efb2aab0e | 1229 | } |
mbed_official | 354:e67efb2aab0e | 1230 | |
mbed_official | 354:e67efb2aab0e | 1231 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1232 | if(__HAL_RTC_TAMPER_GET_IT(hrtc,RTC_IT_TAMP1)) |
mbed_official | 354:e67efb2aab0e | 1233 | { |
mbed_official | 354:e67efb2aab0e | 1234 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
mbed_official | 354:e67efb2aab0e | 1235 | if(((hrtc->Instance->TAFCR & (RTC_TAFCR_TAMPIE))) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 1236 | { |
mbed_official | 354:e67efb2aab0e | 1237 | /* Tamper callback */ |
mbed_official | 354:e67efb2aab0e | 1238 | HAL_RTCEx_Tamper1EventCallback(hrtc); |
mbed_official | 354:e67efb2aab0e | 1239 | |
mbed_official | 354:e67efb2aab0e | 1240 | /* Clear the Tamper interrupt pending bit */ |
mbed_official | 354:e67efb2aab0e | 1241 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F); |
mbed_official | 354:e67efb2aab0e | 1242 | } |
mbed_official | 354:e67efb2aab0e | 1243 | } |
mbed_official | 354:e67efb2aab0e | 1244 | |
mbed_official | 354:e67efb2aab0e | 1245 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1246 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1247 | if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP2)) |
mbed_official | 354:e67efb2aab0e | 1248 | { |
mbed_official | 354:e67efb2aab0e | 1249 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
mbed_official | 354:e67efb2aab0e | 1250 | if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 1251 | { |
mbed_official | 354:e67efb2aab0e | 1252 | /* Tamper callback */ |
mbed_official | 354:e67efb2aab0e | 1253 | HAL_RTCEx_Tamper2EventCallback(hrtc); |
mbed_official | 354:e67efb2aab0e | 1254 | |
mbed_official | 354:e67efb2aab0e | 1255 | /* Clear the Tamper interrupt pending bit */ |
mbed_official | 354:e67efb2aab0e | 1256 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F); |
mbed_official | 354:e67efb2aab0e | 1257 | } |
mbed_official | 354:e67efb2aab0e | 1258 | } |
mbed_official | 354:e67efb2aab0e | 1259 | |
mbed_official | 354:e67efb2aab0e | 1260 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1261 | if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP3)) |
mbed_official | 354:e67efb2aab0e | 1262 | { |
mbed_official | 354:e67efb2aab0e | 1263 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
mbed_official | 354:e67efb2aab0e | 1264 | if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 1265 | { |
mbed_official | 354:e67efb2aab0e | 1266 | /* Tamper callback */ |
mbed_official | 354:e67efb2aab0e | 1267 | HAL_RTCEx_Tamper3EventCallback(hrtc); |
mbed_official | 354:e67efb2aab0e | 1268 | |
mbed_official | 354:e67efb2aab0e | 1269 | /* Clear the Tamper interrupt pending bit */ |
mbed_official | 354:e67efb2aab0e | 1270 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F); |
mbed_official | 354:e67efb2aab0e | 1271 | } |
mbed_official | 354:e67efb2aab0e | 1272 | } |
mbed_official | 354:e67efb2aab0e | 1273 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1274 | |
mbed_official | 354:e67efb2aab0e | 1275 | /* Clear the EXTI s Flag for RTC TimeStamp and Tamper */ |
mbed_official | 354:e67efb2aab0e | 1276 | __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT); |
mbed_official | 354:e67efb2aab0e | 1277 | |
mbed_official | 354:e67efb2aab0e | 1278 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 1279 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1280 | } |
mbed_official | 354:e67efb2aab0e | 1281 | |
mbed_official | 354:e67efb2aab0e | 1282 | /** |
mbed_official | 354:e67efb2aab0e | 1283 | * @brief TimeStamp callback. |
mbed_official | 354:e67efb2aab0e | 1284 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1285 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1286 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1287 | */ |
mbed_official | 354:e67efb2aab0e | 1288 | __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1289 | { |
mbed_official | 354:e67efb2aab0e | 1290 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 354:e67efb2aab0e | 1291 | the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file |
mbed_official | 354:e67efb2aab0e | 1292 | */ |
mbed_official | 354:e67efb2aab0e | 1293 | } |
mbed_official | 354:e67efb2aab0e | 1294 | |
mbed_official | 354:e67efb2aab0e | 1295 | /** |
mbed_official | 354:e67efb2aab0e | 1296 | * @brief Tamper 1 callback. |
mbed_official | 354:e67efb2aab0e | 1297 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1298 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1299 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1300 | */ |
mbed_official | 354:e67efb2aab0e | 1301 | __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1302 | { |
mbed_official | 354:e67efb2aab0e | 1303 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 354:e67efb2aab0e | 1304 | the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file |
mbed_official | 354:e67efb2aab0e | 1305 | */ |
mbed_official | 354:e67efb2aab0e | 1306 | } |
mbed_official | 354:e67efb2aab0e | 1307 | |
mbed_official | 354:e67efb2aab0e | 1308 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1309 | /** |
mbed_official | 354:e67efb2aab0e | 1310 | * @brief Tamper 2 callback. |
mbed_official | 354:e67efb2aab0e | 1311 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1312 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1313 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1314 | */ |
mbed_official | 354:e67efb2aab0e | 1315 | __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1316 | { |
mbed_official | 354:e67efb2aab0e | 1317 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 354:e67efb2aab0e | 1318 | the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file |
mbed_official | 354:e67efb2aab0e | 1319 | */ |
mbed_official | 354:e67efb2aab0e | 1320 | } |
mbed_official | 354:e67efb2aab0e | 1321 | |
mbed_official | 354:e67efb2aab0e | 1322 | /** |
mbed_official | 354:e67efb2aab0e | 1323 | * @brief Tamper 3 callback. |
mbed_official | 354:e67efb2aab0e | 1324 | * @param hrtc: RTC handle |
mbed_official | 354:e67efb2aab0e | 1325 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1326 | */ |
mbed_official | 354:e67efb2aab0e | 1327 | __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1328 | { |
mbed_official | 354:e67efb2aab0e | 1329 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 354:e67efb2aab0e | 1330 | the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file |
mbed_official | 354:e67efb2aab0e | 1331 | */ |
mbed_official | 354:e67efb2aab0e | 1332 | } |
mbed_official | 354:e67efb2aab0e | 1333 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1334 | |
mbed_official | 354:e67efb2aab0e | 1335 | /** |
mbed_official | 354:e67efb2aab0e | 1336 | * @brief This function handles TimeStamp polling request. |
mbed_official | 354:e67efb2aab0e | 1337 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1338 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1339 | * @param Timeout: Timeout duration |
mbed_official | 354:e67efb2aab0e | 1340 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1341 | */ |
mbed_official | 354:e67efb2aab0e | 1342 | HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
mbed_official | 354:e67efb2aab0e | 1343 | { |
mbed_official | 354:e67efb2aab0e | 1344 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1345 | |
mbed_official | 354:e67efb2aab0e | 1346 | while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET) |
mbed_official | 354:e67efb2aab0e | 1347 | { |
mbed_official | 354:e67efb2aab0e | 1348 | if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET) |
mbed_official | 354:e67efb2aab0e | 1349 | { |
mbed_official | 354:e67efb2aab0e | 1350 | /* Clear the TIMESTAMP OverRun Flag */ |
mbed_official | 354:e67efb2aab0e | 1351 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF); |
mbed_official | 354:e67efb2aab0e | 1352 | |
mbed_official | 354:e67efb2aab0e | 1353 | /* Change TIMESTAMP state */ |
mbed_official | 354:e67efb2aab0e | 1354 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 1355 | |
mbed_official | 354:e67efb2aab0e | 1356 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 1357 | } |
mbed_official | 354:e67efb2aab0e | 1358 | |
mbed_official | 354:e67efb2aab0e | 1359 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 354:e67efb2aab0e | 1360 | { |
mbed_official | 354:e67efb2aab0e | 1361 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 354:e67efb2aab0e | 1362 | { |
mbed_official | 354:e67efb2aab0e | 1363 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1364 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1365 | } |
mbed_official | 354:e67efb2aab0e | 1366 | } |
mbed_official | 354:e67efb2aab0e | 1367 | } |
mbed_official | 354:e67efb2aab0e | 1368 | |
mbed_official | 354:e67efb2aab0e | 1369 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 1370 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1371 | |
mbed_official | 354:e67efb2aab0e | 1372 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1373 | } |
mbed_official | 354:e67efb2aab0e | 1374 | |
mbed_official | 354:e67efb2aab0e | 1375 | /** |
mbed_official | 354:e67efb2aab0e | 1376 | * @brief This function handles Tamper1 Polling. |
mbed_official | 354:e67efb2aab0e | 1377 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1378 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1379 | * @param Timeout: Timeout duration |
mbed_official | 354:e67efb2aab0e | 1380 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1381 | */ |
mbed_official | 354:e67efb2aab0e | 1382 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
mbed_official | 354:e67efb2aab0e | 1383 | { |
mbed_official | 354:e67efb2aab0e | 1384 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1385 | |
mbed_official | 354:e67efb2aab0e | 1386 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1387 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP1F)== RESET) |
mbed_official | 354:e67efb2aab0e | 1388 | { |
mbed_official | 354:e67efb2aab0e | 1389 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 354:e67efb2aab0e | 1390 | { |
mbed_official | 354:e67efb2aab0e | 1391 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 354:e67efb2aab0e | 1392 | { |
mbed_official | 354:e67efb2aab0e | 1393 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1394 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1395 | } |
mbed_official | 354:e67efb2aab0e | 1396 | } |
mbed_official | 354:e67efb2aab0e | 1397 | } |
mbed_official | 354:e67efb2aab0e | 1398 | |
mbed_official | 354:e67efb2aab0e | 1399 | /* Clear the Tamper Flag */ |
mbed_official | 354:e67efb2aab0e | 1400 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F); |
mbed_official | 354:e67efb2aab0e | 1401 | |
mbed_official | 354:e67efb2aab0e | 1402 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 1403 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1404 | |
mbed_official | 354:e67efb2aab0e | 1405 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1406 | } |
mbed_official | 354:e67efb2aab0e | 1407 | |
mbed_official | 354:e67efb2aab0e | 1408 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1409 | /** |
mbed_official | 354:e67efb2aab0e | 1410 | * @brief This function handles Tamper2 Polling. |
mbed_official | 354:e67efb2aab0e | 1411 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1412 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1413 | * @param Timeout: Timeout duration |
mbed_official | 354:e67efb2aab0e | 1414 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1415 | */ |
mbed_official | 354:e67efb2aab0e | 1416 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
mbed_official | 354:e67efb2aab0e | 1417 | { |
mbed_official | 354:e67efb2aab0e | 1418 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1419 | |
mbed_official | 354:e67efb2aab0e | 1420 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1421 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP2F) == RESET) |
mbed_official | 354:e67efb2aab0e | 1422 | { |
mbed_official | 354:e67efb2aab0e | 1423 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 354:e67efb2aab0e | 1424 | { |
mbed_official | 354:e67efb2aab0e | 1425 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 354:e67efb2aab0e | 1426 | { |
mbed_official | 354:e67efb2aab0e | 1427 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1428 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1429 | } |
mbed_official | 354:e67efb2aab0e | 1430 | } |
mbed_official | 354:e67efb2aab0e | 1431 | } |
mbed_official | 354:e67efb2aab0e | 1432 | |
mbed_official | 354:e67efb2aab0e | 1433 | /* Clear the Tamper Flag */ |
mbed_official | 354:e67efb2aab0e | 1434 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F); |
mbed_official | 354:e67efb2aab0e | 1435 | |
mbed_official | 354:e67efb2aab0e | 1436 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 1437 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1438 | |
mbed_official | 354:e67efb2aab0e | 1439 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1440 | } |
mbed_official | 354:e67efb2aab0e | 1441 | |
mbed_official | 354:e67efb2aab0e | 1442 | /** |
mbed_official | 354:e67efb2aab0e | 1443 | * @brief This function handles Tamper3 Polling. |
mbed_official | 354:e67efb2aab0e | 1444 | * @param hrtc: RTC handle |
mbed_official | 354:e67efb2aab0e | 1445 | * @param Timeout: Timeout duration |
mbed_official | 354:e67efb2aab0e | 1446 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1447 | */ |
mbed_official | 354:e67efb2aab0e | 1448 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
mbed_official | 354:e67efb2aab0e | 1449 | { |
mbed_official | 354:e67efb2aab0e | 1450 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1451 | |
mbed_official | 354:e67efb2aab0e | 1452 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1453 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP3F) == RESET) |
mbed_official | 354:e67efb2aab0e | 1454 | { |
mbed_official | 354:e67efb2aab0e | 1455 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 354:e67efb2aab0e | 1456 | { |
mbed_official | 354:e67efb2aab0e | 1457 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 354:e67efb2aab0e | 1458 | { |
mbed_official | 354:e67efb2aab0e | 1459 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1460 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1461 | } |
mbed_official | 354:e67efb2aab0e | 1462 | } |
mbed_official | 354:e67efb2aab0e | 1463 | } |
mbed_official | 354:e67efb2aab0e | 1464 | |
mbed_official | 354:e67efb2aab0e | 1465 | /* Clear the Tamper Flag */ |
mbed_official | 354:e67efb2aab0e | 1466 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP3F); |
mbed_official | 354:e67efb2aab0e | 1467 | |
mbed_official | 354:e67efb2aab0e | 1468 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 1469 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1470 | |
mbed_official | 354:e67efb2aab0e | 1471 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1472 | } |
mbed_official | 354:e67efb2aab0e | 1473 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 1474 | |
mbed_official | 354:e67efb2aab0e | 1475 | /** |
mbed_official | 354:e67efb2aab0e | 1476 | * @} |
mbed_official | 354:e67efb2aab0e | 1477 | */ |
mbed_official | 354:e67efb2aab0e | 1478 | |
mbed_official | 354:e67efb2aab0e | 1479 | /** @defgroup RTCEx_Exported_Functions_Group5 RTC Wake-up functions |
mbed_official | 354:e67efb2aab0e | 1480 | * @brief RTC Wake-up functions |
mbed_official | 354:e67efb2aab0e | 1481 | * |
mbed_official | 354:e67efb2aab0e | 1482 | @verbatim |
mbed_official | 354:e67efb2aab0e | 1483 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 1484 | ##### RTC Wake-up functions ##### |
mbed_official | 354:e67efb2aab0e | 1485 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 1486 | |
mbed_official | 354:e67efb2aab0e | 1487 | [..] This section provides functions allowing to configure Wake-up feature |
mbed_official | 354:e67efb2aab0e | 1488 | |
mbed_official | 354:e67efb2aab0e | 1489 | @endverbatim |
mbed_official | 354:e67efb2aab0e | 1490 | * @{ |
mbed_official | 354:e67efb2aab0e | 1491 | */ |
mbed_official | 354:e67efb2aab0e | 1492 | |
mbed_official | 354:e67efb2aab0e | 1493 | /** |
mbed_official | 354:e67efb2aab0e | 1494 | * @brief Sets wake up timer. |
mbed_official | 354:e67efb2aab0e | 1495 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1496 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1497 | * @param WakeUpCounter: Wake up counter |
mbed_official | 354:e67efb2aab0e | 1498 | * @param WakeUpClock: Wake up clock |
mbed_official | 354:e67efb2aab0e | 1499 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1500 | */ |
mbed_official | 354:e67efb2aab0e | 1501 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
mbed_official | 354:e67efb2aab0e | 1502 | { |
mbed_official | 354:e67efb2aab0e | 1503 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 1504 | |
mbed_official | 354:e67efb2aab0e | 1505 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1506 | assert_param(IS_WAKEUP_CLOCK(WakeUpClock)); |
mbed_official | 354:e67efb2aab0e | 1507 | assert_param(IS_WAKEUP_COUNTER(WakeUpCounter)); |
mbed_official | 354:e67efb2aab0e | 1508 | |
mbed_official | 354:e67efb2aab0e | 1509 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1510 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1511 | |
mbed_official | 354:e67efb2aab0e | 1512 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1513 | |
mbed_official | 354:e67efb2aab0e | 1514 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1515 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1516 | |
mbed_official | 354:e67efb2aab0e | 1517 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1518 | |
mbed_official | 354:e67efb2aab0e | 1519 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1520 | |
mbed_official | 354:e67efb2aab0e | 1521 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 1522 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
mbed_official | 354:e67efb2aab0e | 1523 | { |
mbed_official | 354:e67efb2aab0e | 1524 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 1525 | { |
mbed_official | 354:e67efb2aab0e | 1526 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1527 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1528 | |
mbed_official | 354:e67efb2aab0e | 1529 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1530 | |
mbed_official | 354:e67efb2aab0e | 1531 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1532 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1533 | |
mbed_official | 354:e67efb2aab0e | 1534 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1535 | } |
mbed_official | 354:e67efb2aab0e | 1536 | } |
mbed_official | 354:e67efb2aab0e | 1537 | |
mbed_official | 354:e67efb2aab0e | 1538 | /* Clear the Wakeup Timer clock source bits in CR register */ |
mbed_official | 354:e67efb2aab0e | 1539 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
mbed_official | 354:e67efb2aab0e | 1540 | |
mbed_official | 354:e67efb2aab0e | 1541 | /* Configure the clock source */ |
mbed_official | 354:e67efb2aab0e | 1542 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
mbed_official | 354:e67efb2aab0e | 1543 | |
mbed_official | 354:e67efb2aab0e | 1544 | /* Configure the Wakeup Timer counter */ |
mbed_official | 354:e67efb2aab0e | 1545 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
mbed_official | 354:e67efb2aab0e | 1546 | |
mbed_official | 354:e67efb2aab0e | 1547 | /* Enable the Wakeup Timer */ |
mbed_official | 354:e67efb2aab0e | 1548 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1549 | |
mbed_official | 354:e67efb2aab0e | 1550 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1551 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1552 | |
mbed_official | 354:e67efb2aab0e | 1553 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1554 | |
mbed_official | 354:e67efb2aab0e | 1555 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1556 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1557 | |
mbed_official | 354:e67efb2aab0e | 1558 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1559 | } |
mbed_official | 354:e67efb2aab0e | 1560 | |
mbed_official | 354:e67efb2aab0e | 1561 | /** |
mbed_official | 354:e67efb2aab0e | 1562 | * @brief Sets wake up timer with interrupt |
mbed_official | 354:e67efb2aab0e | 1563 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1564 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1565 | * @param WakeUpCounter: Wake up counter |
mbed_official | 354:e67efb2aab0e | 1566 | * @param WakeUpClock: Wake up clock |
mbed_official | 354:e67efb2aab0e | 1567 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1568 | */ |
mbed_official | 354:e67efb2aab0e | 1569 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
mbed_official | 354:e67efb2aab0e | 1570 | { |
mbed_official | 354:e67efb2aab0e | 1571 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 1572 | |
mbed_official | 354:e67efb2aab0e | 1573 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1574 | assert_param(IS_WAKEUP_CLOCK(WakeUpClock)); |
mbed_official | 354:e67efb2aab0e | 1575 | assert_param(IS_WAKEUP_COUNTER(WakeUpCounter)); |
mbed_official | 354:e67efb2aab0e | 1576 | |
mbed_official | 354:e67efb2aab0e | 1577 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1578 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1579 | |
mbed_official | 354:e67efb2aab0e | 1580 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1581 | |
mbed_official | 354:e67efb2aab0e | 1582 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1583 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1584 | |
mbed_official | 354:e67efb2aab0e | 1585 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1586 | |
mbed_official | 354:e67efb2aab0e | 1587 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1588 | |
mbed_official | 354:e67efb2aab0e | 1589 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 1590 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
mbed_official | 354:e67efb2aab0e | 1591 | { |
mbed_official | 354:e67efb2aab0e | 1592 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 1593 | { |
mbed_official | 354:e67efb2aab0e | 1594 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1595 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1596 | |
mbed_official | 354:e67efb2aab0e | 1597 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1598 | |
mbed_official | 354:e67efb2aab0e | 1599 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1600 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1601 | |
mbed_official | 354:e67efb2aab0e | 1602 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1603 | } |
mbed_official | 354:e67efb2aab0e | 1604 | } |
mbed_official | 354:e67efb2aab0e | 1605 | |
mbed_official | 354:e67efb2aab0e | 1606 | /* Configure the Wakeup Timer counter */ |
mbed_official | 354:e67efb2aab0e | 1607 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
mbed_official | 354:e67efb2aab0e | 1608 | |
mbed_official | 354:e67efb2aab0e | 1609 | /* Clear the Wakeup Timer clock source bits in CR register */ |
mbed_official | 354:e67efb2aab0e | 1610 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
mbed_official | 354:e67efb2aab0e | 1611 | |
mbed_official | 354:e67efb2aab0e | 1612 | /* Configure the clock source */ |
mbed_official | 354:e67efb2aab0e | 1613 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
mbed_official | 354:e67efb2aab0e | 1614 | |
mbed_official | 354:e67efb2aab0e | 1615 | /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */ |
mbed_official | 354:e67efb2aab0e | 1616 | __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_WAKEUPTIMER_EVENT); |
mbed_official | 354:e67efb2aab0e | 1617 | |
mbed_official | 354:e67efb2aab0e | 1618 | EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT; |
mbed_official | 354:e67efb2aab0e | 1619 | |
mbed_official | 354:e67efb2aab0e | 1620 | /* Configure the Interrupt in the RTC_CR register */ |
mbed_official | 354:e67efb2aab0e | 1621 | __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT); |
mbed_official | 354:e67efb2aab0e | 1622 | |
mbed_official | 354:e67efb2aab0e | 1623 | /* Enable the Wakeup Timer */ |
mbed_official | 354:e67efb2aab0e | 1624 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1625 | |
mbed_official | 354:e67efb2aab0e | 1626 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1627 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1628 | |
mbed_official | 354:e67efb2aab0e | 1629 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1630 | |
mbed_official | 354:e67efb2aab0e | 1631 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1632 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1633 | |
mbed_official | 354:e67efb2aab0e | 1634 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1635 | } |
mbed_official | 354:e67efb2aab0e | 1636 | |
mbed_official | 354:e67efb2aab0e | 1637 | /** |
mbed_official | 354:e67efb2aab0e | 1638 | * @brief Deactivates wake up timer counter. |
mbed_official | 354:e67efb2aab0e | 1639 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1640 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1641 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1642 | */ |
mbed_official | 354:e67efb2aab0e | 1643 | uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1644 | { |
mbed_official | 354:e67efb2aab0e | 1645 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 1646 | |
mbed_official | 354:e67efb2aab0e | 1647 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1648 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1649 | |
mbed_official | 354:e67efb2aab0e | 1650 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1651 | |
mbed_official | 354:e67efb2aab0e | 1652 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1653 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1654 | |
mbed_official | 354:e67efb2aab0e | 1655 | /* Disable the Wakeup Timer */ |
mbed_official | 354:e67efb2aab0e | 1656 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1657 | |
mbed_official | 354:e67efb2aab0e | 1658 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 354:e67efb2aab0e | 1659 | __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT); |
mbed_official | 354:e67efb2aab0e | 1660 | |
mbed_official | 354:e67efb2aab0e | 1661 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1662 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
mbed_official | 354:e67efb2aab0e | 1663 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
mbed_official | 354:e67efb2aab0e | 1664 | { |
mbed_official | 354:e67efb2aab0e | 1665 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 1666 | { |
mbed_official | 354:e67efb2aab0e | 1667 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1668 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1669 | |
mbed_official | 354:e67efb2aab0e | 1670 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1671 | |
mbed_official | 354:e67efb2aab0e | 1672 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1673 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1674 | |
mbed_official | 354:e67efb2aab0e | 1675 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1676 | } |
mbed_official | 354:e67efb2aab0e | 1677 | } |
mbed_official | 354:e67efb2aab0e | 1678 | |
mbed_official | 354:e67efb2aab0e | 1679 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1680 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1681 | |
mbed_official | 354:e67efb2aab0e | 1682 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1683 | |
mbed_official | 354:e67efb2aab0e | 1684 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1685 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1686 | |
mbed_official | 354:e67efb2aab0e | 1687 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1688 | } |
mbed_official | 354:e67efb2aab0e | 1689 | |
mbed_official | 354:e67efb2aab0e | 1690 | /** |
mbed_official | 354:e67efb2aab0e | 1691 | * @brief Gets wake up timer counter. |
mbed_official | 354:e67efb2aab0e | 1692 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1693 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1694 | * @retval Counter value |
mbed_official | 354:e67efb2aab0e | 1695 | */ |
mbed_official | 354:e67efb2aab0e | 1696 | uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1697 | { |
mbed_official | 354:e67efb2aab0e | 1698 | /* Get the counter value */ |
mbed_official | 354:e67efb2aab0e | 1699 | return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT)); |
mbed_official | 354:e67efb2aab0e | 1700 | } |
mbed_official | 354:e67efb2aab0e | 1701 | |
mbed_official | 354:e67efb2aab0e | 1702 | /** |
mbed_official | 354:e67efb2aab0e | 1703 | * @brief This function handles Wake Up Timer interrupt request. |
mbed_official | 354:e67efb2aab0e | 1704 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1705 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1706 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1707 | */ |
mbed_official | 354:e67efb2aab0e | 1708 | void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1709 | { |
mbed_official | 354:e67efb2aab0e | 1710 | if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT)) |
mbed_official | 354:e67efb2aab0e | 1711 | { |
mbed_official | 354:e67efb2aab0e | 1712 | /* Get the status of the Interrupt */ |
mbed_official | 354:e67efb2aab0e | 1713 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET) |
mbed_official | 354:e67efb2aab0e | 1714 | { |
mbed_official | 354:e67efb2aab0e | 1715 | /* WAKEUPTIMER callback */ |
mbed_official | 354:e67efb2aab0e | 1716 | HAL_RTCEx_WakeUpTimerEventCallback(hrtc); |
mbed_official | 354:e67efb2aab0e | 1717 | |
mbed_official | 354:e67efb2aab0e | 1718 | /* Clear the WAKEUPTIMER interrupt pending bit */ |
mbed_official | 354:e67efb2aab0e | 1719 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
mbed_official | 354:e67efb2aab0e | 1720 | } |
mbed_official | 354:e67efb2aab0e | 1721 | } |
mbed_official | 354:e67efb2aab0e | 1722 | |
mbed_official | 354:e67efb2aab0e | 1723 | /* Clear the EXTI s line Flag for RTC WakeUpTimer */ |
mbed_official | 354:e67efb2aab0e | 1724 | __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_WAKEUPTIMER_EVENT); |
mbed_official | 354:e67efb2aab0e | 1725 | |
mbed_official | 354:e67efb2aab0e | 1726 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 1727 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1728 | } |
mbed_official | 354:e67efb2aab0e | 1729 | |
mbed_official | 354:e67efb2aab0e | 1730 | /** |
mbed_official | 354:e67efb2aab0e | 1731 | * @brief Wake Up Timer callback. |
mbed_official | 354:e67efb2aab0e | 1732 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1733 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1734 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1735 | */ |
mbed_official | 354:e67efb2aab0e | 1736 | __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 1737 | { |
mbed_official | 354:e67efb2aab0e | 1738 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 354:e67efb2aab0e | 1739 | the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file |
mbed_official | 354:e67efb2aab0e | 1740 | */ |
mbed_official | 354:e67efb2aab0e | 1741 | } |
mbed_official | 354:e67efb2aab0e | 1742 | |
mbed_official | 354:e67efb2aab0e | 1743 | /** |
mbed_official | 354:e67efb2aab0e | 1744 | * @brief This function handles Wake Up Timer Polling. |
mbed_official | 354:e67efb2aab0e | 1745 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1746 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1747 | * @param Timeout: Timeout duration |
mbed_official | 354:e67efb2aab0e | 1748 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1749 | */ |
mbed_official | 354:e67efb2aab0e | 1750 | HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
mbed_official | 354:e67efb2aab0e | 1751 | { |
mbed_official | 354:e67efb2aab0e | 1752 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 1753 | |
mbed_official | 354:e67efb2aab0e | 1754 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET) |
mbed_official | 354:e67efb2aab0e | 1755 | { |
mbed_official | 354:e67efb2aab0e | 1756 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 354:e67efb2aab0e | 1757 | { |
mbed_official | 354:e67efb2aab0e | 1758 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 354:e67efb2aab0e | 1759 | { |
mbed_official | 354:e67efb2aab0e | 1760 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1761 | |
mbed_official | 354:e67efb2aab0e | 1762 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 1763 | } |
mbed_official | 354:e67efb2aab0e | 1764 | } |
mbed_official | 354:e67efb2aab0e | 1765 | } |
mbed_official | 354:e67efb2aab0e | 1766 | |
mbed_official | 354:e67efb2aab0e | 1767 | /* Clear the WAKEUPTIMER Flag */ |
mbed_official | 354:e67efb2aab0e | 1768 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
mbed_official | 354:e67efb2aab0e | 1769 | |
mbed_official | 354:e67efb2aab0e | 1770 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 1771 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1772 | |
mbed_official | 354:e67efb2aab0e | 1773 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1774 | } |
mbed_official | 354:e67efb2aab0e | 1775 | |
mbed_official | 354:e67efb2aab0e | 1776 | /** |
mbed_official | 354:e67efb2aab0e | 1777 | * @} |
mbed_official | 354:e67efb2aab0e | 1778 | */ |
mbed_official | 354:e67efb2aab0e | 1779 | |
mbed_official | 354:e67efb2aab0e | 1780 | /** @defgroup RTCEx_Exported_Functions_Group7 Extended Peripheral Control functions |
mbed_official | 354:e67efb2aab0e | 1781 | * @brief Extended Peripheral Control functions |
mbed_official | 354:e67efb2aab0e | 1782 | * |
mbed_official | 354:e67efb2aab0e | 1783 | @verbatim |
mbed_official | 354:e67efb2aab0e | 1784 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 1785 | ##### Extension Peripheral Control functions ##### |
mbed_official | 354:e67efb2aab0e | 1786 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 1787 | [..] |
mbed_official | 354:e67efb2aab0e | 1788 | This subsection provides functions allowing to |
mbed_official | 354:e67efb2aab0e | 1789 | (+) Writes a data in a specified RTC Backup data register |
mbed_official | 354:e67efb2aab0e | 1790 | (+) Read a data in a specified RTC Backup data register |
mbed_official | 354:e67efb2aab0e | 1791 | (+) Sets the Coarse calibration parameters. |
mbed_official | 354:e67efb2aab0e | 1792 | (+) Deactivates the Coarse calibration parameters |
mbed_official | 354:e67efb2aab0e | 1793 | (+) Sets the Smooth calibration parameters. |
mbed_official | 354:e67efb2aab0e | 1794 | (+) Configures the Synchronization Shift Control Settings. |
mbed_official | 354:e67efb2aab0e | 1795 | (+) Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
mbed_official | 354:e67efb2aab0e | 1796 | (+) Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
mbed_official | 354:e67efb2aab0e | 1797 | (+) Enables the RTC reference clock detection. |
mbed_official | 354:e67efb2aab0e | 1798 | (+) Disable the RTC reference clock detection. |
mbed_official | 354:e67efb2aab0e | 1799 | (+) Enables the Bypass Shadow feature. |
mbed_official | 354:e67efb2aab0e | 1800 | (+) Disables the Bypass Shadow feature. |
mbed_official | 354:e67efb2aab0e | 1801 | |
mbed_official | 354:e67efb2aab0e | 1802 | @endverbatim |
mbed_official | 354:e67efb2aab0e | 1803 | * @{ |
mbed_official | 354:e67efb2aab0e | 1804 | */ |
mbed_official | 354:e67efb2aab0e | 1805 | |
mbed_official | 354:e67efb2aab0e | 1806 | /** |
mbed_official | 354:e67efb2aab0e | 1807 | * @brief Writes a data in a specified RTC Backup data register. |
mbed_official | 354:e67efb2aab0e | 1808 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1809 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1810 | * @param BackupRegister: RTC Backup data Register number. |
mbed_official | 354:e67efb2aab0e | 1811 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
mbed_official | 354:e67efb2aab0e | 1812 | * specify the register. |
mbed_official | 354:e67efb2aab0e | 1813 | * @param Data: Data to be written in the specified RTC Backup data register. |
mbed_official | 354:e67efb2aab0e | 1814 | * @retval None |
mbed_official | 354:e67efb2aab0e | 1815 | */ |
mbed_official | 354:e67efb2aab0e | 1816 | void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) |
mbed_official | 354:e67efb2aab0e | 1817 | { |
mbed_official | 354:e67efb2aab0e | 1818 | uint32_t tmp = 0; |
mbed_official | 354:e67efb2aab0e | 1819 | |
mbed_official | 354:e67efb2aab0e | 1820 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1821 | assert_param(IS_RTC_BKP(BackupRegister)); |
mbed_official | 354:e67efb2aab0e | 1822 | |
mbed_official | 354:e67efb2aab0e | 1823 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
mbed_official | 354:e67efb2aab0e | 1824 | tmp += (BackupRegister * 4); |
mbed_official | 354:e67efb2aab0e | 1825 | |
mbed_official | 354:e67efb2aab0e | 1826 | /* Write the specified register */ |
mbed_official | 354:e67efb2aab0e | 1827 | *(__IO uint32_t *)tmp = (uint32_t)Data; |
mbed_official | 354:e67efb2aab0e | 1828 | } |
mbed_official | 354:e67efb2aab0e | 1829 | |
mbed_official | 354:e67efb2aab0e | 1830 | /** |
mbed_official | 354:e67efb2aab0e | 1831 | * @brief Reads data from the specified RTC Backup data Register. |
mbed_official | 354:e67efb2aab0e | 1832 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1833 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1834 | * @param BackupRegister: RTC Backup data Register number. |
mbed_official | 354:e67efb2aab0e | 1835 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
mbed_official | 354:e67efb2aab0e | 1836 | * specify the register. |
mbed_official | 354:e67efb2aab0e | 1837 | * @retval Read value |
mbed_official | 354:e67efb2aab0e | 1838 | */ |
mbed_official | 354:e67efb2aab0e | 1839 | uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) |
mbed_official | 354:e67efb2aab0e | 1840 | { |
mbed_official | 354:e67efb2aab0e | 1841 | uint32_t tmp = 0; |
mbed_official | 354:e67efb2aab0e | 1842 | |
mbed_official | 354:e67efb2aab0e | 1843 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1844 | assert_param(IS_RTC_BKP(BackupRegister)); |
mbed_official | 354:e67efb2aab0e | 1845 | |
mbed_official | 354:e67efb2aab0e | 1846 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
mbed_official | 354:e67efb2aab0e | 1847 | tmp += (BackupRegister * 4); |
mbed_official | 354:e67efb2aab0e | 1848 | |
mbed_official | 354:e67efb2aab0e | 1849 | /* Read the specified register */ |
mbed_official | 354:e67efb2aab0e | 1850 | return (*(__IO uint32_t *)tmp); |
mbed_official | 354:e67efb2aab0e | 1851 | } |
mbed_official | 354:e67efb2aab0e | 1852 | |
mbed_official | 354:e67efb2aab0e | 1853 | /** |
mbed_official | 354:e67efb2aab0e | 1854 | * @brief Sets the Coarse calibration parameters. |
mbed_official | 354:e67efb2aab0e | 1855 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1856 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1857 | * @param CalibSign: Specifies the sign of the coarse calibration value. |
mbed_official | 354:e67efb2aab0e | 1858 | * This parameter can be one of the following values : |
mbed_official | 354:e67efb2aab0e | 1859 | * @arg RTC_CALIBSIGN_POSITIVE: The value sign is positive |
mbed_official | 354:e67efb2aab0e | 1860 | * @arg RTC_CALIBSIGN_NEGATIVE: The value sign is negative |
mbed_official | 354:e67efb2aab0e | 1861 | * @param Value: value of coarse calibration expressed in ppm (coded on 5 bits). |
mbed_official | 354:e67efb2aab0e | 1862 | * |
mbed_official | 354:e67efb2aab0e | 1863 | * @note This Calibration value should be between 0 and 63 when using negative |
mbed_official | 354:e67efb2aab0e | 1864 | * sign with a 2-ppm step. |
mbed_official | 354:e67efb2aab0e | 1865 | * |
mbed_official | 354:e67efb2aab0e | 1866 | * @note This Calibration value should be between 0 and 126 when using positive |
mbed_official | 354:e67efb2aab0e | 1867 | * sign with a 4-ppm step. |
mbed_official | 354:e67efb2aab0e | 1868 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1869 | */ |
mbed_official | 354:e67efb2aab0e | 1870 | HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef* hrtc, uint32_t CalibSign, uint32_t Value) |
mbed_official | 354:e67efb2aab0e | 1871 | { |
mbed_official | 354:e67efb2aab0e | 1872 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1873 | assert_param(IS_RTC_CALIB_SIGN(CalibSign)); |
mbed_official | 354:e67efb2aab0e | 1874 | assert_param(IS_RTC_CALIB_VALUE(Value)); |
mbed_official | 354:e67efb2aab0e | 1875 | |
mbed_official | 354:e67efb2aab0e | 1876 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1877 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1878 | |
mbed_official | 354:e67efb2aab0e | 1879 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1880 | |
mbed_official | 354:e67efb2aab0e | 1881 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1882 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1883 | |
mbed_official | 354:e67efb2aab0e | 1884 | /* Set Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 1885 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 354:e67efb2aab0e | 1886 | { |
mbed_official | 354:e67efb2aab0e | 1887 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1888 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1889 | |
mbed_official | 354:e67efb2aab0e | 1890 | /* Set RTC state*/ |
mbed_official | 354:e67efb2aab0e | 1891 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 1892 | |
mbed_official | 354:e67efb2aab0e | 1893 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1894 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1895 | |
mbed_official | 354:e67efb2aab0e | 1896 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 1897 | } |
mbed_official | 354:e67efb2aab0e | 1898 | else |
mbed_official | 354:e67efb2aab0e | 1899 | { |
mbed_official | 354:e67efb2aab0e | 1900 | /* Enable the Coarse Calibration */ |
mbed_official | 354:e67efb2aab0e | 1901 | __HAL_RTC_COARSE_CALIB_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1902 | |
mbed_official | 354:e67efb2aab0e | 1903 | /* Set the coarse calibration value */ |
mbed_official | 354:e67efb2aab0e | 1904 | hrtc->Instance->CALIBR = (uint32_t)(CalibSign|Value); |
mbed_official | 354:e67efb2aab0e | 1905 | |
mbed_official | 354:e67efb2aab0e | 1906 | /* Exit Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 1907 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
mbed_official | 354:e67efb2aab0e | 1908 | } |
mbed_official | 354:e67efb2aab0e | 1909 | |
mbed_official | 354:e67efb2aab0e | 1910 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1911 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1912 | |
mbed_official | 354:e67efb2aab0e | 1913 | /* Change state */ |
mbed_official | 354:e67efb2aab0e | 1914 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1915 | |
mbed_official | 354:e67efb2aab0e | 1916 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1917 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1918 | |
mbed_official | 354:e67efb2aab0e | 1919 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1920 | } |
mbed_official | 354:e67efb2aab0e | 1921 | |
mbed_official | 354:e67efb2aab0e | 1922 | /** |
mbed_official | 354:e67efb2aab0e | 1923 | * @brief Deactivates the Coarse calibration parameters. |
mbed_official | 354:e67efb2aab0e | 1924 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1925 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1926 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1927 | */ |
mbed_official | 354:e67efb2aab0e | 1928 | HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 1929 | { |
mbed_official | 354:e67efb2aab0e | 1930 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 1931 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1932 | |
mbed_official | 354:e67efb2aab0e | 1933 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 1934 | |
mbed_official | 354:e67efb2aab0e | 1935 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1936 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1937 | |
mbed_official | 354:e67efb2aab0e | 1938 | /* Set Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 1939 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 354:e67efb2aab0e | 1940 | { |
mbed_official | 354:e67efb2aab0e | 1941 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1942 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1943 | |
mbed_official | 354:e67efb2aab0e | 1944 | /* Set RTC state*/ |
mbed_official | 354:e67efb2aab0e | 1945 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 1946 | |
mbed_official | 354:e67efb2aab0e | 1947 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1948 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1949 | |
mbed_official | 354:e67efb2aab0e | 1950 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 1951 | } |
mbed_official | 354:e67efb2aab0e | 1952 | else |
mbed_official | 354:e67efb2aab0e | 1953 | { |
mbed_official | 354:e67efb2aab0e | 1954 | /* Enable the Coarse Calibration */ |
mbed_official | 354:e67efb2aab0e | 1955 | __HAL_RTC_COARSE_CALIB_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1956 | |
mbed_official | 354:e67efb2aab0e | 1957 | /* Exit Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 1958 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
mbed_official | 354:e67efb2aab0e | 1959 | } |
mbed_official | 354:e67efb2aab0e | 1960 | |
mbed_official | 354:e67efb2aab0e | 1961 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 1962 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 1963 | |
mbed_official | 354:e67efb2aab0e | 1964 | /* Change state */ |
mbed_official | 354:e67efb2aab0e | 1965 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 1966 | |
mbed_official | 354:e67efb2aab0e | 1967 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 1968 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 1969 | |
mbed_official | 354:e67efb2aab0e | 1970 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 1971 | } |
mbed_official | 354:e67efb2aab0e | 1972 | |
mbed_official | 354:e67efb2aab0e | 1973 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 1974 | /** |
mbed_official | 354:e67efb2aab0e | 1975 | * @brief Sets the Smooth calibration parameters. |
mbed_official | 354:e67efb2aab0e | 1976 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 1977 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 1978 | * @param SmoothCalibPeriod: Select the Smooth Calibration Period. |
mbed_official | 354:e67efb2aab0e | 1979 | * This parameter can be can be one of the following values : |
mbed_official | 354:e67efb2aab0e | 1980 | * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration periode is 32s. |
mbed_official | 354:e67efb2aab0e | 1981 | * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration periode is 16s. |
mbed_official | 354:e67efb2aab0e | 1982 | * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibartion periode is 8s. |
mbed_official | 354:e67efb2aab0e | 1983 | * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit. |
mbed_official | 354:e67efb2aab0e | 1984 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 1985 | * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK puls every 2*11 pulses. |
mbed_official | 354:e67efb2aab0e | 1986 | * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added. |
mbed_official | 354:e67efb2aab0e | 1987 | * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits. |
mbed_official | 354:e67efb2aab0e | 1988 | * This parameter can be one any value from 0 to 0x000001FF. |
mbed_official | 354:e67efb2aab0e | 1989 | * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses |
mbed_official | 354:e67efb2aab0e | 1990 | * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field |
mbed_official | 354:e67efb2aab0e | 1991 | * SmouthCalibMinusPulsesValue must be equal to 0. |
mbed_official | 354:e67efb2aab0e | 1992 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 1993 | */ |
mbed_official | 354:e67efb2aab0e | 1994 | HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue) |
mbed_official | 354:e67efb2aab0e | 1995 | { |
mbed_official | 354:e67efb2aab0e | 1996 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 1997 | |
mbed_official | 354:e67efb2aab0e | 1998 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 1999 | assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod)); |
mbed_official | 354:e67efb2aab0e | 2000 | assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses)); |
mbed_official | 354:e67efb2aab0e | 2001 | assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue)); |
mbed_official | 354:e67efb2aab0e | 2002 | |
mbed_official | 354:e67efb2aab0e | 2003 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2004 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2005 | |
mbed_official | 354:e67efb2aab0e | 2006 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2007 | |
mbed_official | 354:e67efb2aab0e | 2008 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2009 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2010 | |
mbed_official | 354:e67efb2aab0e | 2011 | /* check if a calibration is pending*/ |
mbed_official | 354:e67efb2aab0e | 2012 | if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) |
mbed_official | 354:e67efb2aab0e | 2013 | { |
mbed_official | 354:e67efb2aab0e | 2014 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 2015 | |
mbed_official | 354:e67efb2aab0e | 2016 | /* check if a calibration is pending*/ |
mbed_official | 354:e67efb2aab0e | 2017 | while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) |
mbed_official | 354:e67efb2aab0e | 2018 | { |
mbed_official | 354:e67efb2aab0e | 2019 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 2020 | { |
mbed_official | 354:e67efb2aab0e | 2021 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2022 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2023 | |
mbed_official | 354:e67efb2aab0e | 2024 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2025 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 2026 | |
mbed_official | 354:e67efb2aab0e | 2027 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2028 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2029 | |
mbed_official | 354:e67efb2aab0e | 2030 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 2031 | } |
mbed_official | 354:e67efb2aab0e | 2032 | } |
mbed_official | 354:e67efb2aab0e | 2033 | } |
mbed_official | 354:e67efb2aab0e | 2034 | |
mbed_official | 354:e67efb2aab0e | 2035 | /* Configure the Smooth calibration settings */ |
mbed_official | 354:e67efb2aab0e | 2036 | hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue); |
mbed_official | 354:e67efb2aab0e | 2037 | |
mbed_official | 354:e67efb2aab0e | 2038 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2039 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2040 | |
mbed_official | 354:e67efb2aab0e | 2041 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2042 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2043 | |
mbed_official | 354:e67efb2aab0e | 2044 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2045 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2046 | |
mbed_official | 354:e67efb2aab0e | 2047 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2048 | } |
mbed_official | 354:e67efb2aab0e | 2049 | |
mbed_official | 354:e67efb2aab0e | 2050 | /** |
mbed_official | 354:e67efb2aab0e | 2051 | * @brief Configures the Synchronization Shift Control Settings. |
mbed_official | 354:e67efb2aab0e | 2052 | * @note When REFCKON is set, firmware must not write to Shift control register. |
mbed_official | 354:e67efb2aab0e | 2053 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2054 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2055 | * @param ShiftAdd1S: Select to add or not 1 second to the time calendar. |
mbed_official | 354:e67efb2aab0e | 2056 | * This parameter can be one of the following values : |
mbed_official | 354:e67efb2aab0e | 2057 | * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar. |
mbed_official | 354:e67efb2aab0e | 2058 | * @arg RTC_SHIFTADD1S_RESET: No effect. |
mbed_official | 354:e67efb2aab0e | 2059 | * @param ShiftSubFS: Select the number of Second Fractions to substitute. |
mbed_official | 354:e67efb2aab0e | 2060 | * This parameter can be one any value from 0 to 0x7FFF. |
mbed_official | 354:e67efb2aab0e | 2061 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2062 | */ |
mbed_official | 354:e67efb2aab0e | 2063 | HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS) |
mbed_official | 354:e67efb2aab0e | 2064 | { |
mbed_official | 354:e67efb2aab0e | 2065 | uint32_t tickstart = 0; |
mbed_official | 354:e67efb2aab0e | 2066 | |
mbed_official | 354:e67efb2aab0e | 2067 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 2068 | assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S)); |
mbed_official | 354:e67efb2aab0e | 2069 | assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS)); |
mbed_official | 354:e67efb2aab0e | 2070 | |
mbed_official | 354:e67efb2aab0e | 2071 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2072 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2073 | |
mbed_official | 354:e67efb2aab0e | 2074 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2075 | |
mbed_official | 354:e67efb2aab0e | 2076 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2077 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2078 | |
mbed_official | 354:e67efb2aab0e | 2079 | tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 2080 | |
mbed_official | 354:e67efb2aab0e | 2081 | /* Wait until the shift is completed*/ |
mbed_official | 354:e67efb2aab0e | 2082 | while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET) |
mbed_official | 354:e67efb2aab0e | 2083 | { |
mbed_official | 354:e67efb2aab0e | 2084 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
mbed_official | 354:e67efb2aab0e | 2085 | { |
mbed_official | 354:e67efb2aab0e | 2086 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2087 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2088 | |
mbed_official | 354:e67efb2aab0e | 2089 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 2090 | |
mbed_official | 354:e67efb2aab0e | 2091 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2092 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2093 | |
mbed_official | 354:e67efb2aab0e | 2094 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 2095 | } |
mbed_official | 354:e67efb2aab0e | 2096 | } |
mbed_official | 354:e67efb2aab0e | 2097 | |
mbed_official | 354:e67efb2aab0e | 2098 | /* Check if the reference clock detection is disabled */ |
mbed_official | 354:e67efb2aab0e | 2099 | if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET) |
mbed_official | 354:e67efb2aab0e | 2100 | { |
mbed_official | 354:e67efb2aab0e | 2101 | /* Configure the Shift settings */ |
mbed_official | 354:e67efb2aab0e | 2102 | hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S); |
mbed_official | 354:e67efb2aab0e | 2103 | |
mbed_official | 354:e67efb2aab0e | 2104 | /* Wait for synchro */ |
mbed_official | 354:e67efb2aab0e | 2105 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
mbed_official | 354:e67efb2aab0e | 2106 | { |
mbed_official | 354:e67efb2aab0e | 2107 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2108 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2109 | |
mbed_official | 354:e67efb2aab0e | 2110 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 2111 | |
mbed_official | 354:e67efb2aab0e | 2112 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2113 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2114 | |
mbed_official | 354:e67efb2aab0e | 2115 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 2116 | } |
mbed_official | 354:e67efb2aab0e | 2117 | } |
mbed_official | 354:e67efb2aab0e | 2118 | else |
mbed_official | 354:e67efb2aab0e | 2119 | { |
mbed_official | 354:e67efb2aab0e | 2120 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2121 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2122 | |
mbed_official | 354:e67efb2aab0e | 2123 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2124 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 2125 | |
mbed_official | 354:e67efb2aab0e | 2126 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2127 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2128 | |
mbed_official | 354:e67efb2aab0e | 2129 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 2130 | } |
mbed_official | 354:e67efb2aab0e | 2131 | |
mbed_official | 354:e67efb2aab0e | 2132 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2133 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2134 | |
mbed_official | 354:e67efb2aab0e | 2135 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2136 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2137 | |
mbed_official | 354:e67efb2aab0e | 2138 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2139 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2140 | |
mbed_official | 354:e67efb2aab0e | 2141 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2142 | } |
mbed_official | 354:e67efb2aab0e | 2143 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 2144 | |
mbed_official | 354:e67efb2aab0e | 2145 | |
mbed_official | 354:e67efb2aab0e | 2146 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 2147 | /** |
mbed_official | 354:e67efb2aab0e | 2148 | * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
mbed_official | 354:e67efb2aab0e | 2149 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2150 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2151 | * @param CalibOutput : Select the Calibration output Selection . |
mbed_official | 354:e67efb2aab0e | 2152 | * This parameter can be one of the following values: |
mbed_official | 354:e67efb2aab0e | 2153 | * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz. |
mbed_official | 354:e67efb2aab0e | 2154 | * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz. |
mbed_official | 354:e67efb2aab0e | 2155 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2156 | */ |
mbed_official | 354:e67efb2aab0e | 2157 | HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput) |
mbed_official | 354:e67efb2aab0e | 2158 | #else |
mbed_official | 354:e67efb2aab0e | 2159 | /** |
mbed_official | 354:e67efb2aab0e | 2160 | * @brief Configure the Calibration Pinout (RTC_CALIB). |
mbed_official | 354:e67efb2aab0e | 2161 | * @param hrtc : RTC handle |
mbed_official | 354:e67efb2aab0e | 2162 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2163 | */ |
mbed_official | 354:e67efb2aab0e | 2164 | HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 2165 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 2166 | { |
mbed_official | 354:e67efb2aab0e | 2167 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 2168 | /* Check the parameters */ |
mbed_official | 354:e67efb2aab0e | 2169 | assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput)); |
mbed_official | 354:e67efb2aab0e | 2170 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 2171 | |
mbed_official | 354:e67efb2aab0e | 2172 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2173 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2174 | |
mbed_official | 354:e67efb2aab0e | 2175 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2176 | |
mbed_official | 354:e67efb2aab0e | 2177 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2178 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2179 | |
mbed_official | 354:e67efb2aab0e | 2180 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 2181 | /* Clear flags before config */ |
mbed_official | 354:e67efb2aab0e | 2182 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL; |
mbed_official | 354:e67efb2aab0e | 2183 | |
mbed_official | 354:e67efb2aab0e | 2184 | /* Configure the RTC_CR register */ |
mbed_official | 354:e67efb2aab0e | 2185 | hrtc->Instance->CR |= (uint32_t)CalibOutput; |
mbed_official | 354:e67efb2aab0e | 2186 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 2187 | |
mbed_official | 354:e67efb2aab0e | 2188 | __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2189 | |
mbed_official | 354:e67efb2aab0e | 2190 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2191 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2192 | |
mbed_official | 354:e67efb2aab0e | 2193 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2194 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2195 | |
mbed_official | 354:e67efb2aab0e | 2196 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2197 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2198 | |
mbed_official | 354:e67efb2aab0e | 2199 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2200 | } |
mbed_official | 354:e67efb2aab0e | 2201 | |
mbed_official | 354:e67efb2aab0e | 2202 | /** |
mbed_official | 354:e67efb2aab0e | 2203 | * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
mbed_official | 354:e67efb2aab0e | 2204 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2205 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2206 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2207 | */ |
mbed_official | 354:e67efb2aab0e | 2208 | HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 2209 | { |
mbed_official | 354:e67efb2aab0e | 2210 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2211 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2212 | |
mbed_official | 354:e67efb2aab0e | 2213 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2214 | |
mbed_official | 354:e67efb2aab0e | 2215 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2216 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2217 | |
mbed_official | 354:e67efb2aab0e | 2218 | __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2219 | |
mbed_official | 354:e67efb2aab0e | 2220 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2221 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2222 | |
mbed_official | 354:e67efb2aab0e | 2223 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2224 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2225 | |
mbed_official | 354:e67efb2aab0e | 2226 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2227 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2228 | |
mbed_official | 354:e67efb2aab0e | 2229 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2230 | } |
mbed_official | 354:e67efb2aab0e | 2231 | |
mbed_official | 354:e67efb2aab0e | 2232 | /** |
mbed_official | 354:e67efb2aab0e | 2233 | * @brief Enables the RTC reference clock detection. |
mbed_official | 354:e67efb2aab0e | 2234 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2235 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2236 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2237 | */ |
mbed_official | 354:e67efb2aab0e | 2238 | HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 2239 | { |
mbed_official | 354:e67efb2aab0e | 2240 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2241 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2242 | |
mbed_official | 354:e67efb2aab0e | 2243 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2244 | |
mbed_official | 354:e67efb2aab0e | 2245 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2246 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2247 | |
mbed_official | 354:e67efb2aab0e | 2248 | /* Set Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 2249 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 354:e67efb2aab0e | 2250 | { |
mbed_official | 354:e67efb2aab0e | 2251 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2252 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2253 | |
mbed_official | 354:e67efb2aab0e | 2254 | /* Set RTC state*/ |
mbed_official | 354:e67efb2aab0e | 2255 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 2256 | |
mbed_official | 354:e67efb2aab0e | 2257 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2258 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2259 | |
mbed_official | 354:e67efb2aab0e | 2260 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 2261 | } |
mbed_official | 354:e67efb2aab0e | 2262 | else |
mbed_official | 354:e67efb2aab0e | 2263 | { |
mbed_official | 354:e67efb2aab0e | 2264 | __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2265 | |
mbed_official | 354:e67efb2aab0e | 2266 | /* Exit Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 2267 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
mbed_official | 354:e67efb2aab0e | 2268 | } |
mbed_official | 354:e67efb2aab0e | 2269 | |
mbed_official | 354:e67efb2aab0e | 2270 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2271 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2272 | |
mbed_official | 354:e67efb2aab0e | 2273 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2274 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2275 | |
mbed_official | 354:e67efb2aab0e | 2276 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2277 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2278 | |
mbed_official | 354:e67efb2aab0e | 2279 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2280 | } |
mbed_official | 354:e67efb2aab0e | 2281 | |
mbed_official | 354:e67efb2aab0e | 2282 | /** |
mbed_official | 354:e67efb2aab0e | 2283 | * @brief Disable the RTC reference clock detection. |
mbed_official | 354:e67efb2aab0e | 2284 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2285 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2286 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2287 | */ |
mbed_official | 354:e67efb2aab0e | 2288 | HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 2289 | { |
mbed_official | 354:e67efb2aab0e | 2290 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2291 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2292 | |
mbed_official | 354:e67efb2aab0e | 2293 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2294 | |
mbed_official | 354:e67efb2aab0e | 2295 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2296 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2297 | |
mbed_official | 354:e67efb2aab0e | 2298 | /* Set Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 2299 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 354:e67efb2aab0e | 2300 | { |
mbed_official | 354:e67efb2aab0e | 2301 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2302 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2303 | |
mbed_official | 354:e67efb2aab0e | 2304 | /* Set RTC state*/ |
mbed_official | 354:e67efb2aab0e | 2305 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 354:e67efb2aab0e | 2306 | |
mbed_official | 354:e67efb2aab0e | 2307 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2308 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2309 | |
mbed_official | 354:e67efb2aab0e | 2310 | return HAL_ERROR; |
mbed_official | 354:e67efb2aab0e | 2311 | } |
mbed_official | 354:e67efb2aab0e | 2312 | else |
mbed_official | 354:e67efb2aab0e | 2313 | { |
mbed_official | 354:e67efb2aab0e | 2314 | __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2315 | |
mbed_official | 354:e67efb2aab0e | 2316 | /* Exit Initialization mode */ |
mbed_official | 354:e67efb2aab0e | 2317 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
mbed_official | 354:e67efb2aab0e | 2318 | } |
mbed_official | 354:e67efb2aab0e | 2319 | |
mbed_official | 354:e67efb2aab0e | 2320 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2321 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2322 | |
mbed_official | 354:e67efb2aab0e | 2323 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2324 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2325 | |
mbed_official | 354:e67efb2aab0e | 2326 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2327 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2328 | |
mbed_official | 354:e67efb2aab0e | 2329 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2330 | } |
mbed_official | 354:e67efb2aab0e | 2331 | |
mbed_official | 354:e67efb2aab0e | 2332 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE) |
mbed_official | 354:e67efb2aab0e | 2333 | /** |
mbed_official | 354:e67efb2aab0e | 2334 | * @brief Enables the Bypass Shadow feature. |
mbed_official | 354:e67efb2aab0e | 2335 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2336 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2337 | * @note When the Bypass Shadow is enabled the calendar value are taken |
mbed_official | 354:e67efb2aab0e | 2338 | * directly from the Calendar counter. |
mbed_official | 354:e67efb2aab0e | 2339 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2340 | */ |
mbed_official | 354:e67efb2aab0e | 2341 | HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 2342 | { |
mbed_official | 354:e67efb2aab0e | 2343 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2344 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2345 | |
mbed_official | 354:e67efb2aab0e | 2346 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2347 | |
mbed_official | 354:e67efb2aab0e | 2348 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2349 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2350 | |
mbed_official | 354:e67efb2aab0e | 2351 | /* Set the BYPSHAD bit */ |
mbed_official | 354:e67efb2aab0e | 2352 | hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD; |
mbed_official | 354:e67efb2aab0e | 2353 | |
mbed_official | 354:e67efb2aab0e | 2354 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2355 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2356 | |
mbed_official | 354:e67efb2aab0e | 2357 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2358 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2359 | |
mbed_official | 354:e67efb2aab0e | 2360 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2361 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2362 | |
mbed_official | 354:e67efb2aab0e | 2363 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2364 | } |
mbed_official | 354:e67efb2aab0e | 2365 | |
mbed_official | 354:e67efb2aab0e | 2366 | /** |
mbed_official | 354:e67efb2aab0e | 2367 | * @brief Disables the Bypass Shadow feature. |
mbed_official | 354:e67efb2aab0e | 2368 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2369 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2370 | * @note When the Bypass Shadow is enabled the calendar value are taken |
mbed_official | 354:e67efb2aab0e | 2371 | * directly from the Calendar counter. |
mbed_official | 354:e67efb2aab0e | 2372 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2373 | */ |
mbed_official | 354:e67efb2aab0e | 2374 | HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc) |
mbed_official | 354:e67efb2aab0e | 2375 | { |
mbed_official | 354:e67efb2aab0e | 2376 | /* Process Locked */ |
mbed_official | 354:e67efb2aab0e | 2377 | __HAL_LOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2378 | |
mbed_official | 354:e67efb2aab0e | 2379 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 354:e67efb2aab0e | 2380 | |
mbed_official | 354:e67efb2aab0e | 2381 | /* Disable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2382 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2383 | |
mbed_official | 354:e67efb2aab0e | 2384 | /* Reset the BYPSHAD bit */ |
mbed_official | 354:e67efb2aab0e | 2385 | hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD; |
mbed_official | 354:e67efb2aab0e | 2386 | |
mbed_official | 354:e67efb2aab0e | 2387 | /* Enable the write protection for RTC registers */ |
mbed_official | 354:e67efb2aab0e | 2388 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 354:e67efb2aab0e | 2389 | |
mbed_official | 354:e67efb2aab0e | 2390 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2391 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2392 | |
mbed_official | 354:e67efb2aab0e | 2393 | /* Process Unlocked */ |
mbed_official | 354:e67efb2aab0e | 2394 | __HAL_UNLOCK(hrtc); |
mbed_official | 354:e67efb2aab0e | 2395 | |
mbed_official | 354:e67efb2aab0e | 2396 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2397 | } |
mbed_official | 354:e67efb2aab0e | 2398 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ |
mbed_official | 354:e67efb2aab0e | 2399 | |
mbed_official | 354:e67efb2aab0e | 2400 | /** |
mbed_official | 354:e67efb2aab0e | 2401 | * @} |
mbed_official | 354:e67efb2aab0e | 2402 | */ |
mbed_official | 354:e67efb2aab0e | 2403 | |
mbed_official | 354:e67efb2aab0e | 2404 | /** @defgroup RTCEx_Exported_Functions_Group8 Extended features functions |
mbed_official | 354:e67efb2aab0e | 2405 | * @brief Extended features functions |
mbed_official | 354:e67efb2aab0e | 2406 | * |
mbed_official | 354:e67efb2aab0e | 2407 | @verbatim |
mbed_official | 354:e67efb2aab0e | 2408 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 2409 | ##### Extended features functions ##### |
mbed_official | 354:e67efb2aab0e | 2410 | =============================================================================== |
mbed_official | 354:e67efb2aab0e | 2411 | [..] This section provides functions allowing to: |
mbed_official | 354:e67efb2aab0e | 2412 | (+) RTC Alram B callback |
mbed_official | 354:e67efb2aab0e | 2413 | (+) RTC Poll for Alarm B request |
mbed_official | 354:e67efb2aab0e | 2414 | |
mbed_official | 354:e67efb2aab0e | 2415 | @endverbatim |
mbed_official | 354:e67efb2aab0e | 2416 | * @{ |
mbed_official | 354:e67efb2aab0e | 2417 | */ |
mbed_official | 354:e67efb2aab0e | 2418 | |
mbed_official | 354:e67efb2aab0e | 2419 | /** |
mbed_official | 354:e67efb2aab0e | 2420 | * @brief Alarm B callback. |
mbed_official | 354:e67efb2aab0e | 2421 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2422 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2423 | * @retval None |
mbed_official | 354:e67efb2aab0e | 2424 | */ |
mbed_official | 354:e67efb2aab0e | 2425 | __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) |
mbed_official | 354:e67efb2aab0e | 2426 | { |
mbed_official | 354:e67efb2aab0e | 2427 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 354:e67efb2aab0e | 2428 | the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file |
mbed_official | 354:e67efb2aab0e | 2429 | */ |
mbed_official | 354:e67efb2aab0e | 2430 | } |
mbed_official | 354:e67efb2aab0e | 2431 | |
mbed_official | 354:e67efb2aab0e | 2432 | /** |
mbed_official | 354:e67efb2aab0e | 2433 | * @brief This function handles AlarmB Polling request. |
mbed_official | 354:e67efb2aab0e | 2434 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
mbed_official | 354:e67efb2aab0e | 2435 | * the configuration information for RTC. |
mbed_official | 354:e67efb2aab0e | 2436 | * @param Timeout: Timeout duration |
mbed_official | 354:e67efb2aab0e | 2437 | * @retval HAL status |
mbed_official | 354:e67efb2aab0e | 2438 | */ |
mbed_official | 354:e67efb2aab0e | 2439 | HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
mbed_official | 354:e67efb2aab0e | 2440 | { |
mbed_official | 354:e67efb2aab0e | 2441 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 354:e67efb2aab0e | 2442 | |
mbed_official | 354:e67efb2aab0e | 2443 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET) |
mbed_official | 354:e67efb2aab0e | 2444 | { |
mbed_official | 354:e67efb2aab0e | 2445 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 354:e67efb2aab0e | 2446 | { |
mbed_official | 354:e67efb2aab0e | 2447 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 354:e67efb2aab0e | 2448 | { |
mbed_official | 354:e67efb2aab0e | 2449 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 2450 | return HAL_TIMEOUT; |
mbed_official | 354:e67efb2aab0e | 2451 | } |
mbed_official | 354:e67efb2aab0e | 2452 | } |
mbed_official | 354:e67efb2aab0e | 2453 | } |
mbed_official | 354:e67efb2aab0e | 2454 | |
mbed_official | 354:e67efb2aab0e | 2455 | /* Clear the Alarm Flag */ |
mbed_official | 354:e67efb2aab0e | 2456 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
mbed_official | 354:e67efb2aab0e | 2457 | |
mbed_official | 354:e67efb2aab0e | 2458 | /* Change RTC state */ |
mbed_official | 354:e67efb2aab0e | 2459 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 354:e67efb2aab0e | 2460 | |
mbed_official | 354:e67efb2aab0e | 2461 | return HAL_OK; |
mbed_official | 354:e67efb2aab0e | 2462 | } |
mbed_official | 354:e67efb2aab0e | 2463 | |
mbed_official | 354:e67efb2aab0e | 2464 | /** |
mbed_official | 354:e67efb2aab0e | 2465 | * @} |
mbed_official | 354:e67efb2aab0e | 2466 | */ |
mbed_official | 354:e67efb2aab0e | 2467 | |
mbed_official | 354:e67efb2aab0e | 2468 | /** |
mbed_official | 354:e67efb2aab0e | 2469 | * @} |
mbed_official | 354:e67efb2aab0e | 2470 | */ |
mbed_official | 354:e67efb2aab0e | 2471 | |
mbed_official | 354:e67efb2aab0e | 2472 | /** |
mbed_official | 354:e67efb2aab0e | 2473 | * @} |
mbed_official | 354:e67efb2aab0e | 2474 | */ |
mbed_official | 354:e67efb2aab0e | 2475 | |
mbed_official | 354:e67efb2aab0e | 2476 | #endif /* HAL_RTC_MODULE_ENABLED */ |
mbed_official | 354:e67efb2aab0e | 2477 | |
mbed_official | 354:e67efb2aab0e | 2478 | /** |
mbed_official | 354:e67efb2aab0e | 2479 | * @} |
mbed_official | 354:e67efb2aab0e | 2480 | */ |
mbed_official | 354:e67efb2aab0e | 2481 | |
mbed_official | 354:e67efb2aab0e | 2482 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |