No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

1785 líneas
55 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_rtc_ex.c
  4. * @author MCD Application Team
  5. * @brief RTC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Real Time Clock (RTC) Extension peripheral:
  8. * + RTC Time Stamp functions
  9. * + RTC Tamper functions
  10. * + RTC Wake-up functions
  11. * + Extension Control functions
  12. * + Extension RTC features functions
  13. *
  14. @verbatim
  15. ==============================================================================
  16. ##### How to use this driver #####
  17. ==============================================================================
  18. [..]
  19. (+) Enable the RTC domain access.
  20. (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
  21. format using the HAL_RTC_Init() function.
  22. *** RTC Wake-up configuration ***
  23. ================================
  24. [..]
  25. (+) To configure the RTC Wake-up Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer()
  26. function. You can also configure the RTC Wake-up timer in interrupt mode
  27. using the HAL_RTCEx_SetWakeUpTimer_IT() function.
  28. (+) To read the RTC Wake-up Counter register, use the HAL_RTCEx_GetWakeUpTimer()
  29. function.
  30. *** TimeStamp configuration ***
  31. ===============================
  32. [..]
  33. (+) Configure the RTC_AFx trigger and enable the RTC TimeStamp using the
  34. HAL_RTCEx_SetTimeStamp() function. You can also configure the RTC TimeStamp with
  35. interrupt mode using the HAL_RTCEx_SetTimeStamp_IT() function.
  36. (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp()
  37. function.
  38. (+) The TIMESTAMP alternate function can be mapped either to RTC_AF1 (PC13)
  39. or RTC_AF2 (PI8 or PA0 only for STM32F446xx devices) depending on the value of TSINSEL bit in
  40. RTC_TAFCR register. The corresponding pin is also selected by HAL_RTCEx_SetTimeStamp()
  41. or HAL_RTCEx_SetTimeStamp_IT() function.
  42. *** Tamper configuration ***
  43. ============================
  44. [..]
  45. (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge
  46. or Level according to the Tamper filter (if equal to 0 Edge else Level)
  47. value, sampling frequency, precharge or discharge and Pull-UP using the
  48. HAL_RTCEx_SetTamper() function. You can configure RTC Tamper in interrupt
  49. mode using HAL_RTCEx_SetTamper_IT() function.
  50. (+) The TAMPER1 alternate function can be mapped either to RTC_AF1 (PC13)
  51. or RTC_AF2 (PI8 or PA0 only for STM32F446xx devices) depending on the value of TAMP1INSEL bit in
  52. RTC_TAFCR register. The corresponding pin is also selected by HAL_RTCEx_SetTamper()
  53. or HAL_RTCEx_SetTamper_IT() function.
  54. *** Backup Data Registers configuration ***
  55. ===========================================
  56. [..]
  57. (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite()
  58. function.
  59. (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead()
  60. function.
  61. @endverbatim
  62. ******************************************************************************
  63. * @attention
  64. *
  65. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  66. * All rights reserved.</center></h2>
  67. *
  68. * This software component is licensed by ST under BSD 3-Clause license,
  69. * the "License"; You may not use this file except in compliance with the
  70. * License. You may obtain a copy of the License at:
  71. * opensource.org/licenses/BSD-3-Clause
  72. *
  73. ******************************************************************************
  74. */
  75. /* Includes ------------------------------------------------------------------*/
  76. #include "stm32f4xx_hal.h"
  77. /** @addtogroup STM32F4xx_HAL_Driver
  78. * @{
  79. */
  80. /** @defgroup RTCEx RTCEx
  81. * @brief RTC HAL module driver
  82. * @{
  83. */
  84. #ifdef HAL_RTC_MODULE_ENABLED
  85. /* Private typedef -----------------------------------------------------------*/
  86. /* Private define ------------------------------------------------------------*/
  87. /* Private macro -------------------------------------------------------------*/
  88. /* Private variables ---------------------------------------------------------*/
  89. /* Private function prototypes -----------------------------------------------*/
  90. /* Private functions ---------------------------------------------------------*/
  91. /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
  92. * @{
  93. */
  94. /** @defgroup RTCEx_Exported_Functions_Group1 RTC TimeStamp and Tamper functions
  95. * @brief RTC TimeStamp and Tamper functions
  96. *
  97. @verbatim
  98. ===============================================================================
  99. ##### RTC TimeStamp and Tamper functions #####
  100. ===============================================================================
  101. [..] This section provides functions allowing to configure TimeStamp feature
  102. @endverbatim
  103. * @{
  104. */
  105. /**
  106. * @brief Sets TimeStamp.
  107. * @note This API must be called before enabling the TimeStamp feature.
  108. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  109. * the configuration information for RTC.
  110. * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is
  111. * activated.
  112. * This parameter can be one of the following values:
  113. * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
  114. * rising edge of the related pin.
  115. * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
  116. * falling edge of the related pin.
  117. * @param RTC_TimeStampPin specifies the RTC TimeStamp Pin.
  118. * This parameter can be one of the following values:
  119. * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin.
  120. * @arg RTC_TIMESTAMPPIN_POS1: PI8/PA0 is selected as RTC TimeStamp Pin.
  121. * (not applicable in the case of STM32F412xx, STM32F413xx and STM32F423xx devices)
  122. * (PI8 for all STM32 devices except for STM32F446xx devices the PA0 is used)
  123. * @arg RTC_TIMESTAMPPIN_PA0: PA0 is selected as RTC TimeStamp Pin only for STM32F446xx devices
  124. * @retval HAL status
  125. */
  126. HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
  127. {
  128. uint32_t tmpreg = 0U;
  129. /* Check the parameters */
  130. assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
  131. assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
  132. /* Process Locked */
  133. __HAL_LOCK(hrtc);
  134. hrtc->State = HAL_RTC_STATE_BUSY;
  135. /* Get the RTC_CR register and clear the bits to be configured */
  136. tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
  137. tmpreg|= TimeStampEdge;
  138. /* Disable the write protection for RTC registers */
  139. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  140. hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL;
  141. hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin);
  142. /* Configure the Time Stamp TSEDGE and Enable bits */
  143. hrtc->Instance->CR = (uint32_t)tmpreg;
  144. __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
  145. /* Enable the write protection for RTC registers */
  146. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  147. /* Change RTC state */
  148. hrtc->State = HAL_RTC_STATE_READY;
  149. /* Process Unlocked */
  150. __HAL_UNLOCK(hrtc);
  151. return HAL_OK;
  152. }
  153. /**
  154. * @brief Sets TimeStamp with Interrupt.
  155. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  156. * the configuration information for RTC.
  157. * @note This API must be called before enabling the TimeStamp feature.
  158. * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is
  159. * activated.
  160. * This parameter can be one of the following values:
  161. * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
  162. * rising edge of the related pin.
  163. * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
  164. * falling edge of the related pin.
  165. * @param RTC_TimeStampPin Specifies the RTC TimeStamp Pin.
  166. * This parameter can be one of the following values:
  167. * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin.
  168. * @arg RTC_TIMESTAMPPIN_PI8: PI8 is selected as RTC TimeStamp Pin. (not applicable in the case of STM32F446xx, STM32F412xx, STM32F413xx and STM32F423xx devices)
  169. * @arg RTC_TIMESTAMPPIN_PA0: PA0 is selected as RTC TimeStamp Pin only for STM32F446xx devices
  170. * @retval HAL status
  171. */
  172. HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
  173. {
  174. uint32_t tmpreg = 0U;
  175. /* Check the parameters */
  176. assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
  177. assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
  178. /* Process Locked */
  179. __HAL_LOCK(hrtc);
  180. hrtc->State = HAL_RTC_STATE_BUSY;
  181. /* Get the RTC_CR register and clear the bits to be configured */
  182. tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
  183. tmpreg |= TimeStampEdge;
  184. /* Disable the write protection for RTC registers */
  185. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  186. /* Configure the Time Stamp TSEDGE and Enable bits */
  187. hrtc->Instance->CR = (uint32_t)tmpreg;
  188. hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_TSINSEL;
  189. hrtc->Instance->TAFCR |= (uint32_t)(RTC_TimeStampPin);
  190. /* Clear RTC Timestamp flag */
  191. __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
  192. __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
  193. /* Enable IT timestamp */
  194. __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS);
  195. /* RTC timestamp Interrupt Configuration: EXTI configuration */
  196. __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
  197. EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
  198. /* Enable the write protection for RTC registers */
  199. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  200. hrtc->State = HAL_RTC_STATE_READY;
  201. /* Process Unlocked */
  202. __HAL_UNLOCK(hrtc);
  203. return HAL_OK;
  204. }
  205. /**
  206. * @brief Deactivates TimeStamp.
  207. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  208. * the configuration information for RTC.
  209. * @retval HAL status
  210. */
  211. HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
  212. {
  213. uint32_t tmpreg = 0U;
  214. /* Process Locked */
  215. __HAL_LOCK(hrtc);
  216. hrtc->State = HAL_RTC_STATE_BUSY;
  217. /* Disable the write protection for RTC registers */
  218. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  219. /* In case of interrupt mode is used, the interrupt source must disabled */
  220. __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS);
  221. /* Get the RTC_CR register and clear the bits to be configured */
  222. tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
  223. /* Configure the Time Stamp TSEDGE and Enable bits */
  224. hrtc->Instance->CR = (uint32_t)tmpreg;
  225. /* Enable the write protection for RTC registers */
  226. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  227. hrtc->State = HAL_RTC_STATE_READY;
  228. /* Process Unlocked */
  229. __HAL_UNLOCK(hrtc);
  230. return HAL_OK;
  231. }
  232. /**
  233. * @brief Gets the RTC TimeStamp value.
  234. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  235. * the configuration information for RTC.
  236. * @param sTimeStamp Pointer to Time structure
  237. * @param sTimeStampDate Pointer to Date structure
  238. * @param Format specifies the format of the entered parameters.
  239. * This parameter can be one of the following values:
  240. * RTC_FORMAT_BIN: Binary data format
  241. * RTC_FORMAT_BCD: BCD data format
  242. * @retval HAL status
  243. */
  244. HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format)
  245. {
  246. uint32_t tmptime = 0U, tmpdate = 0U;
  247. /* Check the parameters */
  248. assert_param(IS_RTC_FORMAT(Format));
  249. /* Get the TimeStamp time and date registers values */
  250. tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
  251. tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
  252. /* Fill the Time structure fields with the read parameters */
  253. sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16U);
  254. sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8U);
  255. sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
  256. sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16U);
  257. sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR;
  258. /* Fill the Date structure fields with the read parameters */
  259. sTimeStampDate->Year = 0U;
  260. sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8U);
  261. sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
  262. sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13U);
  263. /* Check the input parameters format */
  264. if(Format == RTC_FORMAT_BIN)
  265. {
  266. /* Convert the TimeStamp structure parameters to Binary format */
  267. sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
  268. sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
  269. sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
  270. /* Convert the DateTimeStamp structure parameters to Binary format */
  271. sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
  272. sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
  273. sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
  274. }
  275. /* Clear the TIMESTAMP Flag */
  276. __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
  277. return HAL_OK;
  278. }
  279. /**
  280. * @brief Sets Tamper
  281. * @note By calling this API we disable the tamper interrupt for all tampers.
  282. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  283. * the configuration information for RTC.
  284. * @param sTamper Pointer to Tamper Structure.
  285. * @retval HAL status
  286. */
  287. HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
  288. {
  289. uint32_t tmpreg = 0U;
  290. /* Check the parameters */
  291. assert_param(IS_RTC_TAMPER(sTamper->Tamper));
  292. assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection));
  293. assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
  294. assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
  295. assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
  296. assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
  297. assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
  298. assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
  299. /* Process Locked */
  300. __HAL_LOCK(hrtc);
  301. hrtc->State = HAL_RTC_STATE_BUSY;
  302. if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
  303. {
  304. sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1U);
  305. }
  306. tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)sTamper->Trigger |\
  307. (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
  308. (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
  309. hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1U) | (uint32_t)RTC_TAFCR_TAMPTS |\
  310. (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
  311. (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPINSEL | (uint32_t)RTC_TAFCR_TAMPIE);
  312. hrtc->Instance->TAFCR |= tmpreg;
  313. hrtc->State = HAL_RTC_STATE_READY;
  314. /* Process Unlocked */
  315. __HAL_UNLOCK(hrtc);
  316. return HAL_OK;
  317. }
  318. /**
  319. * @brief Sets Tamper with interrupt.
  320. * @note By calling this API we force the tamper interrupt for all tampers.
  321. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  322. * the configuration information for RTC.
  323. * @param sTamper Pointer to RTC Tamper.
  324. * @retval HAL status
  325. */
  326. HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
  327. {
  328. uint32_t tmpreg = 0U;
  329. /* Check the parameters */
  330. assert_param(IS_RTC_TAMPER(sTamper->Tamper));
  331. assert_param(IS_RTC_TAMPER_PIN(sTamper->PinSelection));
  332. assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
  333. assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
  334. assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
  335. assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
  336. assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
  337. assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
  338. /* Process Locked */
  339. __HAL_LOCK(hrtc);
  340. hrtc->State = HAL_RTC_STATE_BUSY;
  341. /* Configure the tamper trigger */
  342. if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
  343. {
  344. sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1U);
  345. }
  346. tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->PinSelection | (uint32_t)sTamper->Trigger |\
  347. (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
  348. (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
  349. hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1U) | (uint32_t)RTC_TAFCR_TAMPTS |\
  350. (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
  351. (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPINSEL);
  352. hrtc->Instance->TAFCR |= tmpreg;
  353. /* Configure the Tamper Interrupt in the RTC_TAFCR */
  354. hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE;
  355. if(sTamper->Tamper == RTC_TAMPER_1)
  356. {
  357. /* Clear RTC Tamper 1 flag */
  358. __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F);
  359. }
  360. else
  361. {
  362. /* Clear RTC Tamper 2 flag */
  363. __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
  364. }
  365. /* RTC Tamper Interrupt Configuration: EXTI configuration */
  366. __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
  367. EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
  368. hrtc->State = HAL_RTC_STATE_READY;
  369. /* Process Unlocked */
  370. __HAL_UNLOCK(hrtc);
  371. return HAL_OK;
  372. }
  373. /**
  374. * @brief Deactivates Tamper.
  375. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  376. * the configuration information for RTC.
  377. * @param Tamper Selected tamper pin.
  378. * This parameter can be RTC_Tamper_1 and/or RTC_TAMPER_2.
  379. * @retval HAL status
  380. */
  381. HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
  382. {
  383. assert_param(IS_RTC_TAMPER(Tamper));
  384. /* Process Locked */
  385. __HAL_LOCK(hrtc);
  386. hrtc->State = HAL_RTC_STATE_BUSY;
  387. /* Disable the selected Tamper pin */
  388. hrtc->Instance->TAFCR &= (uint32_t)~Tamper;
  389. hrtc->State = HAL_RTC_STATE_READY;
  390. /* Process Unlocked */
  391. __HAL_UNLOCK(hrtc);
  392. return HAL_OK;
  393. }
  394. /**
  395. * @brief This function handles TimeStamp interrupt request.
  396. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  397. * the configuration information for RTC.
  398. * @retval None
  399. */
  400. void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
  401. {
  402. /* Get the TimeStamp interrupt source enable status */
  403. if(__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != (uint32_t)RESET)
  404. {
  405. /* Get the pending status of the TIMESTAMP Interrupt */
  406. if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != (uint32_t)RESET)
  407. {
  408. /* TIMESTAMP callback */
  409. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  410. hrtc->TimeStampEventCallback(hrtc);
  411. #else
  412. HAL_RTCEx_TimeStampEventCallback(hrtc);
  413. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  414. /* Clear the TIMESTAMP interrupt pending bit */
  415. __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF);
  416. }
  417. }
  418. /* Get the Tamper1 interrupt source enable status */
  419. if(__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP) != (uint32_t)RESET)
  420. {
  421. /* Get the pending status of the Tamper1 Interrupt */
  422. if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != (uint32_t)RESET)
  423. {
  424. /* Tamper callback */
  425. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  426. hrtc->Tamper1EventCallback(hrtc);
  427. #else
  428. HAL_RTCEx_Tamper1EventCallback(hrtc);
  429. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  430. /* Clear the Tamper interrupt pending bit */
  431. __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
  432. }
  433. }
  434. /* Get the Tamper2 interrupt source enable status */
  435. if(__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP) != (uint32_t)RESET)
  436. {
  437. /* Get the pending status of the Tamper2 Interrupt */
  438. if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != (uint32_t)RESET)
  439. {
  440. /* Tamper callback */
  441. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  442. hrtc->Tamper2EventCallback(hrtc);
  443. #else
  444. HAL_RTCEx_Tamper2EventCallback(hrtc);
  445. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  446. /* Clear the Tamper interrupt pending bit */
  447. __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
  448. }
  449. }
  450. /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
  451. __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
  452. /* Change RTC state */
  453. hrtc->State = HAL_RTC_STATE_READY;
  454. }
  455. /**
  456. * @brief TimeStamp callback.
  457. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  458. * the configuration information for RTC.
  459. * @retval None
  460. */
  461. __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
  462. {
  463. /* Prevent unused argument(s) compilation warning */
  464. UNUSED(hrtc);
  465. /* NOTE : This function Should not be modified, when the callback is needed,
  466. the HAL_RTC_TimeStampEventCallback could be implemented in the user file
  467. */
  468. }
  469. /**
  470. * @brief Tamper 1 callback.
  471. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  472. * the configuration information for RTC.
  473. * @retval None
  474. */
  475. __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
  476. {
  477. /* Prevent unused argument(s) compilation warning */
  478. UNUSED(hrtc);
  479. /* NOTE : This function Should not be modified, when the callback is needed,
  480. the HAL_RTC_Tamper1EventCallback could be implemented in the user file
  481. */
  482. }
  483. /**
  484. * @brief Tamper 2 callback.
  485. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  486. * the configuration information for RTC.
  487. * @retval None
  488. */
  489. __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
  490. {
  491. /* Prevent unused argument(s) compilation warning */
  492. UNUSED(hrtc);
  493. /* NOTE : This function Should not be modified, when the callback is needed,
  494. the HAL_RTC_Tamper2EventCallback could be implemented in the user file
  495. */
  496. }
  497. /**
  498. * @brief This function handles TimeStamp polling request.
  499. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  500. * the configuration information for RTC.
  501. * @param Timeout Timeout duration
  502. * @retval HAL status
  503. */
  504. HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
  505. {
  506. uint32_t tickstart = 0U;
  507. /* Get tick */
  508. tickstart = HAL_GetTick();
  509. while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET)
  510. {
  511. if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET)
  512. {
  513. /* Clear the TIMESTAMP Overrun Flag */
  514. __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
  515. /* Change TIMESTAMP state */
  516. hrtc->State = HAL_RTC_STATE_ERROR;
  517. return HAL_ERROR;
  518. }
  519. if(Timeout != HAL_MAX_DELAY)
  520. {
  521. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  522. {
  523. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  524. return HAL_TIMEOUT;
  525. }
  526. }
  527. }
  528. /* Change RTC state */
  529. hrtc->State = HAL_RTC_STATE_READY;
  530. return HAL_OK;
  531. }
  532. /**
  533. * @brief This function handles Tamper1 Polling.
  534. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  535. * the configuration information for RTC.
  536. * @param Timeout Timeout duration
  537. * @retval HAL status
  538. */
  539. HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
  540. {
  541. uint32_t tickstart = 0U;
  542. /* Get tick */
  543. tickstart = HAL_GetTick();
  544. /* Get the status of the Interrupt */
  545. while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F)== RESET)
  546. {
  547. if(Timeout != HAL_MAX_DELAY)
  548. {
  549. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  550. {
  551. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  552. return HAL_TIMEOUT;
  553. }
  554. }
  555. }
  556. /* Clear the Tamper Flag */
  557. __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
  558. /* Change RTC state */
  559. hrtc->State = HAL_RTC_STATE_READY;
  560. return HAL_OK;
  561. }
  562. /**
  563. * @brief This function handles Tamper2 Polling.
  564. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  565. * the configuration information for RTC.
  566. * @param Timeout Timeout duration
  567. * @retval HAL status
  568. */
  569. HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
  570. {
  571. uint32_t tickstart = 0U;
  572. /* Get tick */
  573. tickstart = HAL_GetTick();
  574. /* Get the status of the Interrupt */
  575. while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == RESET)
  576. {
  577. if(Timeout != HAL_MAX_DELAY)
  578. {
  579. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  580. {
  581. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  582. return HAL_TIMEOUT;
  583. }
  584. }
  585. }
  586. /* Clear the Tamper Flag */
  587. __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F);
  588. /* Change RTC state */
  589. hrtc->State = HAL_RTC_STATE_READY;
  590. return HAL_OK;
  591. }
  592. /**
  593. * @}
  594. */
  595. /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wake-up functions
  596. * @brief RTC Wake-up functions
  597. *
  598. @verbatim
  599. ===============================================================================
  600. ##### RTC Wake-up functions #####
  601. ===============================================================================
  602. [..] This section provides functions allowing to configure Wake-up feature
  603. @endverbatim
  604. * @{
  605. */
  606. /**
  607. * @brief Sets wake up timer.
  608. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  609. * the configuration information for RTC.
  610. * @param WakeUpCounter Wake up counter
  611. * @param WakeUpClock Wake up clock
  612. * @retval HAL status
  613. */
  614. HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
  615. {
  616. uint32_t tickstart = 0U;
  617. /* Check the parameters */
  618. assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
  619. assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
  620. /* Process Locked */
  621. __HAL_LOCK(hrtc);
  622. hrtc->State = HAL_RTC_STATE_BUSY;
  623. /* Disable the write protection for RTC registers */
  624. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  625. /*Check RTC WUTWF flag is reset only when wake up timer enabled*/
  626. if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET)
  627. {
  628. tickstart = HAL_GetTick();
  629. /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */
  630. while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET)
  631. {
  632. if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
  633. {
  634. /* Enable the write protection for RTC registers */
  635. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  636. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  637. /* Process Unlocked */
  638. __HAL_UNLOCK(hrtc);
  639. return HAL_TIMEOUT;
  640. }
  641. }
  642. }
  643. __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
  644. tickstart = HAL_GetTick();
  645. /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
  646. while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
  647. {
  648. if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
  649. {
  650. /* Enable the write protection for RTC registers */
  651. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  652. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  653. /* Process Unlocked */
  654. __HAL_UNLOCK(hrtc);
  655. return HAL_TIMEOUT;
  656. }
  657. }
  658. /* Clear the Wake-up Timer clock source bits in CR register */
  659. hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
  660. /* Configure the clock source */
  661. hrtc->Instance->CR |= (uint32_t)WakeUpClock;
  662. /* Configure the Wake-up Timer counter */
  663. hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
  664. /* Enable the Wake-up Timer */
  665. __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
  666. /* Enable the write protection for RTC registers */
  667. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  668. hrtc->State = HAL_RTC_STATE_READY;
  669. /* Process Unlocked */
  670. __HAL_UNLOCK(hrtc);
  671. return HAL_OK;
  672. }
  673. /**
  674. * @brief Sets wake up timer with interrupt
  675. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  676. * the configuration information for RTC.
  677. * @param WakeUpCounter Wake up counter
  678. * @param WakeUpClock Wake up clock
  679. * @retval HAL status
  680. */
  681. HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
  682. {
  683. __IO uint32_t count;
  684. /* Check the parameters */
  685. assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
  686. assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
  687. /* Process Locked */
  688. __HAL_LOCK(hrtc);
  689. hrtc->State = HAL_RTC_STATE_BUSY;
  690. /* Disable the write protection for RTC registers */
  691. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  692. /* Check RTC WUTWF flag is reset only when wake up timer enabled */
  693. if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET)
  694. {
  695. /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */
  696. count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U);
  697. do
  698. {
  699. if(count-- == 0U)
  700. {
  701. /* Enable the write protection for RTC registers */
  702. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  703. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  704. /* Process Unlocked */
  705. __HAL_UNLOCK(hrtc);
  706. return HAL_TIMEOUT;
  707. }
  708. }
  709. while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET);
  710. }
  711. __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
  712. /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
  713. count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U);
  714. do
  715. {
  716. if(count-- == 0U)
  717. {
  718. /* Enable the write protection for RTC registers */
  719. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  720. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  721. /* Process Unlocked */
  722. __HAL_UNLOCK(hrtc);
  723. return HAL_TIMEOUT;
  724. }
  725. }
  726. while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET);
  727. /* Configure the Wake-up Timer counter */
  728. hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
  729. /* Clear the Wake-up Timer clock source bits in CR register */
  730. hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
  731. /* Configure the clock source */
  732. hrtc->Instance->CR |= (uint32_t)WakeUpClock;
  733. /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
  734. __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
  735. EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
  736. /* Clear RTC Wake Up timer Flag */
  737. __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
  738. /* Configure the Interrupt in the RTC_CR register */
  739. __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
  740. /* Enable the Wake-up Timer */
  741. __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
  742. /* Enable the write protection for RTC registers */
  743. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  744. hrtc->State = HAL_RTC_STATE_READY;
  745. /* Process Unlocked */
  746. __HAL_UNLOCK(hrtc);
  747. return HAL_OK;
  748. }
  749. /**
  750. * @brief Deactivates wake up timer counter.
  751. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  752. * the configuration information for RTC.
  753. * @retval HAL status
  754. */
  755. uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
  756. {
  757. uint32_t tickstart = 0U;
  758. /* Process Locked */
  759. __HAL_LOCK(hrtc);
  760. hrtc->State = HAL_RTC_STATE_BUSY;
  761. /* Disable the write protection for RTC registers */
  762. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  763. /* Disable the Wake-up Timer */
  764. __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
  765. /* In case of interrupt mode is used, the interrupt source must disabled */
  766. __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT);
  767. /* Get tick */
  768. tickstart = HAL_GetTick();
  769. /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
  770. while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
  771. {
  772. if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
  773. {
  774. /* Enable the write protection for RTC registers */
  775. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  776. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  777. /* Process Unlocked */
  778. __HAL_UNLOCK(hrtc);
  779. return HAL_TIMEOUT;
  780. }
  781. }
  782. /* Enable the write protection for RTC registers */
  783. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  784. hrtc->State = HAL_RTC_STATE_READY;
  785. /* Process Unlocked */
  786. __HAL_UNLOCK(hrtc);
  787. return HAL_OK;
  788. }
  789. /**
  790. * @brief Gets wake up timer counter.
  791. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  792. * the configuration information for RTC.
  793. * @retval Counter value
  794. */
  795. uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
  796. {
  797. /* Get the counter value */
  798. return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
  799. }
  800. /**
  801. * @brief This function handles Wake Up Timer interrupt request.
  802. * @note Unlike alarm interrupt line (shared by AlarmA and AlarmB) and tamper
  803. * interrupt line (shared by timestamp and tampers) wakeup timer
  804. * interrupt line is exclusive to the wakeup timer.
  805. * There is no need in this case to check on the interrupt enable
  806. * status via __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE().
  807. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  808. * the configuration information for RTC.
  809. * @retval None
  810. */
  811. void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
  812. {
  813. /* Get the pending status of the WAKEUPTIMER Interrupt */
  814. if(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != (uint32_t)RESET)
  815. {
  816. /* WAKEUPTIMER callback */
  817. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  818. hrtc->WakeUpTimerEventCallback(hrtc);
  819. #else
  820. HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
  821. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  822. /* Clear the WAKEUPTIMER interrupt pending bit */
  823. __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
  824. }
  825. /* Clear the EXTI's line Flag for RTC WakeUpTimer */
  826. __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
  827. /* Change RTC state */
  828. hrtc->State = HAL_RTC_STATE_READY;
  829. }
  830. /**
  831. * @brief Wake Up Timer callback.
  832. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  833. * the configuration information for RTC.
  834. * @retval None
  835. */
  836. __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
  837. {
  838. /* Prevent unused argument(s) compilation warning */
  839. UNUSED(hrtc);
  840. /* NOTE : This function Should not be modified, when the callback is needed,
  841. the HAL_RTC_WakeUpTimerEventCallback could be implemented in the user file
  842. */
  843. }
  844. /**
  845. * @brief This function handles Wake Up Timer Polling.
  846. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  847. * the configuration information for RTC.
  848. * @param Timeout Timeout duration
  849. * @retval HAL status
  850. */
  851. HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
  852. {
  853. uint32_t tickstart = 0U;
  854. /* Get tick */
  855. tickstart = HAL_GetTick();
  856. while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET)
  857. {
  858. if(Timeout != HAL_MAX_DELAY)
  859. {
  860. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  861. {
  862. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  863. return HAL_TIMEOUT;
  864. }
  865. }
  866. }
  867. /* Clear the WAKEUPTIMER Flag */
  868. __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
  869. /* Change RTC state */
  870. hrtc->State = HAL_RTC_STATE_READY;
  871. return HAL_OK;
  872. }
  873. /**
  874. * @}
  875. */
  876. /** @defgroup RTCEx_Exported_Functions_Group3 Extension Peripheral Control functions
  877. * @brief Extension Peripheral Control functions
  878. *
  879. @verbatim
  880. ===============================================================================
  881. ##### Extension Peripheral Control functions #####
  882. ===============================================================================
  883. [..]
  884. This subsection provides functions allowing to
  885. (+) Write a data in a specified RTC Backup data register
  886. (+) Read a data in a specified RTC Backup data register
  887. (+) Set the Coarse calibration parameters.
  888. (+) Deactivate the Coarse calibration parameters
  889. (+) Set the Smooth calibration parameters.
  890. (+) Configure the Synchronization Shift Control Settings.
  891. (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
  892. (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
  893. (+) Enable the RTC reference clock detection.
  894. (+) Disable the RTC reference clock detection.
  895. (+) Enable the Bypass Shadow feature.
  896. (+) Disable the Bypass Shadow feature.
  897. @endverbatim
  898. * @{
  899. */
  900. /**
  901. * @brief Writes a data in a specified RTC Backup data register.
  902. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  903. * the configuration information for RTC.
  904. * @param BackupRegister RTC Backup data Register number.
  905. * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
  906. * specify the register.
  907. * @param Data Data to be written in the specified RTC Backup data register.
  908. * @retval None
  909. */
  910. void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
  911. {
  912. uint32_t tmp = 0U;
  913. /* Check the parameters */
  914. assert_param(IS_RTC_BKP(BackupRegister));
  915. tmp = (uint32_t)&(hrtc->Instance->BKP0R);
  916. tmp += (BackupRegister * 4U);
  917. /* Write the specified register */
  918. *(__IO uint32_t *)tmp = (uint32_t)Data;
  919. }
  920. /**
  921. * @brief Reads data from the specified RTC Backup data Register.
  922. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  923. * the configuration information for RTC.
  924. * @param BackupRegister RTC Backup data Register number.
  925. * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
  926. * specify the register.
  927. * @retval Read value
  928. */
  929. uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
  930. {
  931. uint32_t tmp = 0U;
  932. /* Check the parameters */
  933. assert_param(IS_RTC_BKP(BackupRegister));
  934. tmp = (uint32_t)&(hrtc->Instance->BKP0R);
  935. tmp += (BackupRegister * 4U);
  936. /* Read the specified register */
  937. return (*(__IO uint32_t *)tmp);
  938. }
  939. /**
  940. * @brief Sets the Coarse calibration parameters.
  941. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  942. * the configuration information for RTC.
  943. * @param CalibSign Specifies the sign of the coarse calibration value.
  944. * This parameter can be one of the following values :
  945. * @arg RTC_CALIBSIGN_POSITIVE: The value sign is positive
  946. * @arg RTC_CALIBSIGN_NEGATIVE: The value sign is negative
  947. * @param Value value of coarse calibration expressed in ppm (coded on 5 bits).
  948. *
  949. * @note This Calibration value should be between 0 and 63 when using negative
  950. * sign with a 2-ppm step.
  951. *
  952. * @note This Calibration value should be between 0 and 126 when using positive
  953. * sign with a 4-ppm step.
  954. * @retval HAL status
  955. */
  956. HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef* hrtc, uint32_t CalibSign, uint32_t Value)
  957. {
  958. /* Check the parameters */
  959. assert_param(IS_RTC_CALIB_SIGN(CalibSign));
  960. assert_param(IS_RTC_CALIB_VALUE(Value));
  961. /* Process Locked */
  962. __HAL_LOCK(hrtc);
  963. hrtc->State = HAL_RTC_STATE_BUSY;
  964. /* Disable the write protection for RTC registers */
  965. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  966. /* Set Initialization mode */
  967. if(RTC_EnterInitMode(hrtc) != HAL_OK)
  968. {
  969. /* Enable the write protection for RTC registers */
  970. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  971. /* Set RTC state*/
  972. hrtc->State = HAL_RTC_STATE_ERROR;
  973. /* Process Unlocked */
  974. __HAL_UNLOCK(hrtc);
  975. return HAL_ERROR;
  976. }
  977. else
  978. {
  979. /* Enable the Coarse Calibration */
  980. __HAL_RTC_COARSE_CALIB_ENABLE(hrtc);
  981. /* Set the coarse calibration value */
  982. hrtc->Instance->CALIBR = (uint32_t)(CalibSign|Value);
  983. /* Exit Initialization mode */
  984. hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
  985. }
  986. /* Enable the write protection for RTC registers */
  987. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  988. /* Change state */
  989. hrtc->State = HAL_RTC_STATE_READY;
  990. /* Process Unlocked */
  991. __HAL_UNLOCK(hrtc);
  992. return HAL_OK;
  993. }
  994. /**
  995. * @brief Deactivates the Coarse calibration parameters.
  996. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  997. * the configuration information for RTC.
  998. * @retval HAL status
  999. */
  1000. HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef* hrtc)
  1001. {
  1002. /* Process Locked */
  1003. __HAL_LOCK(hrtc);
  1004. hrtc->State = HAL_RTC_STATE_BUSY;
  1005. /* Disable the write protection for RTC registers */
  1006. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1007. /* Set Initialization mode */
  1008. if(RTC_EnterInitMode(hrtc) != HAL_OK)
  1009. {
  1010. /* Enable the write protection for RTC registers */
  1011. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1012. /* Set RTC state*/
  1013. hrtc->State = HAL_RTC_STATE_ERROR;
  1014. /* Process Unlocked */
  1015. __HAL_UNLOCK(hrtc);
  1016. return HAL_ERROR;
  1017. }
  1018. else
  1019. {
  1020. /* Enable the Coarse Calibration */
  1021. __HAL_RTC_COARSE_CALIB_DISABLE(hrtc);
  1022. /* Exit Initialization mode */
  1023. hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
  1024. }
  1025. /* Enable the write protection for RTC registers */
  1026. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1027. /* Change state */
  1028. hrtc->State = HAL_RTC_STATE_READY;
  1029. /* Process Unlocked */
  1030. __HAL_UNLOCK(hrtc);
  1031. return HAL_OK;
  1032. }
  1033. /**
  1034. * @brief Sets the Smooth calibration parameters.
  1035. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1036. * the configuration information for RTC.
  1037. * @param SmoothCalibPeriod Select the Smooth Calibration Period.
  1038. * This parameter can be can be one of the following values :
  1039. * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
  1040. * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
  1041. * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
  1042. * @param SmoothCalibPlusPulses Select to Set or reset the CALP bit.
  1043. * This parameter can be one of the following values:
  1044. * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
  1045. * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
  1046. * @param SmouthCalibMinusPulsesValue Select the value of CALM[80] bits.
  1047. * This parameter can be one any value from 0 to 0x000001FF.
  1048. * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
  1049. * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
  1050. * SmouthCalibMinusPulsesValue must be equal to 0.
  1051. * @retval HAL status
  1052. */
  1053. HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
  1054. {
  1055. uint32_t tickstart = 0U;
  1056. /* Check the parameters */
  1057. assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
  1058. assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
  1059. assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
  1060. /* Process Locked */
  1061. __HAL_LOCK(hrtc);
  1062. hrtc->State = HAL_RTC_STATE_BUSY;
  1063. /* Disable the write protection for RTC registers */
  1064. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1065. /* check if a calibration is pending*/
  1066. if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
  1067. {
  1068. /* Get tick */
  1069. tickstart = HAL_GetTick();
  1070. /* check if a calibration is pending*/
  1071. while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
  1072. {
  1073. if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
  1074. {
  1075. /* Enable the write protection for RTC registers */
  1076. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1077. /* Change RTC state */
  1078. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  1079. /* Process Unlocked */
  1080. __HAL_UNLOCK(hrtc);
  1081. return HAL_TIMEOUT;
  1082. }
  1083. }
  1084. }
  1085. /* Configure the Smooth calibration settings */
  1086. hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue);
  1087. /* Enable the write protection for RTC registers */
  1088. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1089. /* Change RTC state */
  1090. hrtc->State = HAL_RTC_STATE_READY;
  1091. /* Process Unlocked */
  1092. __HAL_UNLOCK(hrtc);
  1093. return HAL_OK;
  1094. }
  1095. /**
  1096. * @brief Configures the Synchronization Shift Control Settings.
  1097. * @note When REFCKON is set, firmware must not write to Shift control register.
  1098. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1099. * the configuration information for RTC.
  1100. * @param ShiftAdd1S Select to add or not 1 second to the time calendar.
  1101. * This parameter can be one of the following values :
  1102. * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
  1103. * @arg RTC_SHIFTADD1S_RESET: No effect.
  1104. * @param ShiftSubFS Select the number of Second Fractions to substitute.
  1105. * This parameter can be one any value from 0 to 0x7FFF.
  1106. * @retval HAL status
  1107. */
  1108. HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
  1109. {
  1110. uint32_t tickstart = 0U;
  1111. /* Check the parameters */
  1112. assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
  1113. assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
  1114. /* Process Locked */
  1115. __HAL_LOCK(hrtc);
  1116. hrtc->State = HAL_RTC_STATE_BUSY;
  1117. /* Disable the write protection for RTC registers */
  1118. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1119. /* Get tick */
  1120. tickstart = HAL_GetTick();
  1121. /* Wait until the shift is completed*/
  1122. while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET)
  1123. {
  1124. if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
  1125. {
  1126. /* Enable the write protection for RTC registers */
  1127. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1128. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  1129. /* Process Unlocked */
  1130. __HAL_UNLOCK(hrtc);
  1131. return HAL_TIMEOUT;
  1132. }
  1133. }
  1134. /* Check if the reference clock detection is disabled */
  1135. if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET)
  1136. {
  1137. /* Configure the Shift settings */
  1138. hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
  1139. /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
  1140. if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
  1141. {
  1142. if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
  1143. {
  1144. /* Enable the write protection for RTC registers */
  1145. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1146. hrtc->State = HAL_RTC_STATE_ERROR;
  1147. /* Process Unlocked */
  1148. __HAL_UNLOCK(hrtc);
  1149. return HAL_ERROR;
  1150. }
  1151. }
  1152. }
  1153. else
  1154. {
  1155. /* Enable the write protection for RTC registers */
  1156. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1157. /* Change RTC state */
  1158. hrtc->State = HAL_RTC_STATE_ERROR;
  1159. /* Process Unlocked */
  1160. __HAL_UNLOCK(hrtc);
  1161. return HAL_ERROR;
  1162. }
  1163. /* Enable the write protection for RTC registers */
  1164. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1165. /* Change RTC state */
  1166. hrtc->State = HAL_RTC_STATE_READY;
  1167. /* Process Unlocked */
  1168. __HAL_UNLOCK(hrtc);
  1169. return HAL_OK;
  1170. }
  1171. /**
  1172. * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
  1173. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1174. * the configuration information for RTC.
  1175. * @param CalibOutput Select the Calibration output Selection .
  1176. * This parameter can be one of the following values:
  1177. * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
  1178. * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
  1179. * @retval HAL status
  1180. */
  1181. HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput)
  1182. {
  1183. /* Check the parameters */
  1184. assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
  1185. /* Process Locked */
  1186. __HAL_LOCK(hrtc);
  1187. hrtc->State = HAL_RTC_STATE_BUSY;
  1188. /* Disable the write protection for RTC registers */
  1189. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1190. /* Clear flags before config */
  1191. hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
  1192. /* Configure the RTC_CR register */
  1193. hrtc->Instance->CR |= (uint32_t)CalibOutput;
  1194. __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
  1195. /* Enable the write protection for RTC registers */
  1196. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1197. /* Change RTC state */
  1198. hrtc->State = HAL_RTC_STATE_READY;
  1199. /* Process Unlocked */
  1200. __HAL_UNLOCK(hrtc);
  1201. return HAL_OK;
  1202. }
  1203. /**
  1204. * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
  1205. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1206. * the configuration information for RTC.
  1207. * @retval HAL status
  1208. */
  1209. HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc)
  1210. {
  1211. /* Process Locked */
  1212. __HAL_LOCK(hrtc);
  1213. hrtc->State = HAL_RTC_STATE_BUSY;
  1214. /* Disable the write protection for RTC registers */
  1215. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1216. __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
  1217. /* Enable the write protection for RTC registers */
  1218. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1219. /* Change RTC state */
  1220. hrtc->State = HAL_RTC_STATE_READY;
  1221. /* Process Unlocked */
  1222. __HAL_UNLOCK(hrtc);
  1223. return HAL_OK;
  1224. }
  1225. /**
  1226. * @brief Enables the RTC reference clock detection.
  1227. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1228. * the configuration information for RTC.
  1229. * @retval HAL status
  1230. */
  1231. HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc)
  1232. {
  1233. /* Process Locked */
  1234. __HAL_LOCK(hrtc);
  1235. hrtc->State = HAL_RTC_STATE_BUSY;
  1236. /* Disable the write protection for RTC registers */
  1237. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1238. /* Set Initialization mode */
  1239. if(RTC_EnterInitMode(hrtc) != HAL_OK)
  1240. {
  1241. /* Enable the write protection for RTC registers */
  1242. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1243. /* Set RTC state*/
  1244. hrtc->State = HAL_RTC_STATE_ERROR;
  1245. /* Process Unlocked */
  1246. __HAL_UNLOCK(hrtc);
  1247. return HAL_ERROR;
  1248. }
  1249. else
  1250. {
  1251. __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
  1252. /* Exit Initialization mode */
  1253. hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
  1254. }
  1255. /* Enable the write protection for RTC registers */
  1256. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1257. /* Change RTC state */
  1258. hrtc->State = HAL_RTC_STATE_READY;
  1259. /* Process Unlocked */
  1260. __HAL_UNLOCK(hrtc);
  1261. return HAL_OK;
  1262. }
  1263. /**
  1264. * @brief Disable the RTC reference clock detection.
  1265. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1266. * the configuration information for RTC.
  1267. * @retval HAL status
  1268. */
  1269. HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc)
  1270. {
  1271. /* Process Locked */
  1272. __HAL_LOCK(hrtc);
  1273. hrtc->State = HAL_RTC_STATE_BUSY;
  1274. /* Disable the write protection for RTC registers */
  1275. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1276. /* Set Initialization mode */
  1277. if(RTC_EnterInitMode(hrtc) != HAL_OK)
  1278. {
  1279. /* Enable the write protection for RTC registers */
  1280. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1281. /* Set RTC state*/
  1282. hrtc->State = HAL_RTC_STATE_ERROR;
  1283. /* Process Unlocked */
  1284. __HAL_UNLOCK(hrtc);
  1285. return HAL_ERROR;
  1286. }
  1287. else
  1288. {
  1289. __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
  1290. /* Exit Initialization mode */
  1291. hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
  1292. }
  1293. /* Enable the write protection for RTC registers */
  1294. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1295. /* Change RTC state */
  1296. hrtc->State = HAL_RTC_STATE_READY;
  1297. /* Process Unlocked */
  1298. __HAL_UNLOCK(hrtc);
  1299. return HAL_OK;
  1300. }
  1301. /**
  1302. * @brief Enables the Bypass Shadow feature.
  1303. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1304. * the configuration information for RTC.
  1305. * @note When the Bypass Shadow is enabled the calendar value are taken
  1306. * directly from the Calendar counter.
  1307. * @retval HAL status
  1308. */
  1309. HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc)
  1310. {
  1311. /* Process Locked */
  1312. __HAL_LOCK(hrtc);
  1313. hrtc->State = HAL_RTC_STATE_BUSY;
  1314. /* Disable the write protection for RTC registers */
  1315. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1316. /* Set the BYPSHAD bit */
  1317. hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
  1318. /* Enable the write protection for RTC registers */
  1319. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1320. /* Change RTC state */
  1321. hrtc->State = HAL_RTC_STATE_READY;
  1322. /* Process Unlocked */
  1323. __HAL_UNLOCK(hrtc);
  1324. return HAL_OK;
  1325. }
  1326. /**
  1327. * @brief Disables the Bypass Shadow feature.
  1328. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1329. * the configuration information for RTC.
  1330. * @note When the Bypass Shadow is enabled the calendar value are taken
  1331. * directly from the Calendar counter.
  1332. * @retval HAL status
  1333. */
  1334. HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc)
  1335. {
  1336. /* Process Locked */
  1337. __HAL_LOCK(hrtc);
  1338. hrtc->State = HAL_RTC_STATE_BUSY;
  1339. /* Disable the write protection for RTC registers */
  1340. __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
  1341. /* Reset the BYPSHAD bit */
  1342. hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
  1343. /* Enable the write protection for RTC registers */
  1344. __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
  1345. /* Change RTC state */
  1346. hrtc->State = HAL_RTC_STATE_READY;
  1347. /* Process Unlocked */
  1348. __HAL_UNLOCK(hrtc);
  1349. return HAL_OK;
  1350. }
  1351. /**
  1352. * @}
  1353. */
  1354. /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
  1355. * @brief Extended features functions
  1356. *
  1357. @verbatim
  1358. ===============================================================================
  1359. ##### Extended features functions #####
  1360. ===============================================================================
  1361. [..] This section provides functions allowing to:
  1362. (+) RTC Alarm B callback
  1363. (+) RTC Poll for Alarm B request
  1364. @endverbatim
  1365. * @{
  1366. */
  1367. /**
  1368. * @brief Alarm B callback.
  1369. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1370. * the configuration information for RTC.
  1371. * @retval None
  1372. */
  1373. __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
  1374. {
  1375. /* Prevent unused argument(s) compilation warning */
  1376. UNUSED(hrtc);
  1377. /* NOTE : This function Should not be modified, when the callback is needed,
  1378. the HAL_RTC_AlarmBEventCallback could be implemented in the user file
  1379. */
  1380. }
  1381. /**
  1382. * @brief This function handles AlarmB Polling request.
  1383. * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
  1384. * the configuration information for RTC.
  1385. * @param Timeout Timeout duration
  1386. * @retval HAL status
  1387. */
  1388. HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
  1389. {
  1390. uint32_t tickstart = 0U;
  1391. /* Get tick */
  1392. tickstart = HAL_GetTick();
  1393. while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET)
  1394. {
  1395. if(Timeout != HAL_MAX_DELAY)
  1396. {
  1397. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  1398. {
  1399. hrtc->State = HAL_RTC_STATE_TIMEOUT;
  1400. return HAL_TIMEOUT;
  1401. }
  1402. }
  1403. }
  1404. /* Clear the Alarm Flag */
  1405. __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
  1406. /* Change RTC state */
  1407. hrtc->State = HAL_RTC_STATE_READY;
  1408. return HAL_OK;
  1409. }
  1410. /**
  1411. * @}
  1412. */
  1413. /**
  1414. * @}
  1415. */
  1416. #endif /* HAL_RTC_MODULE_ENABLED */
  1417. /**
  1418. * @}
  1419. */
  1420. /**
  1421. * @}
  1422. */
  1423. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/