STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_pwr.c
Go to the documentation of this file.
00001 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f10x_pwr.h"
00024 #include "stm32f10x_rcc.h"
00025 
00047 /* --------- PWR registers bit address in the alias region ---------- */
00048 #define PWR_OFFSET               (PWR_BASE - PERIPH_BASE)
00049 
00050 /* --- CR Register ---*/
00051 
00052 /* Alias word address of DBP bit */
00053 #define CR_OFFSET                (PWR_OFFSET + 0x00)
00054 #define DBP_BitNumber            0x08
00055 #define CR_DBP_BB                (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
00056 
00057 /* Alias word address of PVDE bit */
00058 #define PVDE_BitNumber           0x04
00059 #define CR_PVDE_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
00060 
00061 /* --- CSR Register ---*/
00062 
00063 /* Alias word address of EWUP bit */
00064 #define CSR_OFFSET               (PWR_OFFSET + 0x04)
00065 #define EWUP_BitNumber           0x08
00066 #define CSR_EWUP_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
00067 
00068 /* ------------------ PWR registers bit mask ------------------------ */
00069 
00070 /* CR register bit mask */
00071 #define CR_DS_MASK               ((uint32_t)0xFFFFFFFC)
00072 #define CR_PLS_MASK              ((uint32_t)0xFFFFFF1F)
00073 
00074 
00112 void PWR_DeInit(void)
00113 {
00114   RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
00115   RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
00116 }
00117 
00124 void PWR_BackupAccessCmd(FunctionalState NewState)
00125 {
00126   /* Check the parameters */
00127   assert_param(IS_FUNCTIONAL_STATE(NewState));
00128   *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
00129 }
00130 
00137 void PWR_PVDCmd(FunctionalState NewState)
00138 {
00139   /* Check the parameters */
00140   assert_param(IS_FUNCTIONAL_STATE(NewState));
00141   *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
00142 }
00143 
00158 void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
00159 {
00160   uint32_t tmpreg = 0;
00161   /* Check the parameters */
00162   assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
00163   tmpreg = PWR->CR;
00164   /* Clear PLS[7:5] bits */
00165   tmpreg &= CR_PLS_MASK;
00166   /* Set PLS[7:5] bits according to PWR_PVDLevel value */
00167   tmpreg |= PWR_PVDLevel;
00168   /* Store the new value */
00169   PWR->CR = tmpreg;
00170 }
00171 
00178 void PWR_WakeUpPinCmd(FunctionalState NewState)
00179 {
00180   /* Check the parameters */
00181   assert_param(IS_FUNCTIONAL_STATE(NewState));
00182   *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
00183 }
00184 
00197 void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
00198 {
00199   uint32_t tmpreg = 0;
00200   /* Check the parameters */
00201   assert_param(IS_PWR_REGULATOR(PWR_Regulator));
00202   assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
00203   
00204   /* Select the regulator state in STOP mode ---------------------------------*/
00205   tmpreg = PWR->CR;
00206   /* Clear PDDS and LPDS bits */
00207   tmpreg &= CR_DS_MASK;
00208   /* Set LPDS bit according to PWR_Regulator value */
00209   tmpreg |= PWR_Regulator;
00210   /* Store the new value */
00211   PWR->CR = tmpreg;
00212   /* Set SLEEPDEEP bit of Cortex System Control Register */
00213   SCB->SCR |= SCB_SCR_SLEEPDEEP;
00214   
00215   /* Select STOP mode entry --------------------------------------------------*/
00216   if(PWR_STOPEntry == PWR_STOPEntry_WFI)
00217   {   
00218     /* Request Wait For Interrupt */
00219     __WFI();
00220   }
00221   else
00222   {
00223     /* Request Wait For Event */
00224     __WFE();
00225   }
00226   
00227   /* Reset SLEEPDEEP bit of Cortex System Control Register */
00228   SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);  
00229 }
00230 
00236 void PWR_EnterSTANDBYMode(void)
00237 {
00238   /* Clear Wake-up flag */
00239   PWR->CR |= PWR_CR_CWUF;
00240   /* Select STANDBY mode */
00241   PWR->CR |= PWR_CR_PDDS;
00242   /* Set SLEEPDEEP bit of Cortex System Control Register */
00243   SCB->SCR |= SCB_SCR_SLEEPDEEP;
00244 /* This option is used to ensure that store operations are completed */
00245 #if defined ( __CC_ARM   )
00246   __force_stores();
00247 #endif
00248   /* Request Wait For Interrupt */
00249   __WFI();
00250 }
00251 
00261 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
00262 {
00263   FlagStatus bitstatus = RESET;
00264   /* Check the parameters */
00265   assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
00266   
00267   if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
00268   {
00269     bitstatus = SET;
00270   }
00271   else
00272   {
00273     bitstatus = RESET;
00274   }
00275   /* Return the flag status */
00276   return bitstatus;
00277 }
00278 
00287 void PWR_ClearFlag(uint32_t PWR_FLAG)
00288 {
00289   /* Check the parameters */
00290   assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
00291          
00292   PWR->CR |=  PWR_FLAG << 2;
00293 }
00294 
00307 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/