1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
31
32
33
34
35
36
37
38
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
71
72
73
74
79
80
81
82
83
84
89
90
91
92
97
98
99
100
101
102
103
104
105
106
107
108
109
110
117
122
123
126
127
130
131
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
/* ... */
/* ... */
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
#ifdef RTC_CLOCK_SOURCE_LSE
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)
{
Error_Handler();
}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)
{
Error_Handler();
}if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { ... }
/* ... */#elif defined (RTC_CLOCK_SOURCE_LSI)
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}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)
{
Error_Handler();
}if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { ... }
/* ... */#else
#error Please select the RTC Clock source inside the main.h file
#endif
__HAL_RCC_RTC_ENABLE();
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0x0F, 0);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
}{ ... }
/* ... */
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc)
{
__HAL_RCC_RTC_DISABLE();
}{ ... }
/* ... */
/* ... */
/* ... */