uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
stm32f10x_pwr.c
Go to the documentation of this file.
1 
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x_pwr.h"
24 #include "stm32f10x_rcc.h"
25 
47 /* --------- PWR registers bit address in the alias region ---------- */
48 #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
49 
50 /* --- CR Register ---*/
51 
52 /* Alias word address of DBP bit */
53 #define CR_OFFSET (PWR_OFFSET + 0x00)
54 #define DBP_BitNumber 0x08
55 #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
56 
57 /* Alias word address of PVDE bit */
58 #define PVDE_BitNumber 0x04
59 #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
60 
61 /* --- CSR Register ---*/
62 
63 /* Alias word address of EWUP bit */
64 #define CSR_OFFSET (PWR_OFFSET + 0x04)
65 #define EWUP_BitNumber 0x08
66 #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
67 
68 /* ------------------ PWR registers bit mask ------------------------ */
69 
70 /* CR register bit mask */
71 #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
72 #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
73 
74 
112 void PWR_DeInit(void)
113 {
116 }
117 
125 {
126  /* Check the parameters */
128  *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
129 }
130 
138 {
139  /* Check the parameters */
141  *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
142 }
143 
158 void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
159 {
160  uint32_t tmpreg = 0;
161  /* Check the parameters */
162  assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
163  tmpreg = PWR->CR;
164  /* Clear PLS[7:5] bits */
165  tmpreg &= CR_PLS_MASK;
166  /* Set PLS[7:5] bits according to PWR_PVDLevel value */
167  tmpreg |= PWR_PVDLevel;
168  /* Store the new value */
169  PWR->CR = tmpreg;
170 }
171 
179 {
180  /* Check the parameters */
182  *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
183 }
184 
197 void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
198 {
199  uint32_t tmpreg = 0;
200  /* Check the parameters */
201  assert_param(IS_PWR_REGULATOR(PWR_Regulator));
202  assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
203 
204  /* Select the regulator state in STOP mode ---------------------------------*/
205  tmpreg = PWR->CR;
206  /* Clear PDDS and LPDS bits */
207  tmpreg &= CR_DS_MASK;
208  /* Set LPDS bit according to PWR_Regulator value */
209  tmpreg |= PWR_Regulator;
210  /* Store the new value */
211  PWR->CR = tmpreg;
212  /* Set SLEEPDEEP bit of Cortex System Control Register */
213  SCB->SCR |= SCB_SCR_SLEEPDEEP;
214 
215  /* Select STOP mode entry --------------------------------------------------*/
216  if(PWR_STOPEntry == PWR_STOPEntry_WFI)
217  {
218  /* Request Wait For Interrupt */
219  __WFI();
220  }
221  else
222  {
223  /* Request Wait For Event */
224  __WFE();
225  }
226 
227  /* Reset SLEEPDEEP bit of Cortex System Control Register */
228  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
229 }
230 
237 {
238  /* Clear Wake-up flag */
239  PWR->CR |= PWR_CR_CWUF;
240  /* Select STANDBY mode */
241  PWR->CR |= PWR_CR_PDDS;
242  /* Set SLEEPDEEP bit of Cortex System Control Register */
243  SCB->SCR |= SCB_SCR_SLEEPDEEP;
244 /* This option is used to ensure that store operations are completed */
245 #if defined ( __CC_ARM )
246  __force_stores();
247 #endif
248  /* Request Wait For Interrupt */
249  __WFI();
250 }
251 
261 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
262 {
263  FlagStatus bitstatus = RESET;
264  /* Check the parameters */
265  assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
266 
267  if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
268  {
269  bitstatus = SET;
270  }
271  else
272  {
273  bitstatus = RESET;
274  }
275  /* Return the flag status */
276  return bitstatus;
277 }
278 
287 void PWR_ClearFlag(uint32_t PWR_FLAG)
288 {
289  /* Check the parameters */
290  assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
291 
292  PWR->CR |= PWR_FLAG << 2;
293 }
294 
307 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/