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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
////////////////////////////////////////////////////////////////////////////////
/// @file hal_bkp.c
/// @author AE TEAM
/// @brief THIS FILE PROVIDES ALL THE BKP FIRMWARE FUNCTIONS.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>© COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////
// Define to prevent recursive inclusion
#define _HAL_BKP_C_
// Files includes
#include "types.h"
#include "hal_pwr.h"
#include "hal_rcc.h"
#include "hal_bkp.h"
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MM32_Hardware_Abstract_Layer
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup BKP_HAL
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup BKP_Exported_Functions
/// @{
////////////////////////////////////////////////////////////////////////////////
/// @brief Deinitializes the BKP peripheral registers to their default reset
/// values.
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_DeInit(void)
{
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Configures the Tamper Pin active level.
/// @param tamper_pin_level: specifies the Tamper Pin active level.
/// This parameter can be one of the following values:
/// @arg BKP_TamperPinLevel_High: Tamper pin active on high level
/// @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_TamperPinLevelConfig(BKPTPAL_Typedef tamper_pin_level)
{
BKP->CR = tamper_pin_level;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the Tamper Pin activation.
/// @param state: new state of the Tamper Pin activation.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_TamperPinCmd(FunctionalState state)
{
(state) ? SET_BIT(BKP->CR, BKP_CR_TPE) : CLEAR_BIT(BKP->CR, BKP_CR_TPE);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Enables or disables the Tamper Pin Interrupt.
/// @param state: new state of the Tamper Pin Interrupt.
/// This parameter can be: ENABLE or DISABLE.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_ITConfig(FunctionalState state)
{
(state) ? SET_BIT(BKP->CSR, BKP_CSR_TPIE) : CLEAR_BIT(BKP->CSR, BKP_CSR_TPIE);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Select the RTC output source to output on the Tamper pin.
/// @param rtc_output_source: specifies the RTC output source.
/// This parameter can be one of the following values:
/// @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
/// @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
/// divided by 64 on the Tamper pin.
/// @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
/// the Tamper pin.
/// @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
/// the Tamper pin.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_RTCOutputConfig(BKPRTCOUTPUTSRC_Typedef rtc_output_source)
{
MODIFY_REG(BKP->RTCCR, BKP_RTCCR_CCO | BKP_RTCCR_ASOE | BKP_RTCCR_ASOS, rtc_output_source);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Sets RTC Clock Calibration value.
/// @param calibration_value: specifies the RTC Clock Calibration value.
/// This parameter must be a number between 0 and 0x7F.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_SetRTCCalibrationValue(u8 calibration_value)
{
MODIFY_REG(BKP->RTCCR, BKP_RTCCR_CAL, calibration_value);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Checks whether the Tamper Pin Event flag is set or not.
/// @param None.
/// @retval State: The new state of the Tamper Pin Event flag (SET or RESET).
////////////////////////////////////////////////////////////////////////////////
FlagStatus BKP_GetFlagStatus(void)
{
return ((BKP->CSR & BKP_CSR_TEF) ? SET : RESET);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Clears Tamper Pin Event pending flag.
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_ClearFlag(void)
{
SET_BIT(BKP->CSR, BKP_CSR_CTE);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Checks whether the Tamper Pin Interrupt has occurred or not.
/// @param None.
/// @retval State: The new state of the Tamper Pin Interrupt (SET or RESET).
////////////////////////////////////////////////////////////////////////////////
ITStatus BKP_GetITStatus(void)
{
return ((BKP->CSR & BKP_CSR_TIF) ? SET : RESET);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Clears Tamper Pin Interrupt pending bit.
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_ClearITPendingBit(void)
{
SET_BIT(BKP->CSR, BKP_CSR_CTI);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Writes user data to the specified data Backup Register.
/// @param bkp_dr: specifies the data Backup Register.
/// This parameter can be BKP_DRx where x:[1, 10]
/// @param data: data to write
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void BKP_WriteBackupRegister(BKPDR_Typedef bkp_dr, u16 data)
{
*(vu16*)(BKP_BASE + bkp_dr) = data;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Reads data from the specified data Backup Register.
/// @param bkp_dr: specifies the data Backup Register.
/// This parameter can be BKP_DRx where x:[1, 10]
/// @retval data: The content of the specified data Backup Register
////////////////////////////////////////////////////////////////////////////////
u16 BKP_ReadBackupRegister(BKPDR_Typedef bkp_dr)
{
return (*(vu16*)(BKP_BASE + bkp_dr));
}
////////////////////////////////////////////////////////////////////////////////
// Extended function interface
////////////////////////////////////////////////////////////////////////////////
/// @brief Initializes the BKP peripheral, enable access to the backup
/// registers.
/// @param None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exBKP_Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1ENR_PWR, ENABLE);
//COMMON_EnableIpClock(emCLOCK_PWR);
RCC_APB1PeriphClockCmd(RCC_APB1ENR_BKP, ENABLE);
//COMMON_EnableIpClock(emCLOCK_BKP);
RCC->BDCR |= RCC_BDCR_DBP;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Writes user data to the specified data Backup Register immediately.
/// @param bkp_dr: specifies the data Backup Register.
/// This parameter can be BKP_DRx where x:[1, 10]
/// @param data: data to write
/// @retval None.
////////////////////////////////////////////////////////////////////////////////
void exBKP_ImmWrite(BKPDR_Typedef bkp_dr, u16 dat)
{
RCC->BDCR |= RCC_BDCR_DBP;
*(vu16*)(BKP_BASE + bkp_dr) = dat;
RCC->BDCR &= ~RCC_BDCR_DBP;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Reads data from the specified data Backup Register immediately.
/// @param bkp_dr: specifies the data Backup Register.
/// This parameter can be BKP_DRx where x:[1, 10]
/// @retval data: The content of the specified data Backup Register
////////////////////////////////////////////////////////////////////////////////
u16 exBKP_ImmRead(BKPDR_Typedef bkp_dr)
{
u16 dat;
RCC->BDCR |= RCC_BDCR_DBP;
dat = (*(vu16*)(BKP_BASE + bkp_dr));
RCC->BDCR &= ~RCC_BDCR_DBP;
return dat;
}
/// @}
/// @}
/// @}
|