1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
31
32
33
37
38
39
44
45
46
47
48
49
56
57
58
59
60
61
62
63
64
67
68
69
76
77
78
79
80
81
82
83
84
85
86
90
91
92
93
97
98
99
100
101
102
103
110
115
116
117
118
119
120
121
122
123
124
125
129
130
137
141
142
147
151
152
157
164
165
170
179
180
185
189
190
193
194
/* ... */
#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_OFF;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
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_LSI;
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);
}{ ... }
/* ... */
/* ... */