STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_pwr_ex.c
Go to the documentation of this file.
1 
42 /* Includes ------------------------------------------------------------------*/
43 #include "stm32f7xx_hal.h"
44 
54 #ifdef HAL_PWR_MODULE_ENABLED
55 
56 /* Private typedef -----------------------------------------------------------*/
57 /* Private define ------------------------------------------------------------*/
61 #define PWR_OVERDRIVE_TIMEOUT_VALUE 1000
62 #define PWR_UDERDRIVE_TIMEOUT_VALUE 1000
63 #define PWR_BKPREG_TIMEOUT_VALUE 1000
64 #define PWR_VOSRDY_TIMEOUT_VALUE 1000
65 
69 /* Private macro -------------------------------------------------------------*/
70 /* Private variables ---------------------------------------------------------*/
71 /* Private function prototypes -----------------------------------------------*/
72 /* Private functions ---------------------------------------------------------*/
154 {
155  uint32_t tickstart = 0;
156 
157  /* Enable Backup regulator */
158  PWR->CSR1 |= PWR_CSR1_BRE;
159 
160  /* Workaround for the following hardware bug: */
161  /* Id 19: PWR : No STANDBY wake-up when Back-up RAM enabled (ref. Errata Sheet p23) */
162  PWR->CSR1 |= PWR_CSR1_EIWUP;
163 
164  /* Get tick */
165  tickstart = HAL_GetTick();
166 
167  /* Wait till Backup regulator ready flag is set */
169  {
170  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
171  {
172  return HAL_TIMEOUT;
173  }
174  }
175  return HAL_OK;
176 }
177 
183 {
184  uint32_t tickstart = 0;
185 
186  /* Disable Backup regulator */
187  PWR->CSR1 &= (uint32_t)~((uint32_t)PWR_CSR1_BRE);
188 
189  /* Workaround for the following hardware bug: */
190  /* Id 19: PWR : No STANDBY wake-up when Back-up RAM enabled (ref. Errata Sheet p23) */
191  PWR->CSR1 |= PWR_CSR1_EIWUP;
192 
193  /* Get tick */
194  tickstart = HAL_GetTick();
195 
196  /* Wait till Backup regulator ready flag is set */
198  {
199  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
200  {
201  return HAL_TIMEOUT;
202  }
203  }
204  return HAL_OK;
205 }
206 
212 {
213  /* Enable the Flash Power Down */
214  PWR->CR1 |= PWR_CR1_FPDS;
215 }
216 
222 {
223  /* Disable the Flash Power Down */
224  PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_FPDS);
225 }
226 
232 {
233  /* Enable Main regulator low voltage */
234  PWR->CR1 |= PWR_CR1_MRUDS;
235 }
236 
242 {
243  /* Disable Main regulator low voltage */
244  PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_MRUDS);
245 }
246 
252 {
253  /* Enable low power regulator */
254  PWR->CR1 |= PWR_CR1_LPUDS;
255 }
256 
262 {
263  /* Disable low power regulator */
264  PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_LPUDS);
265 }
266 
278 {
279  uint32_t tickstart = 0;
280 
282 
283  /* Enable the Over-drive to extend the clock frequency to 216 MHz */
285 
286  /* Get tick */
287  tickstart = HAL_GetTick();
288 
290  {
291  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
292  {
293  return HAL_TIMEOUT;
294  }
295  }
296 
297  /* Enable the Over-drive switch */
299 
300  /* Get tick */
301  tickstart = HAL_GetTick();
302 
304  {
305  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
306  {
307  return HAL_TIMEOUT;
308  }
309  }
310  return HAL_OK;
311 }
312 
324 {
325  uint32_t tickstart = 0;
326 
328 
329  /* Disable the Over-drive switch */
331 
332  /* Get tick */
333  tickstart = HAL_GetTick();
334 
336  {
337  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
338  {
339  return HAL_TIMEOUT;
340  }
341  }
342 
343  /* Disable the Over-drive */
345 
346  /* Get tick */
347  tickstart = HAL_GetTick();
348 
350  {
351  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
352  {
353  return HAL_TIMEOUT;
354  }
355  }
356 
357  return HAL_OK;
358 }
359 
397 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
398 {
399  uint32_t tempreg = 0;
400  uint32_t tickstart = 0;
401 
402  /* Check the parameters */
404  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
405 
406  /* Enable Power ctrl clock */
408  /* Enable the Under-drive Mode ---------------------------------------------*/
409  /* Clear Under-drive flag */
411 
412  /* Enable the Under-drive */
414 
415  /* Get tick */
416  tickstart = HAL_GetTick();
417 
418  /* Wait for UnderDrive mode is ready */
420  {
421  if((HAL_GetTick() - tickstart ) > PWR_UDERDRIVE_TIMEOUT_VALUE)
422  {
423  return HAL_TIMEOUT;
424  }
425  }
426 
427  /* Select the regulator state in STOP mode ---------------------------------*/
428  tempreg = PWR->CR1;
429  /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */
430  tempreg &= (uint32_t)~(PWR_CR1_PDDS | PWR_CR1_LPDS | PWR_CR1_LPUDS | PWR_CR1_MRUDS);
431 
432  /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
433  tempreg |= Regulator;
434 
435  /* Store the new value */
436  PWR->CR1 = tempreg;
437 
438  /* Set SLEEPDEEP bit of Cortex System Control Register */
439  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
440 
441  /* Select STOP mode entry --------------------------------------------------*/
442  if(STOPEntry == PWR_SLEEPENTRY_WFI)
443  {
444  /* Request Wait For Interrupt */
445  __WFI();
446  }
447  else
448  {
449  /* Request Wait For Event */
450  __WFE();
451  }
452  /* Reset SLEEPDEEP bit of Cortex System Control Register */
453  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
454 
455  return HAL_OK;
456 }
457 
463 uint32_t HAL_PWREx_GetVoltageRange(void)
464 {
465  return (PWR->CR1 & PWR_CR1_VOS);
466 }
467 
495 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
496 {
497  uint32_t tickstart = 0;
498 
499  assert_param(IS_PWR_REGULATOR_VOLTAGE(VoltageScaling));
500 
501  /* Enable Power ctrl clock */
503 
504  /* Check if the PLL is used as system clock or not */
506  {
507  /* Disable the main PLL */
509 
510  /* Get Start Tick */
511  tickstart = HAL_GetTick();
512  /* Wait till PLL is disabled */
514  {
515  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
516  {
517  return HAL_TIMEOUT;
518  }
519  }
520 
521  /* Set Range */
522  __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
523 
524  /* Enable the main PLL */
526 
527  /* Get Start Tick */
528  tickstart = HAL_GetTick();
529  /* Wait till PLL is ready */
531  {
532  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
533  {
534  return HAL_TIMEOUT;
535  }
536  }
537 
538  /* Get Start Tick */
539  tickstart = HAL_GetTick();
541  {
542  if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
543  {
544  return HAL_TIMEOUT;
545  }
546  }
547  }
548  else
549  {
550  return HAL_ERROR;
551  }
552  return HAL_OK;
553 }
554 
563 #endif /* HAL_PWR_MODULE_ENABLED */
564 
572 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define __HAL_PWR_UNDERDRIVE_ENABLE()
Macros to enable or disable the Under drive mode.
#define RCC_FLAG_PLLRDY
#define SCB_SCR_SLEEPDEEP_Msk
Definition: core_cm0.h:467
#define PWR_FLAG_ODSWRDY
#define __HAL_PWR_OVERDRIVESWITCHING_ENABLE()
Macros to enable or disable the Over drive switching.
#define PLL_TIMEOUT_VALUE
#define assert_param(expr)
Include module's header file.
#define PWR_CR1_LPUDS
Definition: stm32f745xx.h:4981
#define PWR_SLEEPENTRY_WFI
#define __HAL_PWR_OVERDRIVE_ENABLE()
Macros to enable or disable the Over drive mode.
#define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE)
#define PWR_FLAG_UDRDY
#define __HAL_PWR_CLEAR_ODRUDR_FLAG()
Clear the Under-Drive Ready flag.
#define PWR_CSR1_EIWUP
Definition: stm32f745xx.h:4998
#define RCC_CFGR_SWS_PLL
Definition: stm32f745xx.h:5251
#define PWR_CR1_MRUDS
Definition: stm32f745xx.h:4982
#define PWR_FLAG_BRR
#define __HAL_RCC_PWR_CLK_ENABLE()
HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
#define __HAL_RCC_PLL_DISABLE()
#define __HAL_PWR_OVERDRIVE_DISABLE()
#define PWR_CSR1_BRE
Definition: stm32f745xx.h:4999
#define PWR_CR1_VOS
Definition: stm32f745xx.h:4984
#define __HAL_RCC_PLL_ENABLE()
Macros to enable or disable the main PLL.
#define PWR_FLAG_ODRDY
void HAL_PWREx_EnableMainRegulatorLowVoltage(void)
#define __HAL_RCC_GET_FLAG(__FLAG__)
#define SCB
Definition: core_cm0.h:587
HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
#define PWR_CR1_PDDS
Definition: stm32f745xx.h:4962
This file contains all the functions prototypes for the HAL module driver.
#define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__)
macros configure the main internal regulator output voltage.
#define PWR_CR1_FPDS
Definition: stm32f745xx.h:4980
HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
#define PWR
Definition: stm32f745xx.h:1285
void HAL_PWREx_DisableFlashPowerDown(void)
void HAL_PWREx_EnableFlashPowerDown(void)
HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
#define IS_PWR_STOP_ENTRY(ENTRY)
#define PWR_CR1_LPDS
Definition: stm32f745xx.h:4961
#define __HAL_PWR_OVERDRIVESWITCHING_DISABLE()
#define __HAL_PWR_GET_FLAG(__FLAG__)
Check PWR flag is set or not.
#define PWR_FLAG_VOSRDY
#define __WFI
Wait For Interrupt.
Definition: cmsis_armcc.h:320
HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
void HAL_PWREx_DisableLowRegulatorLowVoltage(void)
uint32_t HAL_PWREx_GetVoltageRange(void)
HAL_StatusTypeDef
HAL Status structures definition.
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
#define __WFE
Wait For Event.
Definition: cmsis_armcc.h:328
void HAL_PWREx_DisableMainRegulatorLowVoltage(void)
void HAL_PWREx_EnableLowRegulatorLowVoltage(void)
#define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR)
#define __HAL_RCC_GET_SYSCLK_SOURCE()
Macro to get the clock source used as system clock.