1 | void RtcConfig(void)
|
2 | {
|
3 | NVIC_InitTypeDef NVIC_InitStructure;
|
4 | EXTI_InitTypeDef EXTI_InitStructure;
|
5 |
|
6 | /* Configure EXTI Line17(RTC Alarm) to generate an interrupt on rising edge */
|
7 | EXTI_ClearITPendingBit(EXTI_Line17);
|
8 | EXTI_InitStructure.EXTI_Line = EXTI_Line17;
|
9 | EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
10 | EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
11 | EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
12 | EXTI_Init(&EXTI_InitStructure);
|
13 |
|
14 | /* 2 bits for Preemption Priority and 2 bits for Sub Priority */
|
15 | //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
16 |
|
17 | NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
|
18 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
19 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
20 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
21 | NVIC_Init(&NVIC_InitStructure);
|
22 |
|
23 | /* Enable PWR and BKP clock */
|
24 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
|
25 |
|
26 | /* RTC clock source configuration ------------------------------------------*/
|
27 | /* Allow access to BKP Domain */
|
28 | PWR_BackupAccessCmd(ENABLE);
|
29 |
|
30 | /* Reset Backup Domain */
|
31 | BKP_DeInit();
|
32 |
|
33 | /* Enable the LSE OSC */
|
34 | RCC_LSEConfig(RCC_LSE_ON);
|
35 | /* Wait till LSE is ready */
|
36 | while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
|
37 | {
|
38 | }
|
39 |
|
40 | /* Select the RTC Clock Source */
|
41 | RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
42 |
|
43 | /* Enable the RTC Clock */
|
44 | RCC_RTCCLKCmd(ENABLE);
|
45 |
|
46 | /* RTC configuration -------------------------------------------------------*/
|
47 | /* Wait for RTC APB registers synchronisation */
|
48 | RTC_WaitForSynchro();
|
49 | RTC_WaitForLastTask();
|
50 |
|
51 | /* Set the RTC time base to 1s */
|
52 | RTC_SetPrescaler(32767);
|
53 | /* Wait until last write operation on RTC registers has finished */
|
54 | RTC_WaitForLastTask();
|
55 |
|
56 | /* Enable the RTC Alarm interrupt */
|
57 | RTC_ITConfig(RTC_IT_ALR, ENABLE);
|
58 | /* Wait until last write operation on RTC registers has finished */
|
59 | RTC_WaitForLastTask();
|
60 |
|
61 | rStatus.clockStatus = RTC_CLOCK_ON;
|
62 | }
|