67 #define RTC_CLOCK_SOURCE_HSE
71 #ifdef RTC_CLOCK_SOURCE_HSE
72 #define RTC_ASYNCH_PREDIV 99U
73 #define RTC_SYNCH_PREDIV 9U
74 #define RCC_RTCCLKSOURCE_1MHZ ((uint32_t)((uint32_t)RCC_BDCR_RTCSEL | (uint32_t)((HSE_VALUE/1000000U) << 16U)))
76 #define RTC_ASYNCH_PREDIV 0U
77 #define RTC_SYNCH_PREDIV 31U
98 __IO uint32_t counter = 0U;
102 HAL_StatusTypeDef status;
104 #ifdef RTC_CLOCK_SOURCE_LSE
108 RCC_OscInitStruct.
LSEState = RCC_LSE_ON;
110 #elif defined (RTC_CLOCK_SOURCE_LSI)
114 RCC_OscInitStruct.
LSIState = RCC_LSI_ON;
116 #elif defined (RTC_CLOCK_SOURCE_HSE)
120 RCC_OscInitStruct.
HSEState = RCC_HSE_ON;
124 #error Please select the RTC Clock source
128 if (status == HAL_OK)
133 if (status == HAL_OK)
136 __HAL_RCC_RTC_ENABLE();
149 hRTC_Handle.Instance = RTC;
150 hRTC_Handle.Init.HourFormat = RTC_HOURFORMAT_24;
151 hRTC_Handle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
152 hRTC_Handle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
153 hRTC_Handle.Init.OutPut = RTC_OUTPUT_DISABLE;
154 hRTC_Handle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
155 hRTC_Handle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
158 if (status == HAL_OK)
161 __HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
164 __HAL_RTC_ALARMA_DISABLE(&hRTC_Handle);
167 __HAL_RTC_ALARM_CLEAR_FLAG(&hRTC_Handle, RTC_FLAG_ALRAF);
171 while (__HAL_RTC_ALARM_GET_FLAG(&hRTC_Handle, RTC_FLAG_ALRAWF) == RESET)
173 if (counter++ == (SystemCoreClock / 48U))
179 if (status == HAL_OK)
181 hRTC_Handle.Instance->ALRMAR = (uint32_t)0x01U;
184 __HAL_RTC_ALARMA_ENABLE(&hRTC_Handle);
186 __HAL_RTC_ALARM_ENABLE_IT(&hRTC_Handle, RTC_IT_ALRA);
189 __HAL_RTC_ALARM_EXTI_ENABLE_IT();
190 __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();
193 if ((hRTC_Handle.Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
196 hRTC_Handle.Instance->ISR = (uint32_t)RTC_INIT_MASK;
198 while ((hRTC_Handle.Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
200 if (counter++ == (SystemCoreClock / 48U))
207 if (status == HAL_OK)
209 hRTC_Handle.Instance->DR = 0U;
210 hRTC_Handle.Instance->TR = 0U;
212 hRTC_Handle.Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
215 __HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
221 if (TickPriority < (1UL << __NVIC_PRIO_BITS))
224 uwTickPrio = TickPriority;
243 __HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
245 __HAL_RTC_ALARM_DISABLE_IT(&hRTC_Handle, RTC_IT_ALRA);
247 __HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
258 __HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle);
260 __HAL_RTC_ALARM_ENABLE_IT(&hRTC_Handle, RTC_IT_ALRA);
262 __HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle);
275 __IO uint32_t counter = 0U;
279 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
282 hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
284 while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
286 if(counter++ == (SystemCoreClock /48U))
292 hrtc->Instance->DR = 0U;
293 hrtc->Instance->TR = 0U;
295 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
298 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
Sets the priority of an interrupt.
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
Enables a device specific interrupt in the NVIC interrupt controller.
void HAL_IncTick(void)
This function is called to increment a global variable "uwTick" used as application time base.
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
ALARM A Event Callback in non blocking mode.
void HAL_ResumeTick(void)
Resume Tick increment.
void RTC_Alarm_IRQHandler(void)
This function handles RTC ALARM interrupt request.
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
This function configures the RTC_ALARMA as a time base source. The time source is configured to have ...
void HAL_SuspendTick(void)
Suspend Tick increment.
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
Initializes the RCC extended peripherals clocks according to the specified parameters in the RCC_Peri...
uint32_t PeriphClockSelection
uint32_t RTCClockSelection
RCC extended clocks structure definition.
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef.
RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition.
HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc)
Initializes the RTC peripheral.
void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc)
Handles Alarm interrupt request.
struct __RTC_HandleTypeDef else typedef struct endif RTC_HandleTypeDef
RTC Handle Structure definition.
This file contains all the functions prototypes for the HAL module driver.