1 /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
\r
2 * File Name : stm32f10x_pwr.c
\r
3 * Author : MCD Application Team
\r
4 * Date First Issued : 09/29/2006
\r
5 * Description : This file provides all the PWR firmware functions.
\r
6 ********************************************************************************
\r
11 ********************************************************************************
\r
12 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
\r
14 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
\r
15 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
\r
16 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
\r
17 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 *******************************************************************************/
\r
20 /* Includes ------------------------------------------------------------------*/
\r
21 #include "stm32f10x_pwr.h"
\r
22 #include "stm32f10x_rcc.h"
\r
24 /* Private typedef -----------------------------------------------------------*/
\r
25 /* Private define ------------------------------------------------------------*/
\r
26 /* --------- PWR registers bit address in the alias region ---------- */
\r
27 #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
\r
29 /* --- CR Register ---*/
\r
30 /* Alias word address of DBP bit */
\r
31 #define CR_OFFSET (PWR_OFFSET + 0x00)
\r
32 #define DBP_BitNumber 0x08
\r
33 #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
\r
35 /* Alias word address of PVDE bit */
\r
36 #define PVDE_BitNumber 0x04
\r
37 #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
\r
39 /* --- CSR Register ---*/
\r
40 /* Alias word address of EWUP bit */
\r
41 #define CSR_OFFSET (PWR_OFFSET + 0x04)
\r
42 #define EWUP_BitNumber 0x08
\r
43 #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
\r
45 /* ------------------ PWR registers bit mask ------------------------ */
\r
46 /* CR register bit mask */
\r
47 #define CR_PDDS_Set ((u32)0x00000002)
\r
48 #define CR_DS_Mask ((u32)0xFFFFFFFC)
\r
49 #define CR_CWUF_Set ((u32)0x00000004)
\r
50 #define CR_PLS_Mask ((u32)0xFFFFFF1F)
\r
52 /* --------- Cortex System Control register bit mask ---------------- */
\r
53 /* Cortex System Control register address */
\r
54 #define SCB_SysCtrl ((u32)0xE000ED10)
\r
55 /* SLEEPDEEP bit mask */
\r
56 #define SysCtrl_SLEEPDEEP_Set ((u32)0x00000004)
\r
58 /* Private macro -------------------------------------------------------------*/
\r
59 /* Private variables ---------------------------------------------------------*/
\r
60 /* Private function prototypes -----------------------------------------------*/
\r
61 /* Private functions ---------------------------------------------------------*/
\r
63 /*******************************************************************************
\r
64 * Function Name : PWR_DeInit
\r
65 * Description : Deinitializes the PWR peripheral registers to their default
\r
70 *******************************************************************************/
\r
71 void PWR_DeInit(void)
\r
73 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
\r
74 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
\r
77 /*******************************************************************************
\r
78 * Function Name : PWR_BackupAccessCmd
\r
79 * Description : Enables or disables access to the RTC and backup registers.
\r
80 * Input : - NewState: new state of the access to the RTC and backup
\r
81 * registers. This parameter can be: ENABLE or DISABLE.
\r
84 *******************************************************************************/
\r
85 void PWR_BackupAccessCmd(FunctionalState NewState)
\r
87 /* Check the parameters */
\r
88 assert(IS_FUNCTIONAL_STATE(NewState));
\r
90 *(vu32 *) CR_DBP_BB = (u32)NewState;
\r
93 /*******************************************************************************
\r
94 * Function Name : PWR_PVDCmd
\r
95 * Description : Enables or disables the Power Voltage Detector(PVD).
\r
96 * Input : - NewState: new state of the PVD.
\r
97 * This parameter can be: ENABLE or DISABLE.
\r
100 *******************************************************************************/
\r
101 void PWR_PVDCmd(FunctionalState NewState)
\r
103 /* Check the parameters */
\r
104 assert(IS_FUNCTIONAL_STATE(NewState));
\r
106 *(vu32 *) CR_PVDE_BB = (u32)NewState;
\r
109 /*******************************************************************************
\r
110 * Function Name : PWR_PVDLevelConfig
\r
111 * Description : Configures the value detected by the Power Voltage Detector(PVD).
\r
112 * Input : - PWR_PVDLevel: specifies the PVD detection level
\r
113 * This parameter can be one of the following values:
\r
114 * - PWR_PVDLevel_2V2: PVD detection level set to 2.2V
\r
115 * - PWR_PVDLevel_2V3: PVD detection level set to 2.3V
\r
116 * - PWR_PVDLevel_2V4: PVD detection level set to 2.4V
\r
117 * - PWR_PVDLevel_2V5: PVD detection level set to 2.5V
\r
118 * - PWR_PVDLevel_2V6: PVD detection level set to 2.6V
\r
119 * - PWR_PVDLevel_2V7: PVD detection level set to 2.7V
\r
120 * - PWR_PVDLevel_2V8: PVD detection level set to 2.8V
\r
121 * - PWR_PVDLevel_2V9: PVD detection level set to 2.9V
\r
124 *******************************************************************************/
\r
125 void PWR_PVDLevelConfig(u32 PWR_PVDLevel)
\r
129 /* Check the parameters */
\r
130 assert(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
\r
134 /* Clear PLS[7:5] bits */
\r
135 tmpreg &= CR_PLS_Mask;
\r
137 /* Set PLS[7:5] bits according to PWR_PVDLevel value */
\r
138 tmpreg |= PWR_PVDLevel;
\r
140 /* Store the new value */
\r
144 /*******************************************************************************
\r
145 * Function Name : PWR_WakeUpPinCmd
\r
146 * Description : Enables or disables the WakeUp Pin functionality.
\r
147 * Input : - NewState: new state of the WakeUp Pin functionality.
\r
148 * This parameter can be: ENABLE or DISABLE.
\r
151 *******************************************************************************/
\r
152 void PWR_WakeUpPinCmd(FunctionalState NewState)
\r
154 /* Check the parameters */
\r
155 assert(IS_FUNCTIONAL_STATE(NewState));
\r
157 *(vu32 *) CSR_EWUP_BB = (u32)NewState;
\r
160 /*******************************************************************************
\r
161 * Function Name : PWR_EnterSTOPMode
\r
162 * Description : Enters STOP mode.
\r
163 * Input : - PWR_Regulator: specifies the regulator state in STOP mode.
\r
164 * This parameter can be one of the following values:
\r
165 * - PWR_Regulator_ON: STOP mode with regulator ON
\r
166 * - PWR_Regulator_LowPower: STOP mode with
\r
167 * regulator in low power mode
\r
168 * - PWR_STOPEntry: specifies if STOP mode in entered with WFI or
\r
170 * This parameter can be one of the following values:
\r
171 * - PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
\r
172 * - PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
\r
175 *******************************************************************************/
\r
176 void PWR_EnterSTOPMode(u32 PWR_Regulator, u8 PWR_STOPEntry)
\r
180 /* Check the parameters */
\r
181 assert(IS_PWR_REGULATOR(PWR_Regulator));
\r
182 assert(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
\r
184 /* Select the regulator state in STOP mode ---------------------------------*/
\r
187 /* Clear PDDS and LPDS bits */
\r
188 tmpreg &= CR_DS_Mask;
\r
190 /* Set LPDS bit according to PWR_Regulator value */
\r
191 tmpreg |= PWR_Regulator;
\r
193 /* Store the new value */
\r
196 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
197 *(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
\r
199 /* Select STOP mode entry --------------------------------------------------*/
\r
200 if(PWR_STOPEntry == PWR_STOPEntry_WFI)
\r
202 /* Request Wait For Interrupt */
\r
207 /* Request Wait For Event */
\r
212 /*******************************************************************************
\r
213 * Function Name : PWR_EnterSTANDBYMode
\r
214 * Description : Enters STANDBY mode.
\r
218 *******************************************************************************/
\r
219 void PWR_EnterSTANDBYMode(void)
\r
221 /* Clear Wake-up flag */
\r
222 PWR->CR |= CR_CWUF_Set;
\r
224 /* Select STANDBY mode */
\r
225 PWR->CR |= CR_PDDS_Set;
\r
227 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
228 *(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
\r
230 /* Request Wait For Interrupt */
\r
234 /*******************************************************************************
\r
235 * Function Name : PWR_GetFlagStatus
\r
236 * Description : Checks whether the specified PWR flag is set or not.
\r
237 * Input : - PWR_FLAG: specifies the flag to check.
\r
238 * This parameter can be one of the following values:
\r
239 * - PWR_FLAG_WU: Wake Up flag
\r
240 * - PWR_FLAG_SB: StandBy flag
\r
241 * - PWR_FLAG_PVDO: PVD Output
\r
243 * Return : The new state of PWR_FLAG (SET or RESET).
\r
244 *******************************************************************************/
\r
245 FlagStatus PWR_GetFlagStatus(u32 PWR_FLAG)
\r
247 FlagStatus bitstatus = RESET;
\r
249 /* Check the parameters */
\r
250 assert(IS_PWR_GET_FLAG(PWR_FLAG));
\r
252 if ((PWR->CSR & PWR_FLAG) != (u32)RESET)
\r
261 /* Return the flag status */
\r
265 /*******************************************************************************
\r
266 * Function Name : PWR_ClearFlag
\r
267 * Description : Clears the PWR's pending flags.
\r
268 * Input : - PWR_FLAG: specifies the flag to clear.
\r
269 * This parameter can be one of the following values:
\r
270 * - PWR_FLAG_WU: Wake Up flag
\r
271 * - PWR_FLAG_SB: StandBy flag
\r
274 *******************************************************************************/
\r
275 void PWR_ClearFlag(u32 PWR_FLAG)
\r
277 /* Check the parameters */
\r
278 assert(IS_PWR_CLEAR_FLAG(PWR_FLAG));
\r
280 PWR->CR |= PWR_FLAG << 2;
\r
283 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
\r