stm32f7xx_hal_pwr_ex.c
Go to the documentation of this file.
1 
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm32f7xx_hal.h"
26 
36 #ifdef HAL_PWR_MODULE_ENABLED
37 
38 /* Private typedef -----------------------------------------------------------*/
39 /* Private define ------------------------------------------------------------*/
43 #define PWR_OVERDRIVE_TIMEOUT_VALUE 1000
44 #define PWR_UDERDRIVE_TIMEOUT_VALUE 1000
45 #define PWR_BKPREG_TIMEOUT_VALUE 1000
46 #define PWR_VOSRDY_TIMEOUT_VALUE 1000
47 
51 /* Private macro -------------------------------------------------------------*/
52 /* Private variables ---------------------------------------------------------*/
53 /* Private function prototypes -----------------------------------------------*/
54 /* Private functions ---------------------------------------------------------*/
136 {
137  uint32_t tickstart = 0;
138 
139  /* Enable Backup regulator */
140  PWR->CSR1 |= PWR_CSR1_BRE;
141 
142  /* Workaround for the following hardware bug: */
143  /* Id 19: PWR : No STANDBY wake-up when Back-up RAM enabled (ref. Errata Sheet p23) */
144  PWR->CSR1 |= PWR_CSR1_EIWUP;
145 
146  /* Get tick */
147  tickstart = HAL_GetTick();
148 
149  /* Wait till Backup regulator ready flag is set */
151  {
152  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
153  {
154  return HAL_TIMEOUT;
155  }
156  }
157  return HAL_OK;
158 }
159 
165 {
166  uint32_t tickstart = 0;
167 
168  /* Disable Backup regulator */
169  PWR->CSR1 &= (uint32_t)~((uint32_t)PWR_CSR1_BRE);
170 
171  /* Workaround for the following hardware bug: */
172  /* Id 19: PWR : No STANDBY wake-up when Back-up RAM enabled (ref. Errata Sheet p23) */
173  PWR->CSR1 |= PWR_CSR1_EIWUP;
174 
175  /* Get tick */
176  tickstart = HAL_GetTick();
177 
178  /* Wait till Backup regulator ready flag is set */
180  {
181  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
182  {
183  return HAL_TIMEOUT;
184  }
185  }
186  return HAL_OK;
187 }
188 
194 {
195  /* Enable the Flash Power Down */
196  PWR->CR1 |= PWR_CR1_FPDS;
197 }
198 
204 {
205  /* Disable the Flash Power Down */
206  PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_FPDS);
207 }
208 
214 {
215  /* Enable Main regulator low voltage */
216  PWR->CR1 |= PWR_CR1_MRUDS;
217 }
218 
224 {
225  /* Disable Main regulator low voltage */
226  PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_MRUDS);
227 }
228 
234 {
235  /* Enable low power regulator */
236  PWR->CR1 |= PWR_CR1_LPUDS;
237 }
238 
244 {
245  /* Disable low power regulator */
246  PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_LPUDS);
247 }
248 
260 {
261  uint32_t tickstart = 0;
262 
264 
265  /* Enable the Over-drive to extend the clock frequency to 216 MHz */
267 
268  /* Get tick */
269  tickstart = HAL_GetTick();
270 
272  {
273  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
274  {
275  return HAL_TIMEOUT;
276  }
277  }
278 
279  /* Enable the Over-drive switch */
281 
282  /* Get tick */
283  tickstart = HAL_GetTick();
284 
286  {
287  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
288  {
289  return HAL_TIMEOUT;
290  }
291  }
292  return HAL_OK;
293 }
294 
306 {
307  uint32_t tickstart = 0;
308 
310 
311  /* Disable the Over-drive switch */
313 
314  /* Get tick */
315  tickstart = HAL_GetTick();
316 
318  {
319  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
320  {
321  return HAL_TIMEOUT;
322  }
323  }
324 
325  /* Disable the Over-drive */
327 
328  /* Get tick */
329  tickstart = HAL_GetTick();
330 
332  {
333  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
334  {
335  return HAL_TIMEOUT;
336  }
337  }
338 
339  return HAL_OK;
340 }
341 
379 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
380 {
381  uint32_t tempreg = 0;
382  uint32_t tickstart = 0;
383 
384  /* Check the parameters */
386  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
387 
388  /* Enable Power ctrl clock */
390  /* Enable the Under-drive Mode ---------------------------------------------*/
391  /* Clear Under-drive flag */
393 
394  /* Enable the Under-drive */
396 
397  /* Get tick */
398  tickstart = HAL_GetTick();
399 
400  /* Wait for UnderDrive mode is ready */
402  {
403  if((HAL_GetTick() - tickstart ) > PWR_UDERDRIVE_TIMEOUT_VALUE)
404  {
405  return HAL_TIMEOUT;
406  }
407  }
408 
409  /* Select the regulator state in STOP mode ---------------------------------*/
410  tempreg = PWR->CR1;
411  /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */
412  tempreg &= (uint32_t)~(PWR_CR1_PDDS | PWR_CR1_LPDS | PWR_CR1_LPUDS | PWR_CR1_MRUDS);
413 
414  /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
415  tempreg |= Regulator;
416 
417  /* Store the new value */
418  PWR->CR1 = tempreg;
419 
420  /* Set SLEEPDEEP bit of Cortex System Control Register */
421  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
422 
423  /* Select STOP mode entry --------------------------------------------------*/
424  if(STOPEntry == PWR_SLEEPENTRY_WFI)
425  {
426  /* Request Wait For Interrupt */
427  __WFI();
428  }
429  else
430  {
431  /* Request Wait For Event */
432  __WFE();
433  }
434  /* Reset SLEEPDEEP bit of Cortex System Control Register */
435  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
436 
437  return HAL_OK;
438 }
439 
445 uint32_t HAL_PWREx_GetVoltageRange(void)
446 {
447  return (PWR->CR1 & PWR_CR1_VOS);
448 }
449 
477 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
478 {
479  uint32_t tickstart = 0;
480 
481  assert_param(IS_PWR_REGULATOR_VOLTAGE(VoltageScaling));
482 
483  /* Enable Power ctrl clock */
485 
486  /* Check if the PLL is used as system clock or not */
488  {
489  /* Disable the main PLL */
491 
492  /* Get Start Tick */
493  tickstart = HAL_GetTick();
494  /* Wait till PLL is disabled */
496  {
497  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
498  {
499  return HAL_TIMEOUT;
500  }
501  }
502 
503  /* Set Range */
504  __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
505 
506  /* Enable the main PLL */
508 
509  /* Get Start Tick */
510  tickstart = HAL_GetTick();
511  /* Wait till PLL is ready */
513  {
514  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
515  {
516  return HAL_TIMEOUT;
517  }
518  }
519 
520  /* Get Start Tick */
521  tickstart = HAL_GetTick();
523  {
524  if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
525  {
526  return HAL_TIMEOUT;
527  }
528  }
529  }
530  else
531  {
532  return HAL_ERROR;
533  }
534  return HAL_OK;
535 }
536 
545 #endif /* HAL_PWR_MODULE_ENABLED */
546 
554 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
PWR_FLAG_BRR
#define PWR_FLAG_BRR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h:137
SCB
#define SCB
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:1778
assert_param
#define assert_param(expr)
Include module's header file.
Definition: stm32f407/stm32f407g-disc1/Inc/stm32f4xx_hal_conf.h:353
__HAL_PWR_GET_FLAG
#define __HAL_PWR_GET_FLAG(__FLAG__)
Check PWR flag is set or not.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h:173
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
PWR_CR1_MRUDS
#define PWR_CR1_MRUDS
Definition: stm32f769xx.h:10482
PWR
#define PWR
Definition: stm32f407xx.h:1083
PWR_FLAG_ODRDY
#define PWR_FLAG_ODRDY
Definition: stm32f7xx_hal_pwr_ex.h:82
HAL_PWREx_EnableBkUpReg
HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
__HAL_PWR_OVERDRIVE_DISABLE
#define __HAL_PWR_OVERDRIVE_DISABLE()
Definition: stm32f7xx_hal_pwr_ex.h:113
HAL_PWREx_EnableOverDrive
HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
PLL_TIMEOUT_VALUE
#define PLL_TIMEOUT_VALUE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:6854
HAL_PWREx_EnableLowRegulatorLowVoltage
void HAL_PWREx_EnableLowRegulatorLowVoltage(void)
RCC_CFGR_SWS_PLL
#define RCC_CFGR_SWS_PLL
Definition: stm32f407xx.h:9552
__HAL_PWR_OVERDRIVESWITCHING_ENABLE
#define __HAL_PWR_OVERDRIVESWITCHING_ENABLE()
Macros to enable or disable the Over drive switching.
Definition: stm32f7xx_hal_pwr_ex.h:117
PWR_CR1_LPDS
#define PWR_CR1_LPDS
Definition: stm32f769xx.h:10431
HAL_ERROR
@ HAL_ERROR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:43
IS_PWR_REGULATOR_VOLTAGE
#define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE)
Definition: stm32f7xx_hal_pwr.h:377
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:323
IS_PWR_STOP_ENTRY
#define IS_PWR_STOP_ENTRY(ENTRY)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h:407
RCC_FLAG_PLLRDY
#define RCC_FLAG_PLLRDY
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:351
PWR_SLEEPENTRY_WFI
#define PWR_SLEEPENTRY_WFI
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h:116
__HAL_RCC_PLL_DISABLE
#define __HAL_RCC_PLL_DISABLE()
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:1038
HAL_PWREx_DisableBkUpReg
HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
PWR_FLAG_VOSRDY
#define PWR_FLAG_VOSRDY
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h:138
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
PWR_CR1_VOS
#define PWR_CR1_VOS
Definition: stm32f769xx.h:10488
HAL_PWREx_DisableOverDrive
HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
PWR_CSR1_BRE
#define PWR_CSR1_BRE
Definition: stm32f769xx.h:10521
PWR_FLAG_ODSWRDY
#define PWR_FLAG_ODSWRDY
Definition: stm32f7xx_hal_pwr_ex.h:83
RESET
@ RESET
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:187
HAL_PWREx_EnterUnderDriveSTOPMode
HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
HAL_PWREx_EnableFlashPowerDown
void HAL_PWREx_EnableFlashPowerDown(void)
PWR_FLAG_UDRDY
#define PWR_FLAG_UDRDY
Definition: stm32f7xx_hal_pwr_ex.h:84
IS_PWR_REGULATOR_UNDERDRIVE
#define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR)
Definition: stm32f7xx_hal_pwr_ex.h:219
__HAL_RCC_PWR_CLK_ENABLE
#define __HAL_RCC_PWR_CLK_ENABLE()
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:512
HAL_TIMEOUT
@ HAL_TIMEOUT
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:45
__HAL_RCC_PLL_ENABLE
#define __HAL_RCC_PLL_ENABLE()
Macros to enable or disable the main PLL.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:1037
HAL_PWREx_DisableFlashPowerDown
void HAL_PWREx_DisableFlashPowerDown(void)
__HAL_PWR_CLEAR_ODRUDR_FLAG
#define __HAL_PWR_CLEAR_ODRUDR_FLAG()
Clear the Under-Drive Ready flag.
Definition: stm32f7xx_hal_pwr_ex.h:148
HAL_PWREx_DisableMainRegulatorLowVoltage
void HAL_PWREx_DisableMainRegulatorLowVoltage(void)
__HAL_RCC_GET_FLAG
#define __HAL_RCC_GET_FLAG(__FLAG__)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:1230
HAL_PWREx_GetVoltageRange
uint32_t HAL_PWREx_GetVoltageRange(void)
HAL_PWREx_DisableLowRegulatorLowVoltage
void HAL_PWREx_DisableLowRegulatorLowVoltage(void)
__HAL_PWR_UNDERDRIVE_ENABLE
#define __HAL_PWR_UNDERDRIVE_ENABLE()
Macros to enable or disable the Under drive mode.
Definition: stm32f7xx_hal_pwr_ex.h:130
__HAL_PWR_OVERDRIVESWITCHING_DISABLE
#define __HAL_PWR_OVERDRIVESWITCHING_DISABLE()
Definition: stm32f7xx_hal_pwr_ex.h:118
__HAL_PWR_OVERDRIVE_ENABLE
#define __HAL_PWR_OVERDRIVE_ENABLE()
Macros to enable or disable the Over drive mode.
Definition: stm32f7xx_hal_pwr_ex.h:112
__HAL_RCC_GET_SYSCLK_SOURCE
#define __HAL_RCC_GET_SYSCLK_SOURCE()
Macro to get the clock source used as system clock.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:1088
HAL_PWREx_EnableMainRegulatorLowVoltage
void HAL_PWREx_EnableMainRegulatorLowVoltage(void)
PWR_CSR1_EIWUP
#define PWR_CSR1_EIWUP
Definition: stm32f769xx.h:10518
PWR_CR1_FPDS
#define PWR_CR1_FPDS
Definition: stm32f769xx.h:10476
HAL_PWREx_ControlVoltageScaling
HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
__WFE
#define __WFE
Wait For Event.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_armcc.h:431
PWR_CR1_LPUDS
#define PWR_CR1_LPUDS
Definition: stm32f769xx.h:10479
__HAL_PWR_VOLTAGESCALING_CONFIG
#define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__)
macros configure the main internal regulator output voltage.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:135
__WFI
#define __WFI
Wait For Interrupt.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_armcc.h:423
stm32f7xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
SCB_SCR_SLEEPDEEP_Msk
#define SCB_SCR_SLEEPDEEP_Msk
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:587
PWR_CR1_PDDS
#define PWR_CR1_PDDS
Definition: stm32f769xx.h:10434


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:53