3328 |
povik |
1 |
/** |
|
|
2 |
****************************************************************************** |
|
|
3 |
* @file stm32f10x_bkp.c |
|
|
4 |
* @author MCD Application Team |
|
|
5 |
* @version V3.1.0 |
|
|
6 |
* @date 06/19/2009 |
|
|
7 |
* @brief This file provides all the BKP firmware functions. |
|
|
8 |
****************************************************************************** |
|
|
9 |
* @copy |
|
|
10 |
* |
|
|
11 |
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
|
|
12 |
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
|
|
13 |
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
|
|
14 |
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
|
|
15 |
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
|
|
16 |
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
|
|
17 |
* |
|
|
18 |
* <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2> |
|
|
19 |
*/ |
|
|
20 |
|
|
|
21 |
/* Includes ------------------------------------------------------------------*/ |
|
|
22 |
#include "stm32f10x_bkp.h" |
|
|
23 |
#include "stm32f10x_rcc.h" |
|
|
24 |
|
|
|
25 |
/** @addtogroup STM32F10x_StdPeriph_Driver |
|
|
26 |
* @{ |
|
|
27 |
*/ |
|
|
28 |
|
|
|
29 |
/** @defgroup BKP |
|
|
30 |
* @brief BKP driver modules |
|
|
31 |
* @{ |
|
|
32 |
*/ |
|
|
33 |
|
|
|
34 |
/** @defgroup BKP_Private_TypesDefinitions |
|
|
35 |
* @{ |
|
|
36 |
*/ |
|
|
37 |
|
|
|
38 |
/** |
|
|
39 |
* @} |
|
|
40 |
*/ |
|
|
41 |
|
|
|
42 |
/** @defgroup BKP_Private_Defines |
|
|
43 |
* @{ |
|
|
44 |
*/ |
|
|
45 |
|
|
|
46 |
/* ------------ BKP registers bit address in the alias region --------------- */ |
|
|
47 |
#define BKP_OFFSET (BKP_BASE - PERIPH_BASE) |
|
|
48 |
|
|
|
49 |
/* --- CR Register ----*/ |
|
|
50 |
|
|
|
51 |
/* Alias word address of TPAL bit */ |
|
|
52 |
#define CR_OFFSET (BKP_OFFSET + 0x30) |
|
|
53 |
#define TPAL_BitNumber 0x01 |
|
|
54 |
#define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4)) |
|
|
55 |
|
|
|
56 |
/* Alias word address of TPE bit */ |
|
|
57 |
#define TPE_BitNumber 0x00 |
|
|
58 |
#define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4)) |
|
|
59 |
|
|
|
60 |
/* --- CSR Register ---*/ |
|
|
61 |
|
|
|
62 |
/* Alias word address of TPIE bit */ |
|
|
63 |
#define CSR_OFFSET (BKP_OFFSET + 0x34) |
|
|
64 |
#define TPIE_BitNumber 0x02 |
|
|
65 |
#define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4)) |
|
|
66 |
|
|
|
67 |
/* Alias word address of TIF bit */ |
|
|
68 |
#define TIF_BitNumber 0x09 |
|
|
69 |
#define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4)) |
|
|
70 |
|
|
|
71 |
/* Alias word address of TEF bit */ |
|
|
72 |
#define TEF_BitNumber 0x08 |
|
|
73 |
#define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4)) |
|
|
74 |
|
|
|
75 |
/* ---------------------- BKP registers bit mask ------------------------ */ |
|
|
76 |
|
|
|
77 |
/* RTCCR register bit mask */ |
|
|
78 |
#define RTCCR_CAL_Mask ((uint16_t)0xFF80) |
|
|
79 |
#define RTCCR_Mask ((uint16_t)0xFC7F) |
|
|
80 |
|
|
|
81 |
/* CSR register bit mask */ |
|
|
82 |
#define CSR_CTE_Set ((uint16_t)0x0001) |
|
|
83 |
#define CSR_CTI_Set ((uint16_t)0x0002) |
|
|
84 |
|
|
|
85 |
/** |
|
|
86 |
* @} |
|
|
87 |
*/ |
|
|
88 |
|
|
|
89 |
|
|
|
90 |
/** @defgroup BKP_Private_Macros |
|
|
91 |
* @{ |
|
|
92 |
*/ |
|
|
93 |
|
|
|
94 |
/** |
|
|
95 |
* @} |
|
|
96 |
*/ |
|
|
97 |
|
|
|
98 |
/** @defgroup BKP_Private_Variables |
|
|
99 |
* @{ |
|
|
100 |
*/ |
|
|
101 |
|
|
|
102 |
/** |
|
|
103 |
* @} |
|
|
104 |
*/ |
|
|
105 |
|
|
|
106 |
/** @defgroup BKP_Private_FunctionPrototypes |
|
|
107 |
* @{ |
|
|
108 |
*/ |
|
|
109 |
|
|
|
110 |
/** |
|
|
111 |
* @} |
|
|
112 |
*/ |
|
|
113 |
|
|
|
114 |
/** @defgroup BKP_Private_Functions |
|
|
115 |
* @{ |
|
|
116 |
*/ |
|
|
117 |
|
|
|
118 |
/** |
|
|
119 |
* @brief Deinitializes the BKP peripheral registers to their default reset values. |
|
|
120 |
* @param None |
|
|
121 |
* @retval None |
|
|
122 |
*/ |
|
|
123 |
void BKP_DeInit(void) |
|
|
124 |
{ |
|
|
125 |
RCC_BackupResetCmd(ENABLE); |
|
|
126 |
RCC_BackupResetCmd(DISABLE); |
|
|
127 |
} |
|
|
128 |
|
|
|
129 |
/** |
|
|
130 |
* @brief Configures the Tamper Pin active level. |
|
|
131 |
* @param BKP_TamperPinLevel: specifies the Tamper Pin active level. |
|
|
132 |
* This parameter can be one of the following values: |
|
|
133 |
* @arg BKP_TamperPinLevel_High: Tamper pin active on high level |
|
|
134 |
* @arg BKP_TamperPinLevel_Low: Tamper pin active on low level |
|
|
135 |
* @retval None |
|
|
136 |
*/ |
|
|
137 |
void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel) |
|
|
138 |
{ |
|
|
139 |
/* Check the parameters */ |
|
|
140 |
assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel)); |
|
|
141 |
*(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel; |
|
|
142 |
} |
|
|
143 |
|
|
|
144 |
/** |
|
|
145 |
* @brief Enables or disables the Tamper Pin activation. |
|
|
146 |
* @param NewState: new state of the Tamper Pin activation. |
|
|
147 |
* This parameter can be: ENABLE or DISABLE. |
|
|
148 |
* @retval None |
|
|
149 |
*/ |
|
|
150 |
void BKP_TamperPinCmd(FunctionalState NewState) |
|
|
151 |
{ |
|
|
152 |
/* Check the parameters */ |
|
|
153 |
assert_param(IS_FUNCTIONAL_STATE(NewState)); |
|
|
154 |
*(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState; |
|
|
155 |
} |
|
|
156 |
|
|
|
157 |
/** |
|
|
158 |
* @brief Enables or disables the Tamper Pin Interrupt. |
|
|
159 |
* @param NewState: new state of the Tamper Pin Interrupt. |
|
|
160 |
* This parameter can be: ENABLE or DISABLE. |
|
|
161 |
* @retval None |
|
|
162 |
*/ |
|
|
163 |
void BKP_ITConfig(FunctionalState NewState) |
|
|
164 |
{ |
|
|
165 |
/* Check the parameters */ |
|
|
166 |
assert_param(IS_FUNCTIONAL_STATE(NewState)); |
|
|
167 |
*(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState; |
|
|
168 |
} |
|
|
169 |
|
|
|
170 |
/** |
|
|
171 |
* @brief Select the RTC output source to output on the Tamper pin. |
|
|
172 |
* @param BKP_RTCOutputSource: specifies the RTC output source. |
|
|
173 |
* This parameter can be one of the following values: |
|
|
174 |
* @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin. |
|
|
175 |
* @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency |
|
|
176 |
* divided by 64 on the Tamper pin. |
|
|
177 |
* @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on |
|
|
178 |
* the Tamper pin. |
|
|
179 |
* @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on |
|
|
180 |
* the Tamper pin. |
|
|
181 |
* @retval None |
|
|
182 |
*/ |
|
|
183 |
void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource) |
|
|
184 |
{ |
|
|
185 |
uint16_t tmpreg = 0; |
|
|
186 |
/* Check the parameters */ |
|
|
187 |
assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource)); |
|
|
188 |
tmpreg = BKP->RTCCR; |
|
|
189 |
/* Clear CCO, ASOE and ASOS bits */ |
|
|
190 |
tmpreg &= RTCCR_Mask; |
|
|
191 |
|
|
|
192 |
/* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */ |
|
|
193 |
tmpreg |= BKP_RTCOutputSource; |
|
|
194 |
/* Store the new value */ |
|
|
195 |
BKP->RTCCR = tmpreg; |
|
|
196 |
} |
|
|
197 |
|
|
|
198 |
/** |
|
|
199 |
* @brief Sets RTC Clock Calibration value. |
|
|
200 |
* @param CalibrationValue: specifies the RTC Clock Calibration value. |
|
|
201 |
* This parameter must be a number between 0 and 0x7F. |
|
|
202 |
* @retval None |
|
|
203 |
*/ |
|
|
204 |
void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue) |
|
|
205 |
{ |
|
|
206 |
uint16_t tmpreg = 0; |
|
|
207 |
/* Check the parameters */ |
|
|
208 |
assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue)); |
|
|
209 |
tmpreg = BKP->RTCCR; |
|
|
210 |
/* Clear CAL[6:0] bits */ |
|
|
211 |
tmpreg &= RTCCR_CAL_Mask; |
|
|
212 |
/* Set CAL[6:0] bits according to CalibrationValue value */ |
|
|
213 |
tmpreg |= CalibrationValue; |
|
|
214 |
/* Store the new value */ |
|
|
215 |
BKP->RTCCR = tmpreg; |
|
|
216 |
} |
|
|
217 |
|
|
|
218 |
/** |
|
|
219 |
* @brief Writes user data to the specified Data Backup Register. |
|
|
220 |
* @param BKP_DR: specifies the Data Backup Register. |
|
|
221 |
* This parameter can be BKP_DRx where x:[1, 42] |
|
|
222 |
* @param Data: data to write |
|
|
223 |
* @retval None |
|
|
224 |
*/ |
|
|
225 |
void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data) |
|
|
226 |
{ |
|
|
227 |
__IO uint32_t tmp = 0; |
|
|
228 |
|
|
|
229 |
/* Check the parameters */ |
|
|
230 |
assert_param(IS_BKP_DR(BKP_DR)); |
|
|
231 |
|
|
|
232 |
tmp = (uint32_t)BKP_BASE; |
|
|
233 |
tmp += BKP_DR; |
|
|
234 |
|
|
|
235 |
*(__IO uint32_t *) tmp = Data; |
|
|
236 |
} |
|
|
237 |
|
|
|
238 |
/** |
|
|
239 |
* @brief Reads data from the specified Data Backup Register. |
|
|
240 |
* @param BKP_DR: specifies the Data Backup Register. |
|
|
241 |
* This parameter can be BKP_DRx where x:[1, 42] |
|
|
242 |
* @retval The content of the specified Data Backup Register |
|
|
243 |
*/ |
|
|
244 |
uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR) |
|
|
245 |
{ |
|
|
246 |
__IO uint32_t tmp = 0; |
|
|
247 |
|
|
|
248 |
/* Check the parameters */ |
|
|
249 |
assert_param(IS_BKP_DR(BKP_DR)); |
|
|
250 |
|
|
|
251 |
tmp = (uint32_t)BKP_BASE; |
|
|
252 |
tmp += BKP_DR; |
|
|
253 |
|
|
|
254 |
return (*(__IO uint16_t *) tmp); |
|
|
255 |
} |
|
|
256 |
|
|
|
257 |
/** |
|
|
258 |
* @brief Checks whether the Tamper Pin Event flag is set or not. |
|
|
259 |
* @param None |
|
|
260 |
* @retval The new state of the Tamper Pin Event flag (SET or RESET). |
|
|
261 |
*/ |
|
|
262 |
FlagStatus BKP_GetFlagStatus(void) |
|
|
263 |
{ |
|
|
264 |
return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB); |
|
|
265 |
} |
|
|
266 |
|
|
|
267 |
/** |
|
|
268 |
* @brief Clears Tamper Pin Event pending flag. |
|
|
269 |
* @param None |
|
|
270 |
* @retval None |
|
|
271 |
*/ |
|
|
272 |
void BKP_ClearFlag(void) |
|
|
273 |
{ |
|
|
274 |
/* Set CTE bit to clear Tamper Pin Event flag */ |
|
|
275 |
BKP->CSR |= CSR_CTE_Set; |
|
|
276 |
} |
|
|
277 |
|
|
|
278 |
/** |
|
|
279 |
* @brief Checks whether the Tamper Pin Interrupt has occurred or not. |
|
|
280 |
* @param None |
|
|
281 |
* @retval The new state of the Tamper Pin Interrupt (SET or RESET). |
|
|
282 |
*/ |
|
|
283 |
ITStatus BKP_GetITStatus(void) |
|
|
284 |
{ |
|
|
285 |
return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB); |
|
|
286 |
} |
|
|
287 |
|
|
|
288 |
/** |
|
|
289 |
* @brief Clears Tamper Pin Interrupt pending bit. |
|
|
290 |
* @param None |
|
|
291 |
* @retval None |
|
|
292 |
*/ |
|
|
293 |
void BKP_ClearITPendingBit(void) |
|
|
294 |
{ |
|
|
295 |
/* Set CTI bit to clear Tamper Pin Interrupt pending bit */ |
|
|
296 |
BKP->CSR |= CSR_CTI_Set; |
|
|
297 |
} |
|
|
298 |
|
|
|
299 |
/** |
|
|
300 |
* @} |
|
|
301 |
*/ |
|
|
302 |
|
|
|
303 |
/** |
|
|
304 |
* @} |
|
|
305 |
*/ |
|
|
306 |
|
|
|
307 |
/** |
|
|
308 |
* @} |
|
|
309 |
*/ |
|
|
310 |
|
|
|
311 |
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ |