Build libraries for stm32l1xx and stm32f10x
[fw/stlink] / example / libs_stm / src / stm32f10x / stm32f10x_bkp.c
diff --git a/example/libs_stm/src/stm32f10x/stm32f10x_bkp.c b/example/libs_stm/src/stm32f10x/stm32f10x_bkp.c
new file mode 100644 (file)
index 0000000..de06564
--- /dev/null
@@ -0,0 +1,311 @@
+/**\r
+  ******************************************************************************\r
+  * @file    stm32f10x_bkp.c\r
+  * @author  MCD Application Team\r
+  * @version V3.3.0\r
+  * @date    04/16/2010\r
+  * @brief   This file provides all the BKP firmware functions.\r
+  ******************************************************************************\r
+  * @copy\r
+  *\r
+  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
+  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
+  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
+  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
+  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
+  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
+  *\r
+  * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
+  */ \r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "stm32f10x_bkp.h"\r
+#include "stm32f10x_rcc.h"\r
+\r
+/** @addtogroup STM32F10x_StdPeriph_Driver\r
+  * @{\r
+  */\r
+\r
+/** @defgroup BKP \r
+  * @brief BKP driver modules\r
+  * @{\r
+  */\r
+\r
+/** @defgroup BKP_Private_TypesDefinitions\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup BKP_Private_Defines\r
+  * @{\r
+  */\r
+\r
+/* ------------ BKP registers bit address in the alias region --------------- */\r
+#define BKP_OFFSET        (BKP_BASE - PERIPH_BASE)\r
+\r
+/* --- CR Register ----*/\r
+\r
+/* Alias word address of TPAL bit */\r
+#define CR_OFFSET         (BKP_OFFSET + 0x30)\r
+#define TPAL_BitNumber    0x01\r
+#define CR_TPAL_BB        (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))\r
+\r
+/* Alias word address of TPE bit */\r
+#define TPE_BitNumber     0x00\r
+#define CR_TPE_BB         (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))\r
+\r
+/* --- CSR Register ---*/\r
+\r
+/* Alias word address of TPIE bit */\r
+#define CSR_OFFSET        (BKP_OFFSET + 0x34)\r
+#define TPIE_BitNumber    0x02\r
+#define CSR_TPIE_BB       (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))\r
+\r
+/* Alias word address of TIF bit */\r
+#define TIF_BitNumber     0x09\r
+#define CSR_TIF_BB        (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))\r
+\r
+/* Alias word address of TEF bit */\r
+#define TEF_BitNumber     0x08\r
+#define CSR_TEF_BB        (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))\r
+\r
+/* ---------------------- BKP registers bit mask ------------------------ */\r
+\r
+/* RTCCR register bit mask */\r
+#define RTCCR_CAL_Mask    ((uint16_t)0xFF80)\r
+#define RTCCR_Mask        ((uint16_t)0xFC7F)\r
+\r
+/* CSR register bit mask */\r
+#define CSR_CTE_Set       ((uint16_t)0x0001)\r
+#define CSR_CTI_Set       ((uint16_t)0x0002)\r
+\r
+/**\r
+  * @}\r
+  */ \r
+\r
+\r
+/** @defgroup BKP_Private_Macros\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup BKP_Private_Variables\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup BKP_Private_FunctionPrototypes\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup BKP_Private_Functions\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @brief  Deinitializes the BKP peripheral registers to their default reset values.\r
+  * @param  None\r
+  * @retval None\r
+  */\r
+void BKP_DeInit(void)\r
+{\r
+  RCC_BackupResetCmd(ENABLE);\r
+  RCC_BackupResetCmd(DISABLE);\r
+}\r
+\r
+/**\r
+  * @brief  Configures the Tamper Pin active level.\r
+  * @param  BKP_TamperPinLevel: specifies the Tamper Pin active level.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg BKP_TamperPinLevel_High: Tamper pin active on high level\r
+  *     @arg BKP_TamperPinLevel_Low: Tamper pin active on low level\r
+  * @retval None\r
+  */\r
+void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));\r
+  *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;\r
+}\r
+\r
+/**\r
+  * @brief  Enables or disables the Tamper Pin activation.\r
+  * @param  NewState: new state of the Tamper Pin activation.\r
+  *   This parameter can be: ENABLE or DISABLE.\r
+  * @retval None\r
+  */\r
+void BKP_TamperPinCmd(FunctionalState NewState)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+  *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;\r
+}\r
+\r
+/**\r
+  * @brief  Enables or disables the Tamper Pin Interrupt.\r
+  * @param  NewState: new state of the Tamper Pin Interrupt.\r
+  *   This parameter can be: ENABLE or DISABLE.\r
+  * @retval None\r
+  */\r
+void BKP_ITConfig(FunctionalState NewState)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+  *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;\r
+}\r
+\r
+/**\r
+  * @brief  Select the RTC output source to output on the Tamper pin.\r
+  * @param  BKP_RTCOutputSource: specifies the RTC output source.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.\r
+  *     @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency\r
+  *                                          divided by 64 on the Tamper pin.\r
+  *     @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on\r
+  *                                     the Tamper pin.\r
+  *     @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on\r
+  *                                      the Tamper pin.  \r
+  * @retval None\r
+  */\r
+void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)\r
+{\r
+  uint16_t tmpreg = 0;\r
+  /* Check the parameters */\r
+  assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));\r
+  tmpreg = BKP->RTCCR;\r
+  /* Clear CCO, ASOE and ASOS bits */\r
+  tmpreg &= RTCCR_Mask;\r
+  \r
+  /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */\r
+  tmpreg |= BKP_RTCOutputSource;\r
+  /* Store the new value */\r
+  BKP->RTCCR = tmpreg;\r
+}\r
+\r
+/**\r
+  * @brief  Sets RTC Clock Calibration value.\r
+  * @param  CalibrationValue: specifies the RTC Clock Calibration value.\r
+  *   This parameter must be a number between 0 and 0x7F.\r
+  * @retval None\r
+  */\r
+void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)\r
+{\r
+  uint16_t tmpreg = 0;\r
+  /* Check the parameters */\r
+  assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));\r
+  tmpreg = BKP->RTCCR;\r
+  /* Clear CAL[6:0] bits */\r
+  tmpreg &= RTCCR_CAL_Mask;\r
+  /* Set CAL[6:0] bits according to CalibrationValue value */\r
+  tmpreg |= CalibrationValue;\r
+  /* Store the new value */\r
+  BKP->RTCCR = tmpreg;\r
+}\r
+\r
+/**\r
+  * @brief  Writes user data to the specified Data Backup Register.\r
+  * @param  BKP_DR: specifies the Data Backup Register.\r
+  *   This parameter can be BKP_DRx where x:[1, 42]\r
+  * @param  Data: data to write\r
+  * @retval None\r
+  */\r
+void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)\r
+{\r
+  __IO uint32_t tmp = 0;\r
+\r
+  /* Check the parameters */\r
+  assert_param(IS_BKP_DR(BKP_DR));\r
+\r
+  tmp = (uint32_t)BKP_BASE; \r
+  tmp += BKP_DR;\r
+\r
+  *(__IO uint32_t *) tmp = Data;\r
+}\r
+\r
+/**\r
+  * @brief  Reads data from the specified Data Backup Register.\r
+  * @param  BKP_DR: specifies the Data Backup Register.\r
+  *   This parameter can be BKP_DRx where x:[1, 42]\r
+  * @retval The content of the specified Data Backup Register\r
+  */\r
+uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)\r
+{\r
+  __IO uint32_t tmp = 0;\r
+\r
+  /* Check the parameters */\r
+  assert_param(IS_BKP_DR(BKP_DR));\r
+\r
+  tmp = (uint32_t)BKP_BASE; \r
+  tmp += BKP_DR;\r
+\r
+  return (*(__IO uint16_t *) tmp);\r
+}\r
+\r
+/**\r
+  * @brief  Checks whether the Tamper Pin Event flag is set or not.\r
+  * @param  None\r
+  * @retval The new state of the Tamper Pin Event flag (SET or RESET).\r
+  */\r
+FlagStatus BKP_GetFlagStatus(void)\r
+{\r
+  return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);\r
+}\r
+\r
+/**\r
+  * @brief  Clears Tamper Pin Event pending flag.\r
+  * @param  None\r
+  * @retval None\r
+  */\r
+void BKP_ClearFlag(void)\r
+{\r
+  /* Set CTE bit to clear Tamper Pin Event flag */\r
+  BKP->CSR |= CSR_CTE_Set;\r
+}\r
+\r
+/**\r
+  * @brief  Checks whether the Tamper Pin Interrupt has occurred or not.\r
+  * @param  None\r
+  * @retval The new state of the Tamper Pin Interrupt (SET or RESET).\r
+  */\r
+ITStatus BKP_GetITStatus(void)\r
+{\r
+  return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);\r
+}\r
+\r
+/**\r
+  * @brief  Clears Tamper Pin Interrupt pending bit.\r
+  * @param  None\r
+  * @retval None\r
+  */\r
+void BKP_ClearITPendingBit(void)\r
+{\r
+  /* Set CTI bit to clear Tamper Pin Interrupt pending bit */\r
+  BKP->CSR |= CSR_CTI_Set;\r
+}\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r