Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "k_rtc.h"
Private defines
#define RTC_ASYNCH_PREDIV
#define RTC_SYNCH_PREDIV
RtcHandle
k_CalendarBkupInit()
HAL_RTC_MspInit(RTC_HandleTypeDef *)
HAL_RTC_MspDeInit(RTC_HandleTypeDef *)
k_BkupSaveParameter(uint32_t, uint32_t)
k_BkupRestoreParameter(uint32_t)
k_GetTime(RTC_TimeTypeDef *)
k_SetTime(RTC_TimeTypeDef *)
k_GetDate(RTC_DateTypeDef *)
k_SetDate(RTC_DateTypeDef *)
Files
loading...
CodeScopeSTM32 Libraries and SamplesMB1063Core/Src/k_rtc.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file k_rtc.c * @author MCD Application Team * @brief This file provides the kernel rtc functions ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "k_rtc.h" /** @addtogroup CORE * @{ *//* ... */ /** @defgroup KERNEL_RTC * @brief Kernel rtc routines * @{ *//* ... */ Includes /* External variables --------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/ #define RTC_ASYNCH_PREDIV 0x7F /* LSE as RTC clock */ #define RTC_SYNCH_PREDIV 0x00FF /* LSE as RTC clock */ Private defines/* Private macros ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ RTC_HandleTypeDef RtcHandle; /** * @brief Configure the current time and date. * @param None * @retval None *//* ... */ void k_CalendarBkupInit(void) { /*##-1- Configure the RTC peripheral #######################################*/ /* Configure RTC prescaler and RTC data registers */ /* RTC configured as follow: - Hour Format = Format 24 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain *//* ... */ 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) { ... } }{ ... } /** * @brief RTC MSP Initialization * This function configures the hardware resources used in this demonstration: * - Peripheral's clock enable * @param hrtc: RTC handle pointer * @retval None *//* ... */ void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; /*##-1- Configure LSE as RTC clock source ##################################*/ 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) { ... } /*##-2- Enable RTC peripheral Clocks #######################################*/ /* Enable RTC Clock */ __HAL_RCC_RTC_ENABLE(); }{ ... } /** * @brief RTC MSP De-Initialization * This function frees the hardware resources used in this demonstration: * - Disable the Peripheral's clock * @param hrtc: RTC handle pointer * @retval None *//* ... */ void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc) { /*##-1- Reset peripherals ##################################################*/ __HAL_RCC_RTC_DISABLE(); }{ ... } /** * @brief Backup save parameter * @param address: RTC Backup data Register number. * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to * specify the register. * @param Data: Data to be written in the specified RTC Backup data register. * @retval None *//* ... */ void k_BkupSaveParameter(uint32_t address, uint32_t data) { HAL_RTCEx_BKUPWrite(&RtcHandle,address,data); }{ ... } /** * @brief Backup restore parameter. * @param address: RTC Backup data Register number. * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to * specify the register. * @retval None *//* ... */ uint32_t k_BkupRestoreParameter(uint32_t address) { return HAL_RTCEx_BKUPRead(&RtcHandle,address); }{ ... } /** * @brief RTC Get time. * @param Time: Pointer to Time structure * @retval None *//* ... */ void k_GetTime( RTC_TimeTypeDef *Time) { HAL_RTC_GetTime(&RtcHandle, Time, RTC_FORMAT_BIN); }{ ... } /** * @brief RTC Set time. * @param Time: Pointer to Time structure * @retval None *//* ... */ void k_SetTime( RTC_TimeTypeDef *Time) { Time->StoreOperation = 0; Time->SubSeconds = 0; Time->DayLightSaving = 0; HAL_RTC_SetTime(&RtcHandle, Time, RTC_FORMAT_BIN); }{ ... } /** * @brief RTC Get date * @param Date: Pointer to Date structure * @retval None *//* ... */ void k_GetDate( RTC_DateTypeDef *Date) { HAL_RTC_GetDate(&RtcHandle, Date, RTC_FORMAT_BIN); if((Date->Date == 0) || (Date->Month == 0)) { Date->Date = Date->Month = 1; }if ((Date->Date == 0) || (Date->Month == 0)) { ... } }{ ... } /** * @brief RTC Set date * @param Date: Pointer to Date structure * @retval None *//* ... */ void k_SetDate( RTC_DateTypeDef *Date) { HAL_RTC_SetDate(&RtcHandle, Date, RTC_FORMAT_BIN); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */