]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/ST_Library/stm32f7xx_hal_pwr_ex.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL / ST_Library / stm32f7xx_hal_pwr_ex.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_pwr_ex.c\r
4   * @author  MCD Application Team\r
5   * @version V0.3.0\r
6   * @date    06-March-2015\r
7   * @brief   Extended PWR HAL module driver.\r
8   *          This file provides firmware functions to manage the following \r
9   *          functionalities of PWR extension peripheral:           \r
10   *           + Peripheral Extended features functions\r
11   *         \r
12   ******************************************************************************\r
13   * @attention\r
14   *\r
15   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
16   *\r
17   * Redistribution and use in source and binary forms, with or without modification,\r
18   * are permitted provided that the following conditions are met:\r
19   *   1. Redistributions of source code must retain the above copyright notice,\r
20   *      this list of conditions and the following disclaimer.\r
21   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
22   *      this list of conditions and the following disclaimer in the documentation\r
23   *      and/or other materials provided with the distribution.\r
24   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
25   *      may be used to endorse or promote products derived from this software\r
26   *      without specific prior written permission.\r
27   *\r
28   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
29   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
30   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
31   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
32   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
33   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
34   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
35   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
36   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
37   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
38   *\r
39   ******************************************************************************\r
40   */ \r
41 \r
42 /* Includes ------------------------------------------------------------------*/\r
43 #include "stm32f7xx_hal.h"\r
44 \r
45 /** @addtogroup STM32F7xx_HAL_Driver\r
46   * @{\r
47   */\r
48 \r
49 /** @defgroup PWREx PWREx\r
50   * @brief PWR HAL module driver\r
51   * @{\r
52   */\r
53 \r
54 #ifdef HAL_PWR_MODULE_ENABLED\r
55 \r
56 /* Private typedef -----------------------------------------------------------*/\r
57 /* Private define ------------------------------------------------------------*/\r
58 /** @addtogroup PWREx_Private_Constants\r
59   * @{\r
60   */    \r
61 #define PWR_OVERDRIVE_TIMEOUT_VALUE  1000\r
62 #define PWR_UDERDRIVE_TIMEOUT_VALUE  1000\r
63 #define PWR_BKPREG_TIMEOUT_VALUE     1000\r
64 #define PWR_VOSRDY_TIMEOUT_VALUE     1000\r
65 /**\r
66   * @}\r
67   */\r
68     \r
69 /* Private macro -------------------------------------------------------------*/\r
70 /* Private variables ---------------------------------------------------------*/\r
71 /* Private function prototypes -----------------------------------------------*/\r
72 /* Private functions ---------------------------------------------------------*/\r
73 /** @defgroup PWREx_Exported_Functions PWREx Exported Functions\r
74   *  @{\r
75   */\r
76 \r
77 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended features functions \r
78   *  @brief Peripheral Extended features functions \r
79   *\r
80 @verbatim   \r
81 \r
82  ===============================================================================\r
83                  ##### Peripheral extended features functions #####\r
84  ===============================================================================\r
85 \r
86     *** Main and Backup Regulators configuration ***\r
87     ================================================\r
88     [..] \r
89       (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from \r
90           the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is \r
91           retained even in Standby or VBAT mode when the low power backup regulator\r
92           is enabled. It can be considered as an internal EEPROM when VBAT is \r
93           always present. You can use the HAL_PWREx_EnableBkUpReg() function to \r
94           enable the low power backup regulator. \r
95 \r
96       (+) When the backup domain is supplied by VDD (analog switch connected to VDD) \r
97           the backup SRAM is powered from VDD which replaces the VBAT power supply to \r
98           save battery life.\r
99 \r
100       (+) The backup SRAM is not mass erased by a tamper event. It is read \r
101           protected to prevent confidential data, such as cryptographic private \r
102           key, from being accessed. The backup SRAM can be erased only through \r
103           the Flash interface when a protection level change from level 1 to \r
104           level 0 is requested. \r
105       -@- Refer to the description of Read protection (RDP) in the Flash \r
106           programming manual.\r
107 \r
108       (+) The main internal regulator can be configured to have a tradeoff between \r
109           performance and power consumption when the device does not operate at \r
110           the maximum frequency. This is done through __HAL_PWR_MAINREGULATORMODE_CONFIG() \r
111           macro which configure VOS bit in PWR_CR register\r
112           \r
113         Refer to the product datasheets for more details.\r
114 \r
115     *** FLASH Power Down configuration ****\r
116     =======================================\r
117     [..] \r
118       (+) By setting the FPDS bit in the PWR_CR register by using the \r
119           HAL_PWREx_EnableFlashPowerDown() function, the Flash memory also enters power \r
120           down mode when the device enters Stop mode. When the Flash memory \r
121           is in power down mode, an additional startup delay is incurred when \r
122           waking up from Stop mode.\r
123 \r
124     *** Over-Drive and Under-Drive configuration ****\r
125     =================================================\r
126     [..]         \r
127        (+) In Run mode: the main regulator has 2 operating modes available:\r
128         (++) Normal mode: The CPU and core logic operate at maximum frequency at a given \r
129              voltage scaling (scale 1, scale 2 or scale 3)\r
130         (++) Over-drive mode: This mode allows the CPU and the core logic to operate at a \r
131             higher frequency than the normal mode for a given voltage scaling (scale 1,  \r
132             scale 2 or scale 3). This mode is enabled through HAL_PWREx_EnableOverDrive() function and\r
133             disabled by HAL_PWREx_DisableOverDrive() function, to enter or exit from Over-drive mode please follow \r
134             the sequence described in Reference manual.\r
135              \r
136        (+) In Stop mode: the main regulator or low power regulator supplies a low power \r
137            voltage to the 1.2V domain, thus preserving the content of registers \r
138            and internal SRAM. 2 operating modes are available:\r
139          (++) Normal mode: the 1.2V domain is preserved in nominal leakage mode. This mode is only \r
140               available when the main regulator or the low power regulator is used in Scale 3 or \r
141               low voltage mode.\r
142          (++) Under-drive mode: the 1.2V domain is preserved in reduced leakage mode. This mode is only\r
143               available when the main regulator or the low power regulator is in low voltage mode.\r
144 \r
145 @endverbatim\r
146   * @{\r
147   */\r
148 \r
149 /**\r
150   * @brief Enables the Backup Regulator.\r
151   * @retval HAL status\r
152   */\r
153 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)\r
154 {\r
155   uint32_t tickstart = 0;\r
156 \r
157   /* Enable Backup regulator */\r
158   PWR->CSR1 |= PWR_CSR1_BRE;\r
159 \r
160   /* Get tick */\r
161   tickstart = HAL_GetTick();\r
162 \r
163   /* Wait till Backup regulator ready flag is set */  \r
164   while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET)\r
165   {\r
166     if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)\r
167     {\r
168       return HAL_TIMEOUT;\r
169     } \r
170   }\r
171   return HAL_OK;\r
172 }\r
173 \r
174 /**\r
175   * @brief Disables the Backup Regulator.\r
176   * @retval HAL status\r
177   */\r
178 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)\r
179 {\r
180   uint32_t tickstart = 0;\r
181   \r
182   /* Disable Backup regulator */\r
183   PWR->CSR1 &= (uint32_t)~((uint32_t)PWR_CSR1_BRE);\r
184 \r
185   /* Get tick */\r
186   tickstart = HAL_GetTick();\r
187 \r
188   /* Wait till Backup regulator ready flag is set */  \r
189   while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)\r
190   {\r
191     if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)\r
192     {\r
193       return HAL_TIMEOUT;\r
194     } \r
195   }\r
196   return HAL_OK;\r
197 }\r
198 \r
199 /**\r
200   * @brief Enables the Flash Power Down in Stop mode.\r
201   * @retval None\r
202   */\r
203 void HAL_PWREx_EnableFlashPowerDown(void)\r
204 {\r
205   /* Enable the Flash Power Down */\r
206   PWR->CR1 |= PWR_CR1_FPDS;\r
207 }\r
208 \r
209 /**\r
210   * @brief Disables the Flash Power Down in Stop mode.\r
211   * @retval None\r
212   */\r
213 void HAL_PWREx_DisableFlashPowerDown(void)\r
214 {\r
215   /* Disable the Flash Power Down */\r
216   PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_FPDS);\r
217 }\r
218 \r
219 /**\r
220   * @brief Enables Main Regulator low voltage mode.\r
221   * @retval None\r
222   */\r
223 void HAL_PWREx_EnableMainRegulatorLowVoltage(void)\r
224 {\r
225   /* Enable Main regulator low voltage */\r
226   PWR->CR1 |= PWR_CR1_MRUDS;\r
227 }\r
228 \r
229 /**\r
230   * @brief Disables Main Regulator low voltage mode.\r
231   * @retval None\r
232   */\r
233 void HAL_PWREx_DisableMainRegulatorLowVoltage(void)\r
234 {  \r
235   /* Disable Main regulator low voltage */\r
236   PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_MRUDS);\r
237 }\r
238 \r
239 /**\r
240   * @brief Enables Low Power Regulator low voltage mode.\r
241   * @retval None\r
242   */\r
243 void HAL_PWREx_EnableLowRegulatorLowVoltage(void)\r
244 {\r
245   /* Enable low power regulator */\r
246   PWR->CR1 |= PWR_CR1_LPUDS;\r
247 }\r
248 \r
249 /**\r
250   * @brief Disables Low Power Regulator low voltage mode.\r
251   * @retval None\r
252   */\r
253 void HAL_PWREx_DisableLowRegulatorLowVoltage(void)\r
254 {\r
255   /* Disable low power regulator */\r
256   PWR->CR1 &= (uint32_t)~((uint32_t)PWR_CR1_LPUDS);\r
257 }\r
258 \r
259 /**\r
260   * @brief  Activates the Over-Drive mode.\r
261   * @note   This mode allows the CPU and the core logic to operate at a higher frequency\r
262   *         than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).   \r
263   * @note   It is recommended to enter or exit Over-drive mode when the application is not running \r
264   *         critical tasks and when the system clock source is either HSI or HSE. \r
265   *         During the Over-drive switch activation, no peripheral clocks should be enabled.   \r
266   *         The peripheral clocks must be enabled once the Over-drive mode is activated.   \r
267   * @retval HAL status\r
268   */\r
269 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)\r
270 {\r
271   uint32_t tickstart = 0;\r
272 \r
273   __HAL_RCC_PWR_CLK_ENABLE();\r
274   \r
275   /* Enable the Over-drive to extend the clock frequency to 200 Mhz */\r
276   __HAL_PWR_OVERDRIVE_ENABLE();\r
277 \r
278   /* Get tick */\r
279   tickstart = HAL_GetTick();\r
280 \r
281   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))\r
282   {\r
283     if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)\r
284     {\r
285       return HAL_TIMEOUT;\r
286     }\r
287   }\r
288   \r
289   /* Enable the Over-drive switch */\r
290   __HAL_PWR_OVERDRIVESWITCHING_ENABLE();\r
291 \r
292   /* Get tick */\r
293   tickstart = HAL_GetTick();\r
294 \r
295   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))\r
296   {\r
297     if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)\r
298     {\r
299       return HAL_TIMEOUT;\r
300     }\r
301   } \r
302   return HAL_OK;\r
303 }\r
304 \r
305 /**\r
306   * @brief  Deactivates the Over-Drive mode.\r
307   * @note   This mode allows the CPU and the core logic to operate at a higher frequency\r
308   *         than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).    \r
309   * @note   It is recommended to enter or exit Over-drive mode when the application is not running \r
310   *         critical tasks and when the system clock source is either HSI or HSE. \r
311   *         During the Over-drive switch activation, no peripheral clocks should be enabled.   \r
312   *         The peripheral clocks must be enabled once the Over-drive mode is activated.\r
313   * @retval HAL status\r
314   */\r
315 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)\r
316 {\r
317   uint32_t tickstart = 0;\r
318   \r
319   __HAL_RCC_PWR_CLK_ENABLE();\r
320     \r
321   /* Disable the Over-drive switch */\r
322   __HAL_PWR_OVERDRIVESWITCHING_DISABLE();\r
323   \r
324   /* Get tick */\r
325   tickstart = HAL_GetTick();\r
326  \r
327   while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))\r
328   {\r
329     if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)\r
330     {\r
331       return HAL_TIMEOUT;\r
332     }\r
333   } \r
334   \r
335   /* Disable the Over-drive */\r
336   __HAL_PWR_OVERDRIVE_DISABLE();\r
337 \r
338   /* Get tick */\r
339   tickstart = HAL_GetTick();\r
340 \r
341   while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))\r
342   {\r
343     if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)\r
344     {\r
345       return HAL_TIMEOUT;\r
346     }\r
347   }\r
348   \r
349   return HAL_OK;\r
350 }\r
351 \r
352 /**\r
353   * @brief  Enters in Under-Drive STOP mode.\r
354   * \r
355   * @note    This mode can be selected only when the Under-Drive is already active \r
356   *   \r
357   * @note    This mode is enabled only with STOP low power mode.\r
358   *          In this mode, the 1.2V domain is preserved in reduced leakage mode. This \r
359   *          mode is only available when the main regulator or the low power regulator \r
360   *          is in low voltage mode\r
361   *        \r
362   * @note   If the Under-drive mode was enabled, it is automatically disabled after \r
363   *         exiting Stop mode. \r
364   *         When the voltage regulator operates in Under-drive mode, an additional  \r
365   *         startup delay is induced when waking up from Stop mode.\r
366   *                    \r
367   * @note   In Stop mode, all I/O pins keep the same state as in Run mode.\r
368   *   \r
369   * @note   When exiting Stop mode by issuing an interrupt or a wakeup event, \r
370   *         the HSI RC oscillator is selected as system clock.\r
371   *           \r
372   * @note   When the voltage regulator operates in low power mode, an additional \r
373   *         startup delay is incurred when waking up from Stop mode. \r
374   *         By keeping the internal regulator ON during Stop mode, the consumption \r
375   *         is higher although the startup time is reduced.\r
376   *     \r
377   * @param  Regulator: specifies the regulator state in STOP mode.\r
378   *          This parameter can be one of the following values:\r
379   *            @arg PWR_MAINREGULATOR_UNDERDRIVE_ON:  Main Regulator in under-drive mode \r
380   *                 and Flash memory in power-down when the device is in Stop under-drive mode\r
381   *            @arg PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON:  Low Power Regulator in under-drive mode \r
382   *                and Flash memory in power-down when the device is in Stop under-drive mode\r
383   * @param  STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.\r
384   *          This parameter can be one of the following values:\r
385   *            @arg PWR_SLEEPENTRY_WFI: enter STOP mode with WFI instruction\r
386   *            @arg PWR_SLEEPENTRY_WFE: enter STOP mode with WFE instruction\r
387   * @retval None\r
388   */\r
389 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)\r
390 {\r
391   uint32_t tempreg = 0;\r
392   uint32_t tickstart = 0;\r
393   \r
394   /* Check the parameters */\r
395   assert_param(IS_PWR_REGULATOR_UNDERDRIVE(Regulator));\r
396   assert_param(IS_PWR_STOP_ENTRY(STOPEntry));\r
397   \r
398   /* Enable Power ctrl clock */\r
399   __HAL_RCC_PWR_CLK_ENABLE();\r
400   /* Enable the Under-drive Mode ---------------------------------------------*/\r
401   /* Clear Under-drive flag */\r
402   __HAL_PWR_CLEAR_ODRUDR_FLAG();\r
403   \r
404   /* Enable the Under-drive */ \r
405   __HAL_PWR_UNDERDRIVE_ENABLE();\r
406 \r
407   /* Get tick */\r
408   tickstart = HAL_GetTick();\r
409 \r
410   /* Wait for UnderDrive mode is ready */\r
411   while(__HAL_PWR_GET_FLAG(PWR_FLAG_UDRDY))\r
412   {\r
413     if((HAL_GetTick() - tickstart ) > PWR_UDERDRIVE_TIMEOUT_VALUE)\r
414     {\r
415       return HAL_TIMEOUT;\r
416     }\r
417   }\r
418   \r
419   /* Select the regulator state in STOP mode ---------------------------------*/\r
420   tempreg = PWR->CR1;\r
421   /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */\r
422   tempreg &= (uint32_t)~(PWR_CR1_PDDS | PWR_CR1_LPDS | PWR_CR1_LPUDS | PWR_CR1_MRUDS);\r
423   \r
424   /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */\r
425   tempreg |= Regulator;\r
426   \r
427   /* Store the new value */\r
428   PWR->CR1 = tempreg;\r
429   \r
430   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
431   SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\r
432   \r
433   /* Select STOP mode entry --------------------------------------------------*/\r
434   if(STOPEntry == PWR_SLEEPENTRY_WFI)\r
435   {   \r
436     /* Request Wait For Interrupt */\r
437     __WFI();\r
438   }\r
439   else\r
440   {\r
441     /* Request Wait For Event */\r
442     __WFE();\r
443   }\r
444   /* Reset SLEEPDEEP bit of Cortex System Control Register */\r
445   SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);\r
446 \r
447   return HAL_OK;  \r
448 }\r
449 \r
450 /**\r
451   * @brief Returns Voltage Scaling Range.\r
452   * @param  None       \r
453   * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1, PWR_REGULATOR_VOLTAGE_SCALE2 or \r
454   *            PWR_REGULATOR_VOLTAGE_SCALE3)PWR_REGULATOR_VOLTAGE_SCALE1\r
455   */  \r
456 uint32_t HAL_PWREx_GetVoltageRange(void)\r
457 {\r
458   return  (PWR->CR1 & PWR_CR1_VOS);\r
459 }\r
460 \r
461 /**\r
462   * @brief Configures the main internal regulator output voltage.\r
463   * @param  VoltageScaling: specifies the regulator output voltage to achieve\r
464   *         a tradeoff between performance and power consumption.\r
465   *          This parameter can be one of the following values:\r
466   *            @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output range 1 mode,\r
467   *                                                typical output voltage at 1.4 V,  \r
468   *                                                system frequency up to 200 MHz.\r
469   *            @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output range 2 mode,\r
470   *                                                typical output voltage at 1.2 V,                \r
471   *                                                system frequency up to 180 MHz.\r
472   *            @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output range 2 mode,\r
473   *                                                typical output voltage at 1.00 V,                \r
474   *                                                system frequency up to 151 MHz.\r
475   * @note To update the system clock frequency(SYSCLK):\r
476   *        - Set the HSI or HSE as system clock frequency using the HAL_RCC_ClockConfig().\r
477   *        - Call the HAL_RCC_OscConfig() to configure the PLL.\r
478   *        - Call HAL_PWREx_ConfigVoltageScaling() API to adjust the voltage scale.\r
479   *        - Set the new system clock frequency using the HAL_RCC_ClockConfig().\r
480   * @note The scale can be modified only when the HSI or HSE clock source is selected \r
481   *        as system clock source, otherwise the API returns HAL_ERROR.  \r
482   * @note When the PLL is OFF, the voltage scale 3 is automatically selected and the VOS bits\r
483   *       value in the PWR_CR1 register are not taken in account.\r
484   * @note This API forces the PLL state ON to allow the possibility to configure the voltage scale 1 or 2.\r
485   * @note The new voltage scale is active only when the PLL is ON.  \r
486   * @retval HAL Status\r
487   */\r
488 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)\r
489 {\r
490   uint32_t tickstart = 0;\r
491 \r
492   assert_param(IS_PWR_REGULATOR_VOLTAGE(VoltageScaling));\r
493 \r
494   /* Enable Power ctrl clock */\r
495   __HAL_RCC_PWR_CLK_ENABLE();\r
496 \r
497   /* Check if the PLL is used as system clock or not */\r
498   if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)\r
499   {\r
500     /* Disable the main PLL */\r
501     __HAL_RCC_PLL_DISABLE();\r
502     \r
503     /* Get Start Tick */\r
504     tickstart = HAL_GetTick();    \r
505     /* Wait till PLL is disabled */  \r
506     while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)\r
507     {\r
508       if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)\r
509       {\r
510         return HAL_TIMEOUT;\r
511       }\r
512     }\r
513     \r
514     /* Set Range */\r
515     __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);\r
516     \r
517     /* Enable the main PLL */\r
518     __HAL_RCC_PLL_ENABLE();\r
519     \r
520     /* Get Start Tick */\r
521     tickstart = HAL_GetTick();\r
522     /* Wait till PLL is ready */  \r
523     while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)\r
524     {\r
525       if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)\r
526       {\r
527         return HAL_TIMEOUT;\r
528       } \r
529     }\r
530     \r
531     /* Get Start Tick */\r
532     tickstart = HAL_GetTick();\r
533     while((__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY) == RESET))\r
534     {\r
535       if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)\r
536       {\r
537         return HAL_TIMEOUT;\r
538       } \r
539     }\r
540   }\r
541   else\r
542   {\r
543     return HAL_ERROR;\r
544   }\r
545   return HAL_OK;\r
546 }\r
547 \r
548 /**\r
549   * @}\r
550   */\r
551 \r
552 /**\r
553   * @}\r
554   */\r
555 \r
556 #endif /* HAL_PWR_MODULE_ENABLED */\r
557 /**\r
558   * @}\r
559   */\r
560 \r
561 /**\r
562   * @}\r
563   */\r
564 \r
565 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r