1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
30
31
32
36
37
38
43
44
45
46
47
48
55
56
57
58
59
60
61
62
63
66
67
68
75
76
77
78
79
80
81
82
83
84
85
89
90
91
92
96
97
98
99
100
101
102
109
114
115
116
117
118
119
120
121
122
123
124
128
129
136
140
141
146
150
151
156
163
164
169
178
179
184
188
189
192
193
/* ... */
#include "k_rtc.h"
/* ... */
/* ... */
Includes
#define RTC_ASYNCH_PREDIV 0x7F
#define RTC_SYNCH_PREDIV 0x00FF
Private defines
RTC_HandleTypeDef RtcHandle;
/* ... */
void k_CalendarBkupInit(void)
{
/* ... */
RtcHandle.Instance = RTC;
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
{
}if (HAL_RTC_Init(&RtcHandle) != HAL_OK) { ... }
}{ ... }
/* ... */
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
return;
}if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { ... }
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
return;
}if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { ... }
__HAL_RCC_RTC_ENABLE();
}{ ... }
/* ... */
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc)
{
__HAL_RCC_RTC_DISABLE();
}{ ... }
/* ... */
void k_BkupSaveParameter(uint32_t address, uint32_t data)
{
HAL_RTCEx_BKUPWrite(&RtcHandle,address,data);
}{ ... }
/* ... */
uint32_t k_BkupRestoreParameter(uint32_t address)
{
return HAL_RTCEx_BKUPRead(&RtcHandle,address);
}{ ... }
/* ... */
void k_GetTime( RTC_TimeTypeDef *Time)
{
HAL_RTC_GetTime(&RtcHandle, Time, FORMAT_BIN);
}{ ... }
/* ... */
void k_SetTime( RTC_TimeTypeDef *Time)
{
Time->StoreOperation = 0;
Time->SubSeconds = 0;
Time->DayLightSaving = 0;
HAL_RTC_SetTime(&RtcHandle, Time, FORMAT_BIN);
}{ ... }
/* ... */
void k_GetDate( RTC_DateTypeDef *Date)
{
HAL_RTC_GetDate(&RtcHandle, Date, FORMAT_BIN);
if((Date->Date == 0) || (Date->Month == 0))
{
Date->Date = Date->Month = 1;
}if ((Date->Date == 0) || (Date->Month == 0)) { ... }
}{ ... }
/* ... */
void k_SetDate( RTC_DateTypeDef *Date)
{
HAL_RTC_SetDate(&RtcHandle, Date, FORMAT_BIN);
}{ ... }
/* ... */
/* ... */