2 ******************************************************************************
\r
3 * @file stm32f10x_pwr.c
\r
4 * @author MCD Application Team
\r
6 * @date 11-March-2011
\r
7 * @brief This file provides all the PWR firmware functions.
\r
8 ******************************************************************************
\r
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
\r
19 ******************************************************************************
\r
22 /* Includes ------------------------------------------------------------------*/
\r
23 #include "stm32f10x_pwr.h"
\r
24 #include "stm32f10x_rcc.h"
\r
26 /** @addtogroup STM32F10x_StdPeriph_Driver
\r
31 * @brief PWR driver modules
\r
35 /** @defgroup PWR_Private_TypesDefinitions
\r
43 /** @defgroup PWR_Private_Defines
\r
47 /* --------- PWR registers bit address in the alias region ---------- */
\r
48 #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
\r
50 /* --- CR Register ---*/
\r
52 /* Alias word address of DBP bit */
\r
53 #define CR_OFFSET (PWR_OFFSET + 0x00)
\r
54 #define DBP_BitNumber 0x08
\r
55 #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
\r
57 /* Alias word address of PVDE bit */
\r
58 #define PVDE_BitNumber 0x04
\r
59 #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
\r
61 /* --- CSR Register ---*/
\r
63 /* Alias word address of EWUP bit */
\r
64 #define CSR_OFFSET (PWR_OFFSET + 0x04)
\r
65 #define EWUP_BitNumber 0x08
\r
66 #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
\r
68 /* ------------------ PWR registers bit mask ------------------------ */
\r
70 /* CR register bit mask */
\r
71 #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
\r
72 #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
\r
79 /** @defgroup PWR_Private_Macros
\r
87 /** @defgroup PWR_Private_Variables
\r
95 /** @defgroup PWR_Private_FunctionPrototypes
\r
103 /** @defgroup PWR_Private_Functions
\r
108 * @brief Deinitializes the PWR peripheral registers to their default reset values.
\r
112 void PWR_DeInit(void)
\r
114 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
\r
115 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
\r
119 * @brief Enables or disables access to the RTC and backup registers.
\r
120 * @param NewState: new state of the access to the RTC and backup registers.
\r
121 * This parameter can be: ENABLE or DISABLE.
\r
124 void PWR_BackupAccessCmd(FunctionalState NewState)
\r
126 /* Check the parameters */
\r
127 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
128 *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
\r
132 * @brief Enables or disables the Power Voltage Detector(PVD).
\r
133 * @param NewState: new state of the PVD.
\r
134 * This parameter can be: ENABLE or DISABLE.
\r
137 void PWR_PVDCmd(FunctionalState NewState)
\r
139 /* Check the parameters */
\r
140 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
141 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
\r
145 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
\r
146 * @param PWR_PVDLevel: specifies the PVD detection level
\r
147 * This parameter can be one of the following values:
\r
148 * @arg PWR_PVDLevel_2V2: PVD detection level set to 2.2V
\r
149 * @arg PWR_PVDLevel_2V3: PVD detection level set to 2.3V
\r
150 * @arg PWR_PVDLevel_2V4: PVD detection level set to 2.4V
\r
151 * @arg PWR_PVDLevel_2V5: PVD detection level set to 2.5V
\r
152 * @arg PWR_PVDLevel_2V6: PVD detection level set to 2.6V
\r
153 * @arg PWR_PVDLevel_2V7: PVD detection level set to 2.7V
\r
154 * @arg PWR_PVDLevel_2V8: PVD detection level set to 2.8V
\r
155 * @arg PWR_PVDLevel_2V9: PVD detection level set to 2.9V
\r
158 void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
\r
160 uint32_t tmpreg = 0;
\r
161 /* Check the parameters */
\r
162 assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
\r
164 /* Clear PLS[7:5] bits */
\r
165 tmpreg &= CR_PLS_MASK;
\r
166 /* Set PLS[7:5] bits according to PWR_PVDLevel value */
\r
167 tmpreg |= PWR_PVDLevel;
\r
168 /* Store the new value */
\r
173 * @brief Enables or disables the WakeUp Pin functionality.
\r
174 * @param NewState: new state of the WakeUp Pin functionality.
\r
175 * This parameter can be: ENABLE or DISABLE.
\r
178 void PWR_WakeUpPinCmd(FunctionalState NewState)
\r
180 /* Check the parameters */
\r
181 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
182 *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
\r
186 * @brief Enters STOP mode.
\r
187 * @param PWR_Regulator: specifies the regulator state in STOP mode.
\r
188 * This parameter can be one of the following values:
\r
189 * @arg PWR_Regulator_ON: STOP mode with regulator ON
\r
190 * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
\r
191 * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
\r
192 * This parameter can be one of the following values:
\r
193 * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
\r
194 * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
\r
197 void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
\r
199 uint32_t tmpreg = 0;
\r
200 /* Check the parameters */
\r
201 assert_param(IS_PWR_REGULATOR(PWR_Regulator));
\r
202 assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
\r
204 /* Select the regulator state in STOP mode ---------------------------------*/
\r
206 /* Clear PDDS and LPDS bits */
\r
207 tmpreg &= CR_DS_MASK;
\r
208 /* Set LPDS bit according to PWR_Regulator value */
\r
209 tmpreg |= PWR_Regulator;
\r
210 /* Store the new value */
\r
212 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
213 SCB->SCR |= SCB_SCR_SLEEPDEEP;
\r
215 /* Select STOP mode entry --------------------------------------------------*/
\r
216 if(PWR_STOPEntry == PWR_STOPEntry_WFI)
\r
218 /* Request Wait For Interrupt */
\r
223 /* Request Wait For Event */
\r
227 /* Reset SLEEPDEEP bit of Cortex System Control Register */
\r
228 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
\r
232 * @brief Enters STANDBY mode.
\r
236 void PWR_EnterSTANDBYMode(void)
\r
238 /* Clear Wake-up flag */
\r
239 PWR->CR |= PWR_CR_CWUF;
\r
240 /* Select STANDBY mode */
\r
241 PWR->CR |= PWR_CR_PDDS;
\r
242 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
243 SCB->SCR |= SCB_SCR_SLEEPDEEP;
\r
244 /* This option is used to ensure that store operations are completed */
\r
245 #if defined ( __CC_ARM )
\r
248 /* Request Wait For Interrupt */
\r
253 * @brief Checks whether the specified PWR flag is set or not.
\r
254 * @param PWR_FLAG: specifies the flag to check.
\r
255 * This parameter can be one of the following values:
\r
256 * @arg PWR_FLAG_WU: Wake Up flag
\r
257 * @arg PWR_FLAG_SB: StandBy flag
\r
258 * @arg PWR_FLAG_PVDO: PVD Output
\r
259 * @retval The new state of PWR_FLAG (SET or RESET).
\r
261 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
\r
263 FlagStatus bitstatus = RESET;
\r
264 /* Check the parameters */
\r
265 assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
\r
267 if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
\r
275 /* Return the flag status */
\r
280 * @brief Clears the PWR's pending flags.
\r
281 * @param PWR_FLAG: specifies the flag to clear.
\r
282 * This parameter can be one of the following values:
\r
283 * @arg PWR_FLAG_WU: Wake Up flag
\r
284 * @arg PWR_FLAG_SB: StandBy flag
\r
287 void PWR_ClearFlag(uint32_t PWR_FLAG)
\r
289 /* Check the parameters */
\r
290 assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
\r
292 PWR->CR |= PWR_FLAG << 2;
\r
307 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
\r