Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / lib / main / STM32F1 / Drivers / STM32F10x_StdPeriph_Driver / src / stm32f10x_bkp.c
blob997eecc9e2214c29a8903bb01393a40c81ab4446
1 /**
2 ******************************************************************************
3 * @file stm32f10x_bkp.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 11-March-2011
7 * @brief This file provides all the BKP firmware functions.
8 ******************************************************************************
9 * @attention
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.
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x_bkp.h"
24 #include "stm32f10x_rcc.h"
26 /** @addtogroup STM32F10x_StdPeriph_Driver
27 * @{
30 /** @defgroup BKP
31 * @brief BKP driver modules
32 * @{
35 /** @defgroup BKP_Private_TypesDefinitions
36 * @{
39 /**
40 * @}
43 /** @defgroup BKP_Private_Defines
44 * @{
47 /* ------------ BKP registers bit address in the alias region --------------- */
48 #define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
50 /* --- CR Register ----*/
52 /* Alias word address of TPAL bit */
53 #define CR_OFFSET (BKP_OFFSET + 0x30)
54 #define TPAL_BitNumber 0x01
55 #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
57 /* Alias word address of TPE bit */
58 #define TPE_BitNumber 0x00
59 #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
61 /* --- CSR Register ---*/
63 /* Alias word address of TPIE bit */
64 #define CSR_OFFSET (BKP_OFFSET + 0x34)
65 #define TPIE_BitNumber 0x02
66 #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
68 /* Alias word address of TIF bit */
69 #define TIF_BitNumber 0x09
70 #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
72 /* Alias word address of TEF bit */
73 #define TEF_BitNumber 0x08
74 #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
76 /* ---------------------- BKP registers bit mask ------------------------ */
78 /* RTCCR register bit mask */
79 #define RTCCR_CAL_MASK ((uint16_t)0xFF80)
80 #define RTCCR_MASK ((uint16_t)0xFC7F)
82 /**
83 * @}
84 */
87 /** @defgroup BKP_Private_Macros
88 * @{
91 /**
92 * @}
95 /** @defgroup BKP_Private_Variables
96 * @{
99 /**
100 * @}
103 /** @defgroup BKP_Private_FunctionPrototypes
104 * @{
108 * @}
111 /** @defgroup BKP_Private_Functions
112 * @{
116 * @brief Deinitializes the BKP peripheral registers to their default reset values.
117 * @param None
118 * @retval None
120 void BKP_DeInit(void)
122 RCC_BackupResetCmd(ENABLE);
123 RCC_BackupResetCmd(DISABLE);
127 * @brief Configures the Tamper Pin active level.
128 * @param BKP_TamperPinLevel: specifies the Tamper Pin active level.
129 * This parameter can be one of the following values:
130 * @arg BKP_TamperPinLevel_High: Tamper pin active on high level
131 * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
132 * @retval None
134 void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)
136 /* Check the parameters */
137 assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
138 *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;
142 * @brief Enables or disables the Tamper Pin activation.
143 * @param NewState: new state of the Tamper Pin activation.
144 * This parameter can be: ENABLE or DISABLE.
145 * @retval None
147 void BKP_TamperPinCmd(FunctionalState NewState)
149 /* Check the parameters */
150 assert_param(IS_FUNCTIONAL_STATE(NewState));
151 *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;
155 * @brief Enables or disables the Tamper Pin Interrupt.
156 * @param NewState: new state of the Tamper Pin Interrupt.
157 * This parameter can be: ENABLE or DISABLE.
158 * @retval None
160 void BKP_ITConfig(FunctionalState NewState)
162 /* Check the parameters */
163 assert_param(IS_FUNCTIONAL_STATE(NewState));
164 *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;
168 * @brief Select the RTC output source to output on the Tamper pin.
169 * @param BKP_RTCOutputSource: specifies the RTC output source.
170 * This parameter can be one of the following values:
171 * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
172 * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
173 * divided by 64 on the Tamper pin.
174 * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
175 * the Tamper pin.
176 * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
177 * the Tamper pin.
178 * @retval None
180 void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)
182 uint16_t tmpreg = 0;
183 /* Check the parameters */
184 assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));
185 tmpreg = BKP->RTCCR;
186 /* Clear CCO, ASOE and ASOS bits */
187 tmpreg &= RTCCR_MASK;
189 /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */
190 tmpreg |= BKP_RTCOutputSource;
191 /* Store the new value */
192 BKP->RTCCR = tmpreg;
196 * @brief Sets RTC Clock Calibration value.
197 * @param CalibrationValue: specifies the RTC Clock Calibration value.
198 * This parameter must be a number between 0 and 0x7F.
199 * @retval None
201 void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)
203 uint16_t tmpreg = 0;
204 /* Check the parameters */
205 assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
206 tmpreg = BKP->RTCCR;
207 /* Clear CAL[6:0] bits */
208 tmpreg &= RTCCR_CAL_MASK;
209 /* Set CAL[6:0] bits according to CalibrationValue value */
210 tmpreg |= CalibrationValue;
211 /* Store the new value */
212 BKP->RTCCR = tmpreg;
216 * @brief Writes user data to the specified Data Backup Register.
217 * @param BKP_DR: specifies the Data Backup Register.
218 * This parameter can be BKP_DRx where x:[1, 42]
219 * @param Data: data to write
220 * @retval None
222 void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)
224 __IO uint32_t tmp = 0;
226 /* Check the parameters */
227 assert_param(IS_BKP_DR(BKP_DR));
229 tmp = (uint32_t)BKP_BASE;
230 tmp += BKP_DR;
232 *(__IO uint32_t *) tmp = Data;
236 * @brief Reads data from the specified Data Backup Register.
237 * @param BKP_DR: specifies the Data Backup Register.
238 * This parameter can be BKP_DRx where x:[1, 42]
239 * @retval The content of the specified Data Backup Register
241 uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)
243 __IO uint32_t tmp = 0;
245 /* Check the parameters */
246 assert_param(IS_BKP_DR(BKP_DR));
248 tmp = (uint32_t)BKP_BASE;
249 tmp += BKP_DR;
251 return (*(__IO uint16_t *) tmp);
255 * @brief Checks whether the Tamper Pin Event flag is set or not.
256 * @param None
257 * @retval The new state of the Tamper Pin Event flag (SET or RESET).
259 FlagStatus BKP_GetFlagStatus(void)
261 return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);
265 * @brief Clears Tamper Pin Event pending flag.
266 * @param None
267 * @retval None
269 void BKP_ClearFlag(void)
271 /* Set CTE bit to clear Tamper Pin Event flag */
272 BKP->CSR |= BKP_CSR_CTE;
276 * @brief Checks whether the Tamper Pin Interrupt has occurred or not.
277 * @param None
278 * @retval The new state of the Tamper Pin Interrupt (SET or RESET).
280 ITStatus BKP_GetITStatus(void)
282 return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);
286 * @brief Clears Tamper Pin Interrupt pending bit.
287 * @param None
288 * @retval None
290 void BKP_ClearITPendingBit(void)
292 /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
293 BKP->CSR |= BKP_CSR_CTI;
297 * @}
301 * @}
305 * @}
308 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/