1 |
608 |
jeremybenn |
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
2 |
|
|
* File Name : stm32f10x_bkp.c
|
3 |
|
|
* Author : MCD Application Team
|
4 |
|
|
* Date First Issued : 09/29/2006
|
5 |
|
|
* Description : This file provides all the BKP firmware functions.
|
6 |
|
|
********************************************************************************
|
7 |
|
|
* History:
|
8 |
|
|
* 04/02/2007: V0.2
|
9 |
|
|
* 02/05/2007: V0.1
|
10 |
|
|
* 09/29/2006: V0.01
|
11 |
|
|
********************************************************************************
|
12 |
|
|
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
13 |
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
14 |
|
|
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
15 |
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
16 |
|
|
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
17 |
|
|
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
18 |
|
|
*******************************************************************************/
|
19 |
|
|
|
20 |
|
|
/* Includes ------------------------------------------------------------------*/
|
21 |
|
|
#include "stm32f10x_bkp.h"
|
22 |
|
|
#include "stm32f10x_rcc.h"
|
23 |
|
|
|
24 |
|
|
/* Private typedef -----------------------------------------------------------*/
|
25 |
|
|
/* Private define ------------------------------------------------------------*/
|
26 |
|
|
/* ------------ BKP registers bit address in the alias region ----------- */
|
27 |
|
|
#define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
|
28 |
|
|
|
29 |
|
|
/* --- RTCCR Register ---*/
|
30 |
|
|
/* Alias word address of CCO bit */
|
31 |
|
|
#define RTCCR_OFFSET (BKP_OFFSET + 0x2C)
|
32 |
|
|
#define CCO_BitNumber 0x07
|
33 |
|
|
#define RTCCR_CCO_BB (PERIPH_BB_BASE + (RTCCR_OFFSET * 32) + (CCO_BitNumber * 4))
|
34 |
|
|
|
35 |
|
|
/* --- CR Register ---*/
|
36 |
|
|
/* Alias word address of TPAL bit */
|
37 |
|
|
#define CR_OFFSET (BKP_OFFSET + 0x30)
|
38 |
|
|
#define TPAL_BitNumber 0x01
|
39 |
|
|
#define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
|
40 |
|
|
|
41 |
|
|
/* Alias word address of TPE bit */
|
42 |
|
|
#define TPE_BitNumber 0x00
|
43 |
|
|
#define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
|
44 |
|
|
|
45 |
|
|
/* --- CSR Register ---*/
|
46 |
|
|
/* Alias word address of TPIE bit */
|
47 |
|
|
#define CSR_OFFSET (BKP_OFFSET + 0x34)
|
48 |
|
|
#define TPIE_BitNumber 0x02
|
49 |
|
|
#define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
|
50 |
|
|
|
51 |
|
|
/* Alias word address of TIF bit */
|
52 |
|
|
#define TIF_BitNumber 0x09
|
53 |
|
|
#define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
|
54 |
|
|
|
55 |
|
|
/* Alias word address of TEF bit */
|
56 |
|
|
#define TEF_BitNumber 0x08
|
57 |
|
|
#define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
/* ---------------------- BKP registers bit mask ------------------------ */
|
61 |
|
|
/* RTCCR register bit mask */
|
62 |
|
|
#define RTCCR_CAL_Mask ((u16)0xFF80)
|
63 |
|
|
|
64 |
|
|
/* CSR register bit mask */
|
65 |
|
|
#define CSR_CTE_Set ((u16)0x0001)
|
66 |
|
|
#define CSR_CTI_Set ((u16)0x0002)
|
67 |
|
|
|
68 |
|
|
/* Private macro -------------------------------------------------------------*/
|
69 |
|
|
/* Private variables ---------------------------------------------------------*/
|
70 |
|
|
/* Private function prototypes -----------------------------------------------*/
|
71 |
|
|
/* Private functions ---------------------------------------------------------*/
|
72 |
|
|
|
73 |
|
|
/*******************************************************************************
|
74 |
|
|
* Function Name : BKP_DeInit
|
75 |
|
|
* Description : Deinitializes the BKP peripheral registers to their default
|
76 |
|
|
* reset values.
|
77 |
|
|
* Input : None
|
78 |
|
|
* Output : None
|
79 |
|
|
* Return : None
|
80 |
|
|
*******************************************************************************/
|
81 |
|
|
void BKP_DeInit(void)
|
82 |
|
|
{
|
83 |
|
|
RCC_BackupResetCmd(ENABLE);
|
84 |
|
|
RCC_BackupResetCmd(DISABLE);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
/*******************************************************************************
|
88 |
|
|
* Function Name : BKP_TamperPinLevelConfig
|
89 |
|
|
* Description : Configures the Tamper Pin active level.
|
90 |
|
|
* Input : - BKP_TamperPinLevel: specifies the Tamper Pin active level.
|
91 |
|
|
* This parameter can be one of the following values:
|
92 |
|
|
* - BKP_TamperPinLevel_High: Tamper pin active on high level
|
93 |
|
|
* - BKP_TamperPinLevel_Low: Tamper pin active on low level
|
94 |
|
|
* Output : None
|
95 |
|
|
* Return : None
|
96 |
|
|
*******************************************************************************/
|
97 |
|
|
void BKP_TamperPinLevelConfig(u16 BKP_TamperPinLevel)
|
98 |
|
|
{
|
99 |
|
|
/* Check the parameters */
|
100 |
|
|
assert(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
|
101 |
|
|
|
102 |
|
|
*(vu32 *) CR_TPAL_BB = BKP_TamperPinLevel;
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
/*******************************************************************************
|
106 |
|
|
* Function Name : BKP_TamperPinCmd
|
107 |
|
|
* Description : Enables or disables the Tamper Pin activation.
|
108 |
|
|
* Input : - NewState: new state of the Tamper Pin activation.
|
109 |
|
|
* This parameter can be: ENABLE or DISABLE.
|
110 |
|
|
* Output : None
|
111 |
|
|
* Return : None
|
112 |
|
|
*******************************************************************************/
|
113 |
|
|
void BKP_TamperPinCmd(FunctionalState NewState)
|
114 |
|
|
{
|
115 |
|
|
/* Check the parameters */
|
116 |
|
|
assert(IS_FUNCTIONAL_STATE(NewState));
|
117 |
|
|
|
118 |
|
|
*(vu32 *) CR_TPE_BB = (u32)NewState;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
/*******************************************************************************
|
122 |
|
|
* Function Name : BKP_ITConfig
|
123 |
|
|
* Description : Enables or disables the Tamper Pin Interrupt.
|
124 |
|
|
* Input : - NewState: new state of the Tamper Pin Interrupt.
|
125 |
|
|
* This parameter can be: ENABLE or DISABLE.
|
126 |
|
|
* Output : None
|
127 |
|
|
* Return : None
|
128 |
|
|
*******************************************************************************/
|
129 |
|
|
void BKP_ITConfig(FunctionalState NewState)
|
130 |
|
|
{
|
131 |
|
|
/* Check the parameters */
|
132 |
|
|
assert(IS_FUNCTIONAL_STATE(NewState));
|
133 |
|
|
|
134 |
|
|
*(vu32 *) CSR_TPIE_BB = (u32)NewState;
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
/*******************************************************************************
|
138 |
|
|
* Function Name : BKP_RTCCalibrationClockOutputCmd
|
139 |
|
|
* Description : Enables or disables the output of the Calibration Clock.
|
140 |
|
|
* Input : - NewState: new state of the Calibration Clock output.
|
141 |
|
|
* This parameter can be: ENABLE or DISABLE.
|
142 |
|
|
* Output : None
|
143 |
|
|
* Return : None
|
144 |
|
|
*******************************************************************************/
|
145 |
|
|
void BKP_RTCCalibrationClockOutputCmd(FunctionalState NewState)
|
146 |
|
|
{
|
147 |
|
|
/* Check the parameters */
|
148 |
|
|
assert(IS_FUNCTIONAL_STATE(NewState));
|
149 |
|
|
|
150 |
|
|
*(vu32 *) RTCCR_CCO_BB = (u32)NewState;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
/*******************************************************************************
|
154 |
|
|
* Function Name : BKP_SetRTCCalibrationValue
|
155 |
|
|
* Description : Sets RTC Clock Calibration value.
|
156 |
|
|
* Input : - CalibrationValue: specifies the RTC Clock Calibration value.
|
157 |
|
|
* This parameter must be a number between 0 and 0x7F.
|
158 |
|
|
* Output : None
|
159 |
|
|
* Return : None
|
160 |
|
|
*******************************************************************************/
|
161 |
|
|
void BKP_SetRTCCalibrationValue(u8 CalibrationValue)
|
162 |
|
|
{
|
163 |
|
|
u16 tmpreg = 0;
|
164 |
|
|
|
165 |
|
|
/* Check the parameters */
|
166 |
|
|
assert(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
|
167 |
|
|
|
168 |
|
|
tmpreg = BKP->RTCCR;
|
169 |
|
|
|
170 |
|
|
/* Clear CAL[6:0] bits */
|
171 |
|
|
tmpreg &= RTCCR_CAL_Mask;
|
172 |
|
|
|
173 |
|
|
/* Set CAL[6:0] bits according to CalibrationValue value */
|
174 |
|
|
tmpreg |= CalibrationValue;
|
175 |
|
|
|
176 |
|
|
/* Store the new value */
|
177 |
|
|
BKP->RTCCR = tmpreg;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
/*******************************************************************************
|
181 |
|
|
* Function Name : BKP_WriteBackupRegister
|
182 |
|
|
* Description : Writes user data to the specified Data Backup Register.
|
183 |
|
|
* Input : - BKP_DR: specifies the Data Backup Register.
|
184 |
|
|
* This parameter can be BKP_DRx where x:[1, 10]
|
185 |
|
|
* - Data: data to write
|
186 |
|
|
* Output : None
|
187 |
|
|
* Return : None
|
188 |
|
|
*******************************************************************************/
|
189 |
|
|
void BKP_WriteBackupRegister(u16 BKP_DR, u16 Data)
|
190 |
|
|
{
|
191 |
|
|
/* Check the parameters */
|
192 |
|
|
assert(IS_BKP_DR(BKP_DR));
|
193 |
|
|
|
194 |
|
|
*(vu16 *) (BKP_BASE + BKP_DR) = Data;
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
/*******************************************************************************
|
198 |
|
|
* Function Name : BKP_ReadBackupRegister
|
199 |
|
|
* Description : Reads data from the specified Data Backup Register.
|
200 |
|
|
* Input : - BKP_DR: specifies the Data Backup Register.
|
201 |
|
|
* This parameter can be BKP_DRx where x:[1, 10]
|
202 |
|
|
* Output : None
|
203 |
|
|
* Return : The content of the specified Data Backup Register
|
204 |
|
|
*******************************************************************************/
|
205 |
|
|
u16 BKP_ReadBackupRegister(u16 BKP_DR)
|
206 |
|
|
{
|
207 |
|
|
/* Check the parameters */
|
208 |
|
|
assert(IS_BKP_DR(BKP_DR));
|
209 |
|
|
|
210 |
|
|
return (*(vu16 *) (BKP_BASE + BKP_DR));
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
/*******************************************************************************
|
214 |
|
|
* Function Name : BKP_GetFlagStatus
|
215 |
|
|
* Description : Checks whether the Tamper Pin Event flag is set or not.
|
216 |
|
|
* Input : None
|
217 |
|
|
* Output : None
|
218 |
|
|
* Return : The new state of the Tamper Pin Event flag (SET or RESET).
|
219 |
|
|
*******************************************************************************/
|
220 |
|
|
FlagStatus BKP_GetFlagStatus(void)
|
221 |
|
|
{
|
222 |
|
|
return (FlagStatus)(*(vu32 *) CSR_TEF_BB);
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
/*******************************************************************************
|
226 |
|
|
* Function Name : BKP_ClearFlag
|
227 |
|
|
* Description : Clears Tamper Pin Event pending flag.
|
228 |
|
|
* Input : None
|
229 |
|
|
* Output : None
|
230 |
|
|
* Return : None
|
231 |
|
|
*******************************************************************************/
|
232 |
|
|
void BKP_ClearFlag(void)
|
233 |
|
|
{
|
234 |
|
|
/* Set CTE bit to clear Tamper Pin Event flag */
|
235 |
|
|
BKP->CSR |= CSR_CTE_Set;
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
/*******************************************************************************
|
239 |
|
|
* Function Name : BKP_GetITStatus
|
240 |
|
|
* Description : Checks whether the Tamper Pin Interrupt has occurred or not.
|
241 |
|
|
* Input : None
|
242 |
|
|
* Output : None
|
243 |
|
|
* Return : The new state of the Tamper Pin Interrupt (SET or RESET).
|
244 |
|
|
*******************************************************************************/
|
245 |
|
|
ITStatus BKP_GetITStatus(void)
|
246 |
|
|
{
|
247 |
|
|
return (ITStatus)(*(vu32 *) CSR_TIF_BB);
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
/*******************************************************************************
|
251 |
|
|
* Function Name : BKP_ClearITPendingBit
|
252 |
|
|
* Description : Clears Tamper Pin Interrupt pending bit.
|
253 |
|
|
* Input : None
|
254 |
|
|
* Output : None
|
255 |
|
|
* Return : None
|
256 |
|
|
*******************************************************************************/
|
257 |
|
|
void BKP_ClearITPendingBit(void)
|
258 |
|
|
{
|
259 |
|
|
/* Set CTI bit to clear Tamper Pin Interrupt pending bit */
|
260 |
|
|
BKP->CSR |= CSR_CTI_Set;
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|