stm32f4xx_hal_pwr_ex.c
Go to the documentation of this file.
1 
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm32f4xx_hal.h"
26 
36 #ifdef HAL_PWR_MODULE_ENABLED
37 
38 /* Private typedef -----------------------------------------------------------*/
39 /* Private define ------------------------------------------------------------*/
43 #define PWR_OVERDRIVE_TIMEOUT_VALUE 1000U
44 #define PWR_UDERDRIVE_TIMEOUT_VALUE 1000U
45 #define PWR_BKPREG_TIMEOUT_VALUE 1000U
46 #define PWR_VOSRDY_TIMEOUT_VALUE 1000U
47 
52 /* Private macro -------------------------------------------------------------*/
53 /* Private variables ---------------------------------------------------------*/
54 /* Private function prototypes -----------------------------------------------*/
55 /* Private functions ---------------------------------------------------------*/
144 {
145  uint32_t tickstart = 0U;
146 
147  *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)ENABLE;
148 
149  /* Get tick */
150  tickstart = HAL_GetTick();
151 
152  /* Wait till Backup regulator ready flag is set */
154  {
155  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
156  {
157  return HAL_TIMEOUT;
158  }
159  }
160  return HAL_OK;
161 }
162 
168 {
169  uint32_t tickstart = 0U;
170 
171  *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)DISABLE;
172 
173  /* Get tick */
174  tickstart = HAL_GetTick();
175 
176  /* Wait till Backup regulator ready flag is set */
178  {
179  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
180  {
181  return HAL_TIMEOUT;
182  }
183  }
184  return HAL_OK;
185 }
186 
192 {
193  *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)ENABLE;
194 }
195 
201 {
202  *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)DISABLE;
203 }
204 
213 uint32_t HAL_PWREx_GetVoltageRange(void)
214 {
215  return (PWR->CR & PWR_CR_VOS);
216 }
217 
218 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)
219 
234 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
235 {
236  uint32_t tickstart = 0U;
237 
239 
240  /* Enable PWR RCC Clock Peripheral */
242 
243  /* Set Range */
244  __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
245 
246  /* Get Start Tick*/
247  tickstart = HAL_GetTick();
249  {
250  if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
251  {
252  return HAL_TIMEOUT;
253  }
254  }
255 
256  return HAL_OK;
257 }
258 
259 #elif defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
260  defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || \
261  defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F469xx) || \
262  defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || \
263  defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
264 
290 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
291 {
292  uint32_t tickstart = 0U;
293 
295 
296  /* Enable PWR RCC Clock Peripheral */
298 
299  /* Check if the PLL is used as system clock or not */
301  {
302  /* Disable the main PLL */
304 
305  /* Get Start Tick */
306  tickstart = HAL_GetTick();
307  /* Wait till PLL is disabled */
309  {
310  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
311  {
312  return HAL_TIMEOUT;
313  }
314  }
315 
316  /* Set Range */
317  __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
318 
319  /* Enable the main PLL */
321 
322  /* Get Start Tick */
323  tickstart = HAL_GetTick();
324  /* Wait till PLL is ready */
326  {
327  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
328  {
329  return HAL_TIMEOUT;
330  }
331  }
332 
333  /* Get Start Tick */
334  tickstart = HAL_GetTick();
336  {
337  if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
338  {
339  return HAL_TIMEOUT;
340  }
341  }
342  }
343  else
344  {
345  return HAL_ERROR;
346  }
347 
348  return HAL_OK;
349 }
350 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */
351 
352 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
353  defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) ||\
354  defined(STM32F413xx) || defined(STM32F423xx)
355 
362 {
363  *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)ENABLE;
364 }
365 
373 {
374  *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)DISABLE;
375 }
376 
384 {
385  *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)ENABLE;
386 }
387 
395 {
396  *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)DISABLE;
397 }
398 
399 #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx ||
400  STM32F413xx || STM32F423xx */
401 
402 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
403  defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
404 
416 {
417  uint32_t tickstart = 0U;
418 
420 
421  /* Enable the Over-drive to extend the clock frequency to 180 Mhz */
423 
424  /* Get tick */
425  tickstart = HAL_GetTick();
426 
428  {
429  if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
430  {
431  return HAL_TIMEOUT;
432  }
433  }
434 
435  /* Enable the Over-drive switch */
437 
438  /* Get tick */
439  tickstart = HAL_GetTick();
440 
442  {
443  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
444  {
445  return HAL_TIMEOUT;
446  }
447  }
448  return HAL_OK;
449 }
450 
463 {
464  uint32_t tickstart = 0U;
465 
467 
468  /* Disable the Over-drive switch */
470 
471  /* Get tick */
472  tickstart = HAL_GetTick();
473 
475  {
476  if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
477  {
478  return HAL_TIMEOUT;
479  }
480  }
481 
482  /* Disable the Over-drive */
484 
485  /* Get tick */
486  tickstart = HAL_GetTick();
487 
489  {
490  if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
491  {
492  return HAL_TIMEOUT;
493  }
494  }
495 
496  return HAL_OK;
497 }
498 
538 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
539 {
540  uint32_t tmpreg1 = 0U;
541 
542  /* Check the parameters */
544  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
545 
546  /* Enable Power ctrl clock */
548  /* Enable the Under-drive Mode ---------------------------------------------*/
549  /* Clear Under-drive flag */
551 
552  /* Enable the Under-drive */
554 
555  /* Select the regulator state in STOP mode ---------------------------------*/
556  tmpreg1 = PWR->CR;
557  /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */
558  tmpreg1 &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_LPUDS | PWR_CR_MRUDS);
559 
560  /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
561  tmpreg1 |= Regulator;
562 
563  /* Store the new value */
564  PWR->CR = tmpreg1;
565 
566  /* Set SLEEPDEEP bit of Cortex System Control Register */
567  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
568 
569  /* Select STOP mode entry --------------------------------------------------*/
570  if(STOPEntry == PWR_SLEEPENTRY_WFI)
571  {
572  /* Request Wait For Interrupt */
573  __WFI();
574  }
575  else
576  {
577  /* Request Wait For Event */
578  __WFE();
579  }
580  /* Reset SLEEPDEEP bit of Cortex System Control Register */
581  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
582 
583  return HAL_OK;
584 }
585 
586 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
587 
595 #endif /* HAL_PWR_MODULE_ENABLED */
596 
604 /************************ (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
CR_FPDS_BB
#define CR_FPDS_BB
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:248
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
PWR_CR_LPDS
#define PWR_CR_LPDS
Definition: stm32f407xx.h:9351
DISABLE
@ DISABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:193
PWR
#define PWR
Definition: stm32f407xx.h:1083
CSR_BRE_BB
#define CSR_BRE_BB
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:276
PWR_FLAG_ODRDY
#define PWR_FLAG_ODRDY
Definition: stm32f7xx_hal_pwr_ex.h:82
CR_MRLVDS_BB
#define CR_MRLVDS_BB
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:260
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
IS_PWR_VOLTAGE_SCALING_RANGE
#define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:304
PWR_CR_PDDS
#define PWR_CR_PDDS
Definition: stm32f407xx.h:9354
HAL_ERROR
@ HAL_ERROR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:43
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
ENABLE
@ ENABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:194
__HAL_RCC_PLL_DISABLE
#define __HAL_RCC_PLL_DISABLE()
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:1038
PWR_CR_VOS
#define PWR_CR_VOS
Definition: stm32f407xx.h:9389
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
CR_LPLVDS_BB
#define CR_LPLVDS_BB
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:264
HAL_PWREx_DisableOverDrive
HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
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_CR_LPUDS
#define PWR_CR_LPUDS
Definition: stm32f469xx.h:13196
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)
PWR_CR_MRUDS
#define PWR_CR_MRUDS
Definition: stm32f469xx.h:13197
__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)
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
__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
SCB_SCR_SLEEPDEEP_Msk
#define SCB_SCR_SLEEPDEEP_Msk
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:587


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