2 ******************************************************************************
\r
3 * @file stm32f10x_bkp.c
\r
4 * @author MCD Application Team
\r
6 * @date 11-March-2011
\r
7 * @brief This file provides all the BKP firmware functions.
\r
8 ******************************************************************************
\r
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
\r
19 ******************************************************************************
\r
22 /* Includes ------------------------------------------------------------------*/
\r
23 #include "stm32f10x_bkp.h"
\r
24 #include "stm32f10x_rcc.h"
\r
26 /** @addtogroup STM32F10x_StdPeriph_Driver
\r
31 * @brief BKP driver modules
\r
35 /** @defgroup BKP_Private_TypesDefinitions
\r
43 /** @defgroup BKP_Private_Defines
\r
47 /* ------------ BKP registers bit address in the alias region --------------- */
\r
48 #define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
\r
50 /* --- CR Register ----*/
\r
52 /* Alias word address of TPAL bit */
\r
53 #define CR_OFFSET (BKP_OFFSET + 0x30)
\r
54 #define TPAL_BitNumber 0x01
\r
55 #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
\r
57 /* Alias word address of TPE bit */
\r
58 #define TPE_BitNumber 0x00
\r
59 #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
\r
61 /* --- CSR Register ---*/
\r
63 /* Alias word address of TPIE bit */
\r
64 #define CSR_OFFSET (BKP_OFFSET + 0x34)
\r
65 #define TPIE_BitNumber 0x02
\r
66 #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
\r
68 /* Alias word address of TIF bit */
\r
69 #define TIF_BitNumber 0x09
\r
70 #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
\r
72 /* Alias word address of TEF bit */
\r
73 #define TEF_BitNumber 0x08
\r
74 #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
\r
76 /* ---------------------- BKP registers bit mask ------------------------ */
\r
78 /* RTCCR register bit mask */
\r
79 #define RTCCR_CAL_MASK ((uint16_t)0xFF80)
\r
80 #define RTCCR_MASK ((uint16_t)0xFC7F)
\r
87 /** @defgroup BKP_Private_Macros
\r
95 /** @defgroup BKP_Private_Variables
\r
103 /** @defgroup BKP_Private_FunctionPrototypes
\r
111 /** @defgroup BKP_Private_Functions
\r
116 * @brief Deinitializes the BKP peripheral registers to their default reset values.
\r
120 void BKP_DeInit(void)
\r
122 RCC_BackupResetCmd(ENABLE);
\r
123 RCC_BackupResetCmd(DISABLE);
\r
127 * @brief Configures the Tamper Pin active level.
\r
128 * @param BKP_TamperPinLevel: specifies the Tamper Pin active level.
\r
129 * This parameter can be one of the following values:
\r
130 * @arg BKP_TamperPinLevel_High: Tamper pin active on high level
\r
131 * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
\r
134 void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)
\r
136 /* Check the parameters */
\r
137 assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
\r
138 *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;
\r
142 * @brief Enables or disables the Tamper Pin activation.
\r
143 * @param NewState: new state of the Tamper Pin activation.
\r
144 * This parameter can be: ENABLE or DISABLE.
\r
147 void BKP_TamperPinCmd(FunctionalState NewState)
\r
149 /* Check the parameters */
\r
150 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
151 *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;
\r
155 * @brief Enables or disables the Tamper Pin Interrupt.
\r
156 * @param NewState: new state of the Tamper Pin Interrupt.
\r
157 * This parameter can be: ENABLE or DISABLE.
\r
160 void BKP_ITConfig(FunctionalState NewState)
\r
162 /* Check the parameters */
\r
163 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
164 *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;
\r
168 * @brief Select the RTC output source to output on the Tamper pin.
\r
169 * @param BKP_RTCOutputSource: specifies the RTC output source.
\r
170 * This parameter can be one of the following values:
\r
171 * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
\r
172 * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
\r
173 * divided by 64 on the Tamper pin.
\r
174 * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
\r
176 * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
\r
180 void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)
\r
182 uint16_t tmpreg = 0;
\r
183 /* Check the parameters */
\r
184 assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));
\r
185 tmpreg = BKP->RTCCR;
\r
186 /* Clear CCO, ASOE and ASOS bits */
\r
187 tmpreg &= RTCCR_MASK;
\r
189 /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */
\r
190 tmpreg |= BKP_RTCOutputSource;
\r
191 /* Store the new value */
\r
192 BKP->RTCCR = tmpreg;
\r
196 * @brief Sets RTC Clock Calibration value.
\r
197 * @param CalibrationValue: specifies the RTC Clock Calibration value.
\r
198 * This parameter must be a number between 0 and 0x7F.
\r
201 void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)
\r
203 uint16_t tmpreg = 0;
\r
204 /* Check the parameters */
\r
205 assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
\r
206 tmpreg = BKP->RTCCR;
\r
207 /* Clear CAL[6:0] bits */
\r
208 tmpreg &= RTCCR_CAL_MASK;
\r
209 /* Set CAL[6:0] bits according to CalibrationValue value */
\r
210 tmpreg |= CalibrationValue;
\r
211 /* Store the new value */
\r
212 BKP->RTCCR = tmpreg;
\r
216 * @brief Writes user data to the specified Data Backup Register.
\r
217 * @param BKP_DR: specifies the Data Backup Register.
\r
218 * This parameter can be BKP_DRx where x:[1, 42]
\r
219 * @param Data: data to write
\r
222 void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)
\r
224 __IO uint32_t tmp = 0;
\r
226 /* Check the parameters */
\r
227 assert_param(IS_BKP_DR(BKP_DR));
\r
229 tmp = (uint32_t)BKP_BASE;
\r
232 *(__IO uint32_t *) tmp = Data;
\r
236 * @brief Reads data from the specified Data Backup Register.
\r
237 * @param BKP_DR: specifies the Data Backup Register.
\r
238 * This parameter can be BKP_DRx where x:[1, 42]
\r
239 * @retval The content of the specified Data Backup Register
\r
241 uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)
\r
243 __IO uint32_t tmp = 0;
\r
245 /* Check the parameters */
\r
246 assert_param(IS_BKP_DR(BKP_DR));
\r
248 tmp = (uint32_t)BKP_BASE;
\r
251 return (*(__IO uint16_t *) tmp);
\r
255 * @brief Checks whether the Tamper Pin Event flag is set or not.
\r
257 * @retval The new state of the Tamper Pin Event flag (SET or RESET).
\r
259 FlagStatus BKP_GetFlagStatus(void)
\r
261 return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);
\r
265 * @brief Clears Tamper Pin Event pending flag.
\r
269 void BKP_ClearFlag(void)
\r
271 /* Set CTE bit to clear Tamper Pin Event flag */
\r
272 BKP->CSR |= BKP_CSR_CTE;
\r
276 * @brief Checks whether the Tamper Pin Interrupt has occurred or not.
\r
278 * @retval The new state of the Tamper Pin Interrupt (SET or RESET).
\r
280 ITStatus BKP_GetITStatus(void)
\r
282 return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);
\r
286 * @brief Clears Tamper Pin Interrupt pending bit.
\r
290 void BKP_ClearITPendingBit(void)
\r
292 /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
\r
293 BKP->CSR |= BKP_CSR_CTI;
\r
308 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
\r