2 ******************************************************************************
\r
3 * @file stm32f10x_pwr.c
\r
4 * @author MCD Application Team
\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 2009 STMicroelectronics</center></h2>
\r
21 /* Includes ------------------------------------------------------------------*/
\r
22 #include "stm32f10x_pwr.h"
\r
23 #include "stm32f10x_rcc.h"
\r
25 /** @addtogroup STM32F10x_StdPeriph_Driver
\r
30 * @brief PWR driver modules
\r
34 /** @defgroup PWR_Private_TypesDefinitions
\r
42 /** @defgroup PWR_Private_Defines
\r
46 /* --------- PWR registers bit address in the alias region ---------- */
\r
47 #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
\r
49 /* --- CR Register ---*/
\r
51 /* Alias word address of DBP bit */
\r
52 #define CR_OFFSET (PWR_OFFSET + 0x00)
\r
53 #define DBP_BitNumber 0x08
\r
54 #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
\r
56 /* Alias word address of PVDE bit */
\r
57 #define PVDE_BitNumber 0x04
\r
58 #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
\r
60 /* --- CSR Register ---*/
\r
62 /* Alias word address of EWUP bit */
\r
63 #define CSR_OFFSET (PWR_OFFSET + 0x04)
\r
64 #define EWUP_BitNumber 0x08
\r
65 #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
\r
67 /* ------------------ PWR registers bit mask ------------------------ */
\r
69 /* CR register bit mask */
\r
70 #define CR_PDDS_Set ((uint32_t)0x00000002)
\r
71 #define CR_DS_Mask ((uint32_t)0xFFFFFFFC)
\r
72 #define CR_CWUF_Set ((uint32_t)0x00000004)
\r
73 #define CR_PLS_Mask ((uint32_t)0xFFFFFF1F)
\r
75 /* --------- Cortex System Control register bit mask ---------------- */
\r
77 /* Cortex System Control register address */
\r
78 #define SCB_SysCtrl ((uint32_t)0xE000ED10)
\r
80 /* SLEEPDEEP bit mask */
\r
81 #define SysCtrl_SLEEPDEEP_Set ((uint32_t)0x00000004)
\r
86 /** @defgroup PWR_Private_Macros
\r
94 /** @defgroup PWR_Private_Variables
\r
102 /** @defgroup PWR_Private_FunctionPrototypes
\r
110 /** @defgroup PWR_Private_Functions
\r
115 * @brief Deinitializes the PWR peripheral registers to their default reset values.
\r
119 void PWR_DeInit(void)
\r
121 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
\r
122 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
\r
126 * @brief Enables or disables access to the RTC and backup registers.
\r
127 * @param NewState: new state of the access to the RTC and backup registers.
\r
128 * This parameter can be: ENABLE or DISABLE.
\r
131 void PWR_BackupAccessCmd(FunctionalState NewState)
\r
133 /* Check the parameters */
\r
134 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
135 *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
\r
139 * @brief Enables or disables the Power Voltage Detector(PVD).
\r
140 * @param NewState: new state of the PVD.
\r
141 * This parameter can be: ENABLE or DISABLE.
\r
144 void PWR_PVDCmd(FunctionalState NewState)
\r
146 /* Check the parameters */
\r
147 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
148 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
\r
152 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
\r
153 * @param PWR_PVDLevel: specifies the PVD detection level
\r
154 * This parameter can be one of the following values:
\r
155 * @arg PWR_PVDLevel_2V2: PVD detection level set to 2.2V
\r
156 * @arg PWR_PVDLevel_2V3: PVD detection level set to 2.3V
\r
157 * @arg PWR_PVDLevel_2V4: PVD detection level set to 2.4V
\r
158 * @arg PWR_PVDLevel_2V5: PVD detection level set to 2.5V
\r
159 * @arg PWR_PVDLevel_2V6: PVD detection level set to 2.6V
\r
160 * @arg PWR_PVDLevel_2V7: PVD detection level set to 2.7V
\r
161 * @arg PWR_PVDLevel_2V8: PVD detection level set to 2.8V
\r
162 * @arg PWR_PVDLevel_2V9: PVD detection level set to 2.9V
\r
165 void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
\r
167 uint32_t tmpreg = 0;
\r
168 /* Check the parameters */
\r
169 assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
\r
171 /* Clear PLS[7:5] bits */
\r
172 tmpreg &= CR_PLS_Mask;
\r
173 /* Set PLS[7:5] bits according to PWR_PVDLevel value */
\r
174 tmpreg |= PWR_PVDLevel;
\r
175 /* Store the new value */
\r
180 * @brief Enables or disables the WakeUp Pin functionality.
\r
181 * @param NewState: new state of the WakeUp Pin functionality.
\r
182 * This parameter can be: ENABLE or DISABLE.
\r
185 void PWR_WakeUpPinCmd(FunctionalState NewState)
\r
187 /* Check the parameters */
\r
188 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
189 *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
\r
193 * @brief Enters STOP mode.
\r
194 * @param PWR_Regulator: specifies the regulator state in STOP mode.
\r
195 * This parameter can be one of the following values:
\r
196 * @arg PWR_Regulator_ON: STOP mode with regulator ON
\r
197 * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
\r
198 * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
\r
199 * This parameter can be one of the following values:
\r
200 * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
\r
201 * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
\r
204 void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
\r
206 uint32_t tmpreg = 0;
\r
207 /* Check the parameters */
\r
208 assert_param(IS_PWR_REGULATOR(PWR_Regulator));
\r
209 assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
\r
211 /* Select the regulator state in STOP mode ---------------------------------*/
\r
213 /* Clear PDDS and LPDS bits */
\r
214 tmpreg &= CR_DS_Mask;
\r
215 /* Set LPDS bit according to PWR_Regulator value */
\r
216 tmpreg |= PWR_Regulator;
\r
217 /* Store the new value */
\r
219 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
220 *(__IO uint32_t *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
\r
222 /* Select STOP mode entry --------------------------------------------------*/
\r
223 if(PWR_STOPEntry == PWR_STOPEntry_WFI)
\r
225 /* Request Wait For Interrupt */
\r
230 /* Request Wait For Event */
\r
236 * @brief Enters STANDBY mode.
\r
240 void PWR_EnterSTANDBYMode(void)
\r
242 /* Clear Wake-up flag */
\r
243 PWR->CR |= CR_CWUF_Set;
\r
244 /* Select STANDBY mode */
\r
245 PWR->CR |= CR_PDDS_Set;
\r
246 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
247 *(__IO uint32_t *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
\r
248 /* This option is used to ensure that store operations are completed */
\r
249 #if defined ( __CC_ARM )
\r
252 /* Request Wait For Interrupt */
\r
257 * @brief Checks whether the specified PWR flag is set or not.
\r
258 * @param PWR_FLAG: specifies the flag to check.
\r
259 * This parameter can be one of the following values:
\r
260 * @arg PWR_FLAG_WU: Wake Up flag
\r
261 * @arg PWR_FLAG_SB: StandBy flag
\r
262 * @arg PWR_FLAG_PVDO: PVD Output
\r
263 * @retval The new state of PWR_FLAG (SET or RESET).
\r
265 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
\r
267 FlagStatus bitstatus = RESET;
\r
268 /* Check the parameters */
\r
269 assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
\r
271 if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
\r
279 /* Return the flag status */
\r
284 * @brief Clears the PWR's pending flags.
\r
285 * @param PWR_FLAG: specifies the flag to clear.
\r
286 * This parameter can be one of the following values:
\r
287 * @arg PWR_FLAG_WU: Wake Up flag
\r
288 * @arg PWR_FLAG_SB: StandBy flag
\r
291 void PWR_ClearFlag(uint32_t PWR_FLAG)
\r
293 /* Check the parameters */
\r
294 assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
\r
296 PWR->CR |= PWR_FLAG << 2;
\r
311 /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
\r