STM32F4xx_HAL_Driver  1.8.3
stm32f4xx_hal_pwr_ex.c
Go to the documentation of this file.
1 
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f4xx_hal.h"
24 
34 #ifdef HAL_PWR_MODULE_ENABLED
35 
36 /* Private typedef -----------------------------------------------------------*/
37 /* Private define ------------------------------------------------------------*/
41 #define PWR_OVERDRIVE_TIMEOUT_VALUE 1000U
42 #define PWR_UDERDRIVE_TIMEOUT_VALUE 1000U
43 #define PWR_BKPREG_TIMEOUT_VALUE 1000U
44 #define PWR_VOSRDY_TIMEOUT_VALUE 1000U
50 /* Private macro -------------------------------------------------------------*/
51 /* Private variables ---------------------------------------------------------*/
52 /* Private function prototypes -----------------------------------------------*/
53 /* Private functions ---------------------------------------------------------*/
141 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
142 {
143  uint32_t tickstart = 0U;
144 
145  *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)ENABLE;
146 
147  /* Get tick */
148  tickstart = HAL_GetTick();
149 
150  /* Wait till Backup regulator ready flag is set */
151  while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET)
152  {
153  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
154  {
155  return HAL_TIMEOUT;
156  }
157  }
158  return HAL_OK;
159 }
160 
165 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
166 {
167  uint32_t tickstart = 0U;
168 
169  *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)DISABLE;
170 
171  /* Get tick */
172  tickstart = HAL_GetTick();
173 
174  /* Wait till Backup regulator ready flag is set */
175  while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)
176  {
177  if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
178  {
179  return HAL_TIMEOUT;
180  }
181  }
182  return HAL_OK;
183 }
184 
190 {
191  *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)ENABLE;
192 }
193 
199 {
200  *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)DISABLE;
201 }
202 
212 {
213  return (PWR->CR & PWR_CR_VOS);
214 }
215 
216 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)
232 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
233 {
234  uint32_t tickstart = 0U;
235 
236  assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
237 
238  /* Enable PWR RCC Clock Peripheral */
239  __HAL_RCC_PWR_CLK_ENABLE();
240 
241  /* Set Range */
242  __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
243 
244  /* Get Start Tick*/
245  tickstart = HAL_GetTick();
246  while((__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY) == RESET))
247  {
248  if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
249  {
250  return HAL_TIMEOUT;
251  }
252  }
253 
254  return HAL_OK;
255 }
256 
257 #elif defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
258  defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || \
259  defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F469xx) || \
260  defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || \
261  defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
288 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
289 {
290  uint32_t tickstart = 0U;
291 
292  assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
293 
294  /* Enable PWR RCC Clock Peripheral */
295  __HAL_RCC_PWR_CLK_ENABLE();
296 
297  /* Check if the PLL is used as system clock or not */
298  if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
299  {
300  /* Disable the main PLL */
301  __HAL_RCC_PLL_DISABLE();
302 
303  /* Get Start Tick */
304  tickstart = HAL_GetTick();
305  /* Wait till PLL is disabled */
306  while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
307  {
308  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
309  {
310  return HAL_TIMEOUT;
311  }
312  }
313 
314  /* Set Range */
315  __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
316 
317  /* Enable the main PLL */
318  __HAL_RCC_PLL_ENABLE();
319 
320  /* Get Start Tick */
321  tickstart = HAL_GetTick();
322  /* Wait till PLL is ready */
323  while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
324  {
325  if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
326  {
327  return HAL_TIMEOUT;
328  }
329  }
330 
331  /* Get Start Tick */
332  tickstart = HAL_GetTick();
333  while((__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY) == RESET))
334  {
335  if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
336  {
337  return HAL_TIMEOUT;
338  }
339  }
340  }
341  else
342  {
343  return HAL_ERROR;
344  }
345 
346  return HAL_OK;
347 }
348 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */
349 
350 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
351  defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) ||\
352  defined(STM32F413xx) || defined(STM32F423xx)
360 {
361  *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)ENABLE;
362 }
363 
371 {
372  *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)DISABLE;
373 }
374 
382 {
383  *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)ENABLE;
384 }
385 
393 {
394  *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)DISABLE;
395 }
396 
397 #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx ||
398  STM32F413xx || STM32F423xx */
399 
400 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
401  defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
413 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
414 {
415  uint32_t tickstart = 0U;
416 
417  __HAL_RCC_PWR_CLK_ENABLE();
418 
419  /* Enable the Over-drive to extend the clock frequency to 180 Mhz */
420  __HAL_PWR_OVERDRIVE_ENABLE();
421 
422  /* Get tick */
423  tickstart = HAL_GetTick();
424 
425  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
426  {
427  if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
428  {
429  return HAL_TIMEOUT;
430  }
431  }
432 
433  /* Enable the Over-drive switch */
434  __HAL_PWR_OVERDRIVESWITCHING_ENABLE();
435 
436  /* Get tick */
437  tickstart = HAL_GetTick();
438 
439  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
440  {
441  if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
442  {
443  return HAL_TIMEOUT;
444  }
445  }
446  return HAL_OK;
447 }
448 
460 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
461 {
462  uint32_t tickstart = 0U;
463 
464  __HAL_RCC_PWR_CLK_ENABLE();
465 
466  /* Disable the Over-drive switch */
467  __HAL_PWR_OVERDRIVESWITCHING_DISABLE();
468 
469  /* Get tick */
470  tickstart = HAL_GetTick();
471 
472  while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
473  {
474  if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
475  {
476  return HAL_TIMEOUT;
477  }
478  }
479 
480  /* Disable the Over-drive */
481  __HAL_PWR_OVERDRIVE_DISABLE();
482 
483  /* Get tick */
484  tickstart = HAL_GetTick();
485 
486  while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
487  {
488  if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
489  {
490  return HAL_TIMEOUT;
491  }
492  }
493 
494  return HAL_OK;
495 }
496 
536 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
537 {
538  uint32_t tmpreg1 = 0U;
539 
540  /* Check the parameters */
541  assert_param(IS_PWR_REGULATOR_UNDERDRIVE(Regulator));
542  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
543 
544  /* Enable Power ctrl clock */
545  __HAL_RCC_PWR_CLK_ENABLE();
546  /* Enable the Under-drive Mode ---------------------------------------------*/
547  /* Clear Under-drive flag */
548  __HAL_PWR_CLEAR_ODRUDR_FLAG();
549 
550  /* Enable the Under-drive */
551  __HAL_PWR_UNDERDRIVE_ENABLE();
552 
553  /* Select the regulator state in STOP mode ---------------------------------*/
554  tmpreg1 = PWR->CR;
555  /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */
556  tmpreg1 &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_LPUDS | PWR_CR_MRUDS);
557 
558  /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
559  tmpreg1 |= Regulator;
560 
561  /* Store the new value */
562  PWR->CR = tmpreg1;
563 
564  /* Set SLEEPDEEP bit of Cortex System Control Register */
565  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
566 
567  /* Select STOP mode entry --------------------------------------------------*/
568  if(STOPEntry == PWR_SLEEPENTRY_WFI)
569  {
570  /* Request Wait For Interrupt */
571  __WFI();
572  }
573  else
574  {
575  /* Request Wait For Event */
576  __WFE();
577  }
578  /* Reset SLEEPDEEP bit of Cortex System Control Register */
579  SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
580 
581  return HAL_OK;
582 }
583 
584 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
593 #endif /* HAL_PWR_MODULE_ENABLED */
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
void HAL_PWREx_DisableLowRegulatorLowVoltage(void)
Disables Low Power Regulator low voltage mode.
void HAL_PWREx_DisableFlashPowerDown(void)
Disables the Flash Power Down in Stop mode.
HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
Configures the main internal regulator output voltage.
HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
Enables the Backup Regulator.
uint32_t HAL_PWREx_GetVoltageRange(void)
Return Voltage Scaling Range.
HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
Enters in Under-Drive STOP mode.
HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
Deactivates the Over-Drive mode.
void HAL_PWREx_EnableFlashPowerDown(void)
Enables the Flash Power Down in Stop mode.
void HAL_PWREx_EnableMainRegulatorLowVoltage(void)
Enables Main Regulator low voltage mode.
HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
Activates the Over-Drive mode.
void HAL_PWREx_EnableLowRegulatorLowVoltage(void)
Enables Low Power Regulator low voltage mode.
HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
Disables the Backup Regulator.
void HAL_PWREx_DisableMainRegulatorLowVoltage(void)
Disables Main Regulator low voltage mode.
This file contains all the functions prototypes for the HAL module driver.