STM32F10x Standard Peripherals Library
3.5.0
|
00001 00022 /* Includes ------------------------------------------------------------------*/ 00023 #include "stm32f10x_bkp.h" 00024 #include "stm32f10x_rcc.h" 00025 00047 /* ------------ BKP registers bit address in the alias region --------------- */ 00048 #define BKP_OFFSET (BKP_BASE - PERIPH_BASE) 00049 00050 /* --- CR Register ----*/ 00051 00052 /* Alias word address of TPAL bit */ 00053 #define CR_OFFSET (BKP_OFFSET + 0x30) 00054 #define TPAL_BitNumber 0x01 00055 #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4)) 00056 00057 /* Alias word address of TPE bit */ 00058 #define TPE_BitNumber 0x00 00059 #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4)) 00060 00061 /* --- CSR Register ---*/ 00062 00063 /* Alias word address of TPIE bit */ 00064 #define CSR_OFFSET (BKP_OFFSET + 0x34) 00065 #define TPIE_BitNumber 0x02 00066 #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4)) 00067 00068 /* Alias word address of TIF bit */ 00069 #define TIF_BitNumber 0x09 00070 #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4)) 00071 00072 /* Alias word address of TEF bit */ 00073 #define TEF_BitNumber 0x08 00074 #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4)) 00075 00076 /* ---------------------- BKP registers bit mask ------------------------ */ 00077 00078 /* RTCCR register bit mask */ 00079 #define RTCCR_CAL_MASK ((uint16_t)0xFF80) 00080 #define RTCCR_MASK ((uint16_t)0xFC7F) 00081 00120 void BKP_DeInit(void) 00121 { 00122 RCC_BackupResetCmd(ENABLE); 00123 RCC_BackupResetCmd(DISABLE); 00124 } 00125 00134 void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel) 00135 { 00136 /* Check the parameters */ 00137 assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel)); 00138 *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel; 00139 } 00140 00147 void BKP_TamperPinCmd(FunctionalState NewState) 00148 { 00149 /* Check the parameters */ 00150 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00151 *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState; 00152 } 00153 00160 void BKP_ITConfig(FunctionalState NewState) 00161 { 00162 /* Check the parameters */ 00163 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00164 *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState; 00165 } 00166 00180 void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource) 00181 { 00182 uint16_t tmpreg = 0; 00183 /* Check the parameters */ 00184 assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource)); 00185 tmpreg = BKP->RTCCR; 00186 /* Clear CCO, ASOE and ASOS bits */ 00187 tmpreg &= RTCCR_MASK; 00188 00189 /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */ 00190 tmpreg |= BKP_RTCOutputSource; 00191 /* Store the new value */ 00192 BKP->RTCCR = tmpreg; 00193 } 00194 00201 void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue) 00202 { 00203 uint16_t tmpreg = 0; 00204 /* Check the parameters */ 00205 assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue)); 00206 tmpreg = BKP->RTCCR; 00207 /* Clear CAL[6:0] bits */ 00208 tmpreg &= RTCCR_CAL_MASK; 00209 /* Set CAL[6:0] bits according to CalibrationValue value */ 00210 tmpreg |= CalibrationValue; 00211 /* Store the new value */ 00212 BKP->RTCCR = tmpreg; 00213 } 00214 00222 void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data) 00223 { 00224 __IO uint32_t tmp = 0; 00225 00226 /* Check the parameters */ 00227 assert_param(IS_BKP_DR(BKP_DR)); 00228 00229 tmp = (uint32_t)BKP_BASE; 00230 tmp += BKP_DR; 00231 00232 *(__IO uint32_t *) tmp = Data; 00233 } 00234 00241 uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR) 00242 { 00243 __IO uint32_t tmp = 0; 00244 00245 /* Check the parameters */ 00246 assert_param(IS_BKP_DR(BKP_DR)); 00247 00248 tmp = (uint32_t)BKP_BASE; 00249 tmp += BKP_DR; 00250 00251 return (*(__IO uint16_t *) tmp); 00252 } 00253 00259 FlagStatus BKP_GetFlagStatus(void) 00260 { 00261 return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB); 00262 } 00263 00269 void BKP_ClearFlag(void) 00270 { 00271 /* Set CTE bit to clear Tamper Pin Event flag */ 00272 BKP->CSR |= BKP_CSR_CTE; 00273 } 00274 00280 ITStatus BKP_GetITStatus(void) 00281 { 00282 return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB); 00283 } 00284 00290 void BKP_ClearITPendingBit(void) 00291 { 00292 /* Set CTI bit to clear Tamper Pin Interrupt pending bit */ 00293 BKP->CSR |= BKP_CSR_CTI; 00294 } 00295 00308 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/