stm32f10x_bkp.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f10x_bkp.c
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   This file provides all the BKP firmware functions.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x_bkp.h"
00023 #include "stm32f10x_rcc.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Driver
00026   * @{
00027   */
00028 
00029 /** @defgroup BKP 
00030   * @brief BKP driver modules
00031   * @{
00032   */
00033 
00034 /** @defgroup BKP_Private_TypesDefinitions
00035   * @{
00036   */
00037 
00038 /**
00039   * @}
00040   */
00041 
00042 /** @defgroup BKP_Private_Defines
00043   * @{
00044   */
00045 
00046 /* ------------ BKP registers bit address in the alias region --------------- */
00047 #define BKP_OFFSET        (BKP_BASE - PERIPH_BASE)
00048 
00049 /* --- CR Register ----*/
00050 
00051 /* Alias word address of TPAL bit */
00052 #define CR_OFFSET         (BKP_OFFSET + 0x30)
00053 #define TPAL_BitNumber    0x01
00054 #define CR_TPAL_BB        (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
00055 
00056 /* Alias word address of TPE bit */
00057 #define TPE_BitNumber     0x00
00058 #define CR_TPE_BB         (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
00059 
00060 /* --- CSR Register ---*/
00061 
00062 /* Alias word address of TPIE bit */
00063 #define CSR_OFFSET        (BKP_OFFSET + 0x34)
00064 #define TPIE_BitNumber    0x02
00065 #define CSR_TPIE_BB       (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
00066 
00067 /* Alias word address of TIF bit */
00068 #define TIF_BitNumber     0x09
00069 #define CSR_TIF_BB        (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
00070 
00071 /* Alias word address of TEF bit */
00072 #define TEF_BitNumber     0x08
00073 #define CSR_TEF_BB        (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
00074 
00075 /* ---------------------- BKP registers bit mask ------------------------ */
00076 
00077 /* RTCCR register bit mask */
00078 #define RTCCR_CAL_MASK    ((uint16_t)0xFF80)
00079 #define RTCCR_MASK        ((uint16_t)0xFC7F)
00080 
00081 /**
00082   * @}
00083   */ 
00084 
00085 
00086 /** @defgroup BKP_Private_Macros
00087   * @{
00088   */
00089 
00090 /**
00091   * @}
00092   */
00093 
00094 /** @defgroup BKP_Private_Variables
00095   * @{
00096   */
00097 
00098 /**
00099   * @}
00100   */
00101 
00102 /** @defgroup BKP_Private_FunctionPrototypes
00103   * @{
00104   */
00105 
00106 /**
00107   * @}
00108   */
00109 
00110 /** @defgroup BKP_Private_Functions
00111   * @{
00112   */
00113 
00114 /**
00115   * @brief  Deinitializes the BKP peripheral registers to their default reset values.
00116   * @param  None
00117   * @retval None
00118   */
00119 void BKP_DeInit(void)
00120 {
00121   RCC_BackupResetCmd(ENABLE);
00122   RCC_BackupResetCmd(DISABLE);
00123 }
00124 
00125 /**
00126   * @brief  Configures the Tamper Pin active level.
00127   * @param  BKP_TamperPinLevel: specifies the Tamper Pin active level.
00128   *   This parameter can be one of the following values:
00129   *     @arg BKP_TamperPinLevel_High: Tamper pin active on high level
00130   *     @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
00131   * @retval None
00132   */
00133 void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)
00134 {
00135   /* Check the parameters */
00136   assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
00137   *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;
00138 }
00139 
00140 /**
00141   * @brief  Enables or disables the Tamper Pin activation.
00142   * @param  NewState: new state of the Tamper Pin activation.
00143   *   This parameter can be: ENABLE or DISABLE.
00144   * @retval None
00145   */
00146 void BKP_TamperPinCmd(FunctionalState NewState)
00147 {
00148   /* Check the parameters */
00149   assert_param(IS_FUNCTIONAL_STATE(NewState));
00150   *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;
00151 }
00152 
00153 /**
00154   * @brief  Enables or disables the Tamper Pin Interrupt.
00155   * @param  NewState: new state of the Tamper Pin Interrupt.
00156   *   This parameter can be: ENABLE or DISABLE.
00157   * @retval None
00158   */
00159 void BKP_ITConfig(FunctionalState NewState)
00160 {
00161   /* Check the parameters */
00162   assert_param(IS_FUNCTIONAL_STATE(NewState));
00163   *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;
00164 }
00165 
00166 /**
00167   * @brief  Select the RTC output source to output on the Tamper pin.
00168   * @param  BKP_RTCOutputSource: specifies the RTC output source.
00169   *   This parameter can be one of the following values:
00170   *     @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
00171   *     @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
00172   *                                          divided by 64 on the Tamper pin.
00173   *     @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
00174   *                                     the Tamper pin.
00175   *     @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
00176   *                                      the Tamper pin.  
00177   * @retval None
00178   */
00179 void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)
00180 {
00181   uint16_t tmpreg = 0;
00182   /* Check the parameters */
00183   assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));
00184   tmpreg = BKP->RTCCR;
00185   /* Clear CCO, ASOE and ASOS bits */
00186   tmpreg &= RTCCR_MASK;
00187   
00188   /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */
00189   tmpreg |= BKP_RTCOutputSource;
00190   /* Store the new value */
00191   BKP->RTCCR = tmpreg;
00192 }
00193 
00194 /**
00195   * @brief  Sets RTC Clock Calibration value.
00196   * @param  CalibrationValue: specifies the RTC Clock Calibration value.
00197   *   This parameter must be a number between 0 and 0x7F.
00198   * @retval None
00199   */
00200 void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)
00201 {
00202   uint16_t tmpreg = 0;
00203   /* Check the parameters */
00204   assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
00205   tmpreg = BKP->RTCCR;
00206   /* Clear CAL[6:0] bits */
00207   tmpreg &= RTCCR_CAL_MASK;
00208   /* Set CAL[6:0] bits according to CalibrationValue value */
00209   tmpreg |= CalibrationValue;
00210   /* Store the new value */
00211   BKP->RTCCR = tmpreg;
00212 }
00213 
00214 /**
00215   * @brief  Writes user data to the specified Data Backup Register.
00216   * @param  BKP_DR: specifies the Data Backup Register.
00217   *   This parameter can be BKP_DRx where x:[1, 42]
00218   * @param  Data: data to write
00219   * @retval None
00220   */
00221 void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)
00222 {
00223   __IO uint32_t tmp = 0;
00224 
00225   /* Check the parameters */
00226   assert_param(IS_BKP_DR(BKP_DR));
00227 
00228   tmp = (uint32_t)BKP_BASE; 
00229   tmp += BKP_DR;
00230 
00231   *(__IO uint32_t *) tmp = Data;
00232 }
00233 
00234 /**
00235   * @brief  Reads data from the specified Data Backup Register.
00236   * @param  BKP_DR: specifies the Data Backup Register.
00237   *   This parameter can be BKP_DRx where x:[1, 42]
00238   * @retval The content of the specified Data Backup Register
00239   */
00240 uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)
00241 {
00242   __IO uint32_t tmp = 0;
00243 
00244   /* Check the parameters */
00245   assert_param(IS_BKP_DR(BKP_DR));
00246 
00247   tmp = (uint32_t)BKP_BASE; 
00248   tmp += BKP_DR;
00249 
00250   return (*(__IO uint16_t *) tmp);
00251 }
00252 
00253 /**
00254   * @brief  Checks whether the Tamper Pin Event flag is set or not.
00255   * @param  None
00256   * @retval The new state of the Tamper Pin Event flag (SET or RESET).
00257   */
00258 FlagStatus BKP_GetFlagStatus(void)
00259 {
00260   return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);
00261 }
00262 
00263 /**
00264   * @brief  Clears Tamper Pin Event pending flag.
00265   * @param  None
00266   * @retval None
00267   */
00268 void BKP_ClearFlag(void)
00269 {
00270   /* Set CTE bit to clear Tamper Pin Event flag */
00271   BKP->CSR |= BKP_CSR_CTE;
00272 }
00273 
00274 /**
00275   * @brief  Checks whether the Tamper Pin Interrupt has occurred or not.
00276   * @param  None
00277   * @retval The new state of the Tamper Pin Interrupt (SET or RESET).
00278   */
00279 ITStatus BKP_GetITStatus(void)
00280 {
00281   return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);
00282 }
00283 
00284 /**
00285   * @brief  Clears Tamper Pin Interrupt pending bit.
00286   * @param  None
00287   * @retval None
00288   */
00289 void BKP_ClearITPendingBit(void)
00290 {
00291   /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
00292   BKP->CSR |= BKP_CSR_CTI;
00293 }
00294 
00295 /**
00296   * @}
00297   */
00298 
00299 /**
00300   * @}
00301   */
00302 
00303 /**
00304   * @}
00305   */
00306 
00307 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32