Build libraries for stm32l1xx and stm32f10x
[fw/stlink] / example / libs_stm / src / stm32f10x / stm32f10x_pwr.c
diff --git a/example/libs_stm/src/stm32f10x/stm32f10x_pwr.c b/example/libs_stm/src/stm32f10x/stm32f10x_pwr.c
new file mode 100644 (file)
index 0000000..a017ac6
--- /dev/null
@@ -0,0 +1,316 @@
+/**\r
+  ******************************************************************************\r
+  * @file    stm32f10x_pwr.c\r
+  * @author  MCD Application Team\r
+  * @version V3.3.0\r
+  * @date    04/16/2010\r
+  * @brief   This file provides all the PWR 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_pwr.h"\r
+#include "stm32f10x_rcc.h"\r
+\r
+/** @addtogroup STM32F10x_StdPeriph_Driver\r
+  * @{\r
+  */\r
+\r
+/** @defgroup PWR \r
+  * @brief PWR driver modules\r
+  * @{\r
+  */ \r
+\r
+/** @defgroup PWR_Private_TypesDefinitions\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup PWR_Private_Defines\r
+  * @{\r
+  */\r
+\r
+/* --------- PWR registers bit address in the alias region ---------- */\r
+#define PWR_OFFSET               (PWR_BASE - PERIPH_BASE)\r
+\r
+/* --- CR Register ---*/\r
+\r
+/* Alias word address of DBP bit */\r
+#define CR_OFFSET                (PWR_OFFSET + 0x00)\r
+#define DBP_BitNumber            0x08\r
+#define CR_DBP_BB                (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))\r
+\r
+/* Alias word address of PVDE bit */\r
+#define PVDE_BitNumber           0x04\r
+#define CR_PVDE_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))\r
+\r
+/* --- CSR Register ---*/\r
+\r
+/* Alias word address of EWUP bit */\r
+#define CSR_OFFSET               (PWR_OFFSET + 0x04)\r
+#define EWUP_BitNumber           0x08\r
+#define CSR_EWUP_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))\r
+\r
+/* ------------------ PWR registers bit mask ------------------------ */\r
+\r
+/* CR register bit mask */\r
+#define CR_PDDS_Set              ((uint32_t)0x00000002)\r
+#define CR_DS_Mask               ((uint32_t)0xFFFFFFFC)\r
+#define CR_CWUF_Set              ((uint32_t)0x00000004)\r
+#define CR_PLS_Mask              ((uint32_t)0xFFFFFF1F)\r
+\r
+/* --------- Cortex System Control register bit mask ---------------- */\r
+\r
+/* Cortex System Control register address */\r
+#define SCB_SysCtrl              ((uint32_t)0xE000ED10)\r
+\r
+/* SLEEPDEEP bit mask */\r
+#define SysCtrl_SLEEPDEEP_Set    ((uint32_t)0x00000004)\r
+#define SysCtrl_SLEEPDEEP_Reset  ((uint32_t)0xFFFFFFFB)\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup PWR_Private_Macros\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup PWR_Private_Variables\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup PWR_Private_FunctionPrototypes\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup PWR_Private_Functions\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @brief  Deinitializes the PWR peripheral registers to their default reset values.\r
+  * @param  None\r
+  * @retval None\r
+  */\r
+void PWR_DeInit(void)\r
+{\r
+  RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);\r
+  RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);\r
+}\r
+\r
+/**\r
+  * @brief  Enables or disables access to the RTC and backup registers.\r
+  * @param  NewState: new state of the access to the RTC and backup registers.\r
+  *   This parameter can be: ENABLE or DISABLE.\r
+  * @retval None\r
+  */\r
+void PWR_BackupAccessCmd(FunctionalState NewState)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+  *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;\r
+}\r
+\r
+/**\r
+  * @brief  Enables or disables the Power Voltage Detector(PVD).\r
+  * @param  NewState: new state of the PVD.\r
+  *   This parameter can be: ENABLE or DISABLE.\r
+  * @retval None\r
+  */\r
+void PWR_PVDCmd(FunctionalState NewState)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+  *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;\r
+}\r
+\r
+/**\r
+  * @brief  Configures the voltage threshold detected by the Power Voltage Detector(PVD).\r
+  * @param  PWR_PVDLevel: specifies the PVD detection level\r
+  *   This parameter can be one of the following values:\r
+  *     @arg PWR_PVDLevel_2V2: PVD detection level set to 2.2V\r
+  *     @arg PWR_PVDLevel_2V3: PVD detection level set to 2.3V\r
+  *     @arg PWR_PVDLevel_2V4: PVD detection level set to 2.4V\r
+  *     @arg PWR_PVDLevel_2V5: PVD detection level set to 2.5V\r
+  *     @arg PWR_PVDLevel_2V6: PVD detection level set to 2.6V\r
+  *     @arg PWR_PVDLevel_2V7: PVD detection level set to 2.7V\r
+  *     @arg PWR_PVDLevel_2V8: PVD detection level set to 2.8V\r
+  *     @arg PWR_PVDLevel_2V9: PVD detection level set to 2.9V\r
+  * @retval None\r
+  */\r
+void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)\r
+{\r
+  uint32_t tmpreg = 0;\r
+  /* Check the parameters */\r
+  assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));\r
+  tmpreg = PWR->CR;\r
+  /* Clear PLS[7:5] bits */\r
+  tmpreg &= CR_PLS_Mask;\r
+  /* Set PLS[7:5] bits according to PWR_PVDLevel value */\r
+  tmpreg |= PWR_PVDLevel;\r
+  /* Store the new value */\r
+  PWR->CR = tmpreg;\r
+}\r
+\r
+/**\r
+  * @brief  Enables or disables the WakeUp Pin functionality.\r
+  * @param  NewState: new state of the WakeUp Pin functionality.\r
+  *   This parameter can be: ENABLE or DISABLE.\r
+  * @retval None\r
+  */\r
+void PWR_WakeUpPinCmd(FunctionalState NewState)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_FUNCTIONAL_STATE(NewState));\r
+  *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;\r
+}\r
+\r
+/**\r
+  * @brief  Enters STOP mode.\r
+  * @param  PWR_Regulator: specifies the regulator state in STOP mode.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg PWR_Regulator_ON: STOP mode with regulator ON\r
+  *     @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode\r
+  * @param  PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction\r
+  *     @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction\r
+  * @retval None\r
+  */\r
+void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)\r
+{\r
+  uint32_t tmpreg = 0;\r
+  /* Check the parameters */\r
+  assert_param(IS_PWR_REGULATOR(PWR_Regulator));\r
+  assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));\r
+  \r
+  /* Select the regulator state in STOP mode ---------------------------------*/\r
+  tmpreg = PWR->CR;\r
+  /* Clear PDDS and LPDS bits */\r
+  tmpreg &= CR_DS_Mask;\r
+  /* Set LPDS bit according to PWR_Regulator value */\r
+  tmpreg |= PWR_Regulator;\r
+  /* Store the new value */\r
+  PWR->CR = tmpreg;\r
+  /* Set SLEEPDEEP bit of Cortex System Control Register */\r
+  *(__IO uint32_t *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;\r
+  \r
+  /* Select STOP mode entry --------------------------------------------------*/\r
+  if(PWR_STOPEntry == PWR_STOPEntry_WFI)\r
+  {   \r
+    /* Request Wait For Interrupt */\r
+    __WFI();\r
+  }\r
+  else\r
+  {\r
+    /* Request Wait For Event */\r
+    __WFE();\r
+  }\r
+  \r
+  /* Reset SLEEPDEEP bit of Cortex System Control Register */\r
+  *(__IO uint32_t *) SCB_SysCtrl &= SysCtrl_SLEEPDEEP_Reset;  \r
+}\r
+\r
+/**\r
+  * @brief  Enters STANDBY mode.\r
+  * @param  None\r
+  * @retval None\r
+  */\r
+void PWR_EnterSTANDBYMode(void)\r
+{\r
+  /* Clear Wake-up flag */\r
+  PWR->CR |= CR_CWUF_Set;\r
+  /* Select STANDBY mode */\r
+  PWR->CR |= CR_PDDS_Set;\r
+  /* Set SLEEPDEEP bit of Cortex System Control Register */\r
+  *(__IO uint32_t *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;\r
+/* This option is used to ensure that store operations are completed */\r
+#if defined ( __CC_ARM   )\r
+  __force_stores();\r
+#endif\r
+  /* Request Wait For Interrupt */\r
+  __WFI();\r
+}\r
+\r
+/**\r
+  * @brief  Checks whether the specified PWR flag is set or not.\r
+  * @param  PWR_FLAG: specifies the flag to check.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg PWR_FLAG_WU: Wake Up flag\r
+  *     @arg PWR_FLAG_SB: StandBy flag\r
+  *     @arg PWR_FLAG_PVDO: PVD Output\r
+  * @retval The new state of PWR_FLAG (SET or RESET).\r
+  */\r
+FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)\r
+{\r
+  FlagStatus bitstatus = RESET;\r
+  /* Check the parameters */\r
+  assert_param(IS_PWR_GET_FLAG(PWR_FLAG));\r
+  \r
+  if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)\r
+  {\r
+    bitstatus = SET;\r
+  }\r
+  else\r
+  {\r
+    bitstatus = RESET;\r
+  }\r
+  /* Return the flag status */\r
+  return bitstatus;\r
+}\r
+\r
+/**\r
+  * @brief  Clears the PWR's pending flags.\r
+  * @param  PWR_FLAG: specifies the flag to clear.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg PWR_FLAG_WU: Wake Up flag\r
+  *     @arg PWR_FLAG_SB: StandBy flag\r
+  * @retval None\r
+  */\r
+void PWR_ClearFlag(uint32_t PWR_FLAG)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));\r
+         \r
+  PWR->CR |=  PWR_FLAG << 2;\r
+}\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r