1 | /**
|
2 | * @brief Configures the RTC peripheral and select the clock source.
|
3 | * @param None
|
4 | * @retval None
|
5 | */
|
6 | static void RTC_Config(void)
|
7 | {
|
8 | RTC_InitTypeDef RTC_InitStructure;
|
9 | RTC_TimeTypeDef RTC_TimeStruct;
|
10 | RTC_DateTypeDef RTC_DateStruct;
|
11 |
|
12 | /* Enable the PWR clock */
|
13 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
14 |
|
15 | /* Allow access to RTC */
|
16 | PWR_BackupAccessCmd(ENABLE);
|
17 |
|
18 | /* Reset RTC Domain */
|
19 | RCC_BackupResetCmd(ENABLE);
|
20 | RCC_BackupResetCmd(DISABLE);
|
21 |
|
22 | /* Enable the LSE OSC */
|
23 | RCC_LSEConfig(RCC_LSE_ON);
|
24 |
|
25 | /* Wait till LSE is ready */
|
26 | while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
|
27 | {
|
28 | }
|
29 |
|
30 | /* Select the RTC Clock Source */
|
31 | RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
32 |
|
33 | /* Enable the RTC Clock */
|
34 | RCC_RTCCLKCmd(ENABLE);
|
35 |
|
36 | /* Wait for RTC APB registers synchronisation */
|
37 | RTC_WaitForSynchro();
|
38 |
|
39 | /* Configure the RTC data register and RTC prescaler */
|
40 | /* ck_spre(1Hz) = RTCCLK(LSI) /(AsynchPrediv + 1)*(SynchPrediv + 1)*/
|
41 | RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
|
42 | RTC_InitStructure.RTC_SynchPrediv = 0xFF;
|
43 | RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
|
44 | RTC_Init(&RTC_InitStructure);
|
45 |
|
46 | /* Set the time to 00h 00mn 00s AM */
|
47 | RTC_TimeStruct.RTC_H12 = RTC_H12_AM;
|
48 | RTC_TimeStruct.RTC_Hours = 9;
|
49 | RTC_TimeStruct.RTC_Minutes = 31;
|
50 | RTC_TimeStruct.RTC_Seconds = 0;
|
51 | RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
|
52 |
|
53 | /* Wait for RTC APB registers synchronisation */
|
54 | RTC_WaitForSynchro();
|
55 |
|
56 | RTC_DateStruct.RTC_Date = 25;
|
57 | RTC_DateStruct.RTC_Month = 10;
|
58 | RTC_DateStruct.RTC_WeekDay = 5; // 1 is monday
|
59 | RTC_DateStruct.RTC_Year = 13;
|
60 | RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
|
61 | }
|