]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c
Make vSetupTimerInterrupt weak in the RVDS M4 MPU port to give the
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube / ST_Code / Drivers / STM32L4xx_HAL_Driver / Src / stm32l4xx_hal_pwr_ex.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l4xx_hal_pwr_ex.c\r
4   * @author  MCD Application Team\r
5   * @brief   Extended PWR HAL module driver.\r
6   *          This file provides firmware functions to manage the following\r
7   *          functionalities of the Power Controller (PWR) peripheral:\r
8   *           + Extended Initialization and de-initialization functions\r
9   *           + Extended Peripheral Control functions\r
10   *\r
11   ******************************************************************************\r
12   * @attention\r
13   *\r
14   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.\r
15   * All rights reserved.</center></h2>\r
16   *\r
17   * This software component is licensed by ST under BSD 3-Clause license,\r
18   * the "License"; You may not use this file except in compliance with the\r
19   * License. You may obtain a copy of the License at:\r
20   *                        opensource.org/licenses/BSD-3-Clause\r
21   *\r
22   ******************************************************************************\r
23   */\r
24 \r
25 /* Includes ------------------------------------------------------------------*/\r
26 #include "stm32l4xx_hal.h"\r
27 \r
28 /** @addtogroup STM32L4xx_HAL_Driver\r
29   * @{\r
30   */\r
31 \r
32 /** @defgroup PWREx PWREx\r
33   * @brief PWR Extended HAL module driver\r
34   * @{\r
35   */\r
36 \r
37 #ifdef HAL_PWR_MODULE_ENABLED\r
38 \r
39 /* Private typedef -----------------------------------------------------------*/\r
40 /* Private define ------------------------------------------------------------*/\r
41 \r
42 #if defined (STM32L412xx) || defined (STM32L422xx) || defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx)\r
43 #define PWR_PORTH_AVAILABLE_PINS   ((uint32_t)0x0000000B) /* PH0/PH1/PH3 */\r
44 #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)\r
45 #define PWR_PORTH_AVAILABLE_PINS   ((uint32_t)0x0000000B) /* PH0/PH1/PH3 */\r
46 #elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx)\r
47 #define PWR_PORTH_AVAILABLE_PINS   ((uint32_t)0x00000003) /* PH0/PH1 */\r
48 #elif defined (STM32L496xx) || defined (STM32L4A6xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)\r
49 #define PWR_PORTH_AVAILABLE_PINS   ((uint32_t)0x0000FFFF) /* PH0..PH15 */\r
50 #endif\r
51 \r
52 #if defined (STM32L496xx) || defined (STM32L4A6xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)\r
53 #define PWR_PORTI_AVAILABLE_PINS   ((uint32_t)0x00000FFF) /* PI0..PI11 */\r
54 #endif\r
55 \r
56 /** @defgroup PWR_Extended_Private_Defines PWR Extended Private Defines\r
57   * @{\r
58   */\r
59 \r
60 /** @defgroup PWREx_PVM_Mode_Mask PWR PVM Mode Mask\r
61   * @{\r
62   */\r
63 #define PVM_MODE_IT               ((uint32_t)0x00010000)  /*!< Mask for interruption yielded by PVM threshold crossing */\r
64 #define PVM_MODE_EVT              ((uint32_t)0x00020000)  /*!< Mask for event yielded by PVM threshold crossing        */\r
65 #define PVM_RISING_EDGE           ((uint32_t)0x00000001)  /*!< Mask for rising edge set as PVM trigger                 */\r
66 #define PVM_FALLING_EDGE          ((uint32_t)0x00000002)  /*!< Mask for falling edge set as PVM trigger                */\r
67 /**\r
68   * @}\r
69   */\r
70 \r
71 /** @defgroup PWREx_TimeOut_Value PWR Extended Flag Setting Time Out Value\r
72   * @{\r
73   */\r
74 #define PWR_FLAG_SETTING_DELAY_US                      50UL   /*!< Time out value for REGLPF and VOSF flags setting */\r
75 /**\r
76   * @}\r
77   */\r
78 \r
79 \r
80 \r
81 /**\r
82   * @}\r
83   */\r
84 \r
85 \r
86 \r
87 /* Private macro -------------------------------------------------------------*/\r
88 /* Private variables ---------------------------------------------------------*/\r
89 /* Private function prototypes -----------------------------------------------*/\r
90 /* Exported functions --------------------------------------------------------*/\r
91 \r
92 /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions\r
93   * @{\r
94   */\r
95 \r
96 /** @defgroup PWREx_Exported_Functions_Group1 Extended Peripheral Control functions\r
97   *  @brief   Extended Peripheral Control functions\r
98   *\r
99 @verbatim\r
100  ===============================================================================\r
101               ##### Extended Peripheral Initialization and de-initialization functions #####\r
102  ===============================================================================\r
103     [..]\r
104 \r
105 @endverbatim\r
106   * @{\r
107   */\r
108 \r
109 \r
110 /**\r
111   * @brief Return Voltage Scaling Range.\r
112   * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_RANGE1 or PWR_REGULATOR_VOLTAGE_RANGE2\r
113   *         or PWR_REGULATOR_VOLTAGE_SCALE1_BOOST when applicable)\r
114   */\r
115 uint32_t HAL_PWREx_GetVoltageRange(void)\r
116 {\r
117 #if defined(PWR_CR5_R1MODE)\r
118     if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)\r
119     {\r
120       return PWR_REGULATOR_VOLTAGE_SCALE2;\r
121     }\r
122     else if (READ_BIT(PWR->CR5, PWR_CR5_R1MODE) == PWR_CR5_R1MODE)\r
123     {\r
124       /* PWR_CR5_R1MODE bit set means that Range 1 Boost is disabled */\r
125       return PWR_REGULATOR_VOLTAGE_SCALE1;\r
126     }\r
127     else\r
128     {\r
129       return PWR_REGULATOR_VOLTAGE_SCALE1_BOOST;\r
130     }\r
131 #else\r
132   return  (PWR->CR1 & PWR_CR1_VOS);\r
133 #endif\r
134 }\r
135 \r
136 \r
137 \r
138 /**\r
139   * @brief Configure the main internal regulator output voltage.\r
140   * @param  VoltageScaling: specifies the regulator output voltage to achieve\r
141   *         a tradeoff between performance and power consumption.\r
142   *          This parameter can be one of the following values:\r
143   @if STM32L4S9xx\r
144   *            @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1_BOOST when available, Regulator voltage output range 1 boost mode,\r
145   *                                                typical output voltage at 1.2 V,\r
146   *                                                system frequency up to 120 MHz.\r
147   @endif\r
148   *            @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1 Regulator voltage output range 1 mode,\r
149   *                                                typical output voltage at 1.2 V,\r
150   *                                                system frequency up to 80 MHz.\r
151   *            @arg @ref PWR_REGULATOR_VOLTAGE_SCALE2 Regulator voltage output range 2 mode,\r
152   *                                                typical output voltage at 1.0 V,\r
153   *                                                system frequency up to 26 MHz.\r
154   * @note  When moving from Range 1 to Range 2, the system frequency must be decreased to\r
155   *        a value below 26 MHz before calling HAL_PWREx_ControlVoltageScaling() API.\r
156   *        When moving from Range 2 to Range 1, the system frequency can be increased to\r
157   *        a value up to 80 MHz after calling HAL_PWREx_ControlVoltageScaling() API. For\r
158   *        some devices, the system frequency can be increased up to 120 MHz.\r
159   * @note  When moving from Range 2 to Range 1, the API waits for VOSF flag to be\r
160   *        cleared before returning the status. If the flag is not cleared within\r
161   *        50 microseconds, HAL_TIMEOUT status is reported.\r
162   * @retval HAL Status\r
163   */\r
164 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)\r
165 {\r
166   uint32_t wait_loop_index;\r
167 \r
168   assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));\r
169 \r
170 #if defined(PWR_CR5_R1MODE)\r
171   if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1_BOOST)\r
172   {\r
173     /* If current range is range 2 */\r
174     if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)\r
175     {\r
176       /* Make sure Range 1 Boost is enabled */\r
177       CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);\r
178 \r
179       /* Set Range 1 */\r
180       MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);\r
181 \r
182       /* Wait until VOSF is cleared */\r
183       wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1;\r
184       while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))\r
185       {\r
186         wait_loop_index--;\r
187       }\r
188       if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))\r
189       {\r
190         return HAL_TIMEOUT;\r
191       }\r
192     }\r
193     /* If current range is range 1 normal or boost mode */\r
194     else\r
195     {\r
196       /* Enable Range 1 Boost (no issue if bit already reset) */\r
197       CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);\r
198     }\r
199   }\r
200   else if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1)\r
201   {\r
202     /* If current range is range 2 */\r
203     if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)\r
204     {\r
205       /* Make sure Range 1 Boost is disabled */\r
206       SET_BIT(PWR->CR5, PWR_CR5_R1MODE);\r
207 \r
208       /* Set Range 1 */\r
209       MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);\r
210 \r
211       /* Wait until VOSF is cleared */\r
212       wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1;\r
213       while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))\r
214       {\r
215         wait_loop_index--;\r
216       }\r
217       if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))\r
218       {\r
219         return HAL_TIMEOUT;\r
220       }\r
221     }\r
222      /* If current range is range 1 normal or boost mode */\r
223     else\r
224     {\r
225       /* Disable Range 1 Boost (no issue if bit already set) */\r
226       SET_BIT(PWR->CR5, PWR_CR5_R1MODE);\r
227     }\r
228   }\r
229   else\r
230   {\r
231     /* Set Range 2 */\r
232     MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE2);\r
233     /* No need to wait for VOSF to be cleared for this transition */\r
234     /* PWR_CR5_R1MODE bit setting has no effect in Range 2        */\r
235   }\r
236 \r
237 #else\r
238 \r
239   /* If Set Range 1 */\r
240   if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1)\r
241   {\r
242     if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE1)\r
243     {\r
244       /* Set Range 1 */\r
245       MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);\r
246 \r
247       /* Wait until VOSF is cleared */\r
248       wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U;\r
249       while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))\r
250       {\r
251         wait_loop_index--;\r
252       }\r
253       if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))\r
254       {\r
255         return HAL_TIMEOUT;\r
256       }\r
257     }\r
258   }\r
259   else\r
260   {\r
261     if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE2)\r
262     {\r
263       /* Set Range 2 */\r
264       MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE2);\r
265       /* No need to wait for VOSF to be cleared for this transition */\r
266     }\r
267   }\r
268 #endif\r
269 \r
270   return HAL_OK;\r
271 }\r
272 \r
273 \r
274 /**\r
275   * @brief Enable battery charging.\r
276   *        When VDD is present, charge the external battery on VBAT thru an internal resistor.\r
277   * @param  ResistorSelection: specifies the resistor impedance.\r
278   *          This parameter can be one of the following values:\r
279   *            @arg @ref PWR_BATTERY_CHARGING_RESISTOR_5     5 kOhms resistor\r
280   *            @arg @ref PWR_BATTERY_CHARGING_RESISTOR_1_5 1.5 kOhms resistor\r
281   * @retval None\r
282   */\r
283 void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection)\r
284 {\r
285   assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorSelection));\r
286 \r
287   /* Specify resistor selection */\r
288   MODIFY_REG(PWR->CR4, PWR_CR4_VBRS, ResistorSelection);\r
289 \r
290   /* Enable battery charging */\r
291   SET_BIT(PWR->CR4, PWR_CR4_VBE);\r
292 }\r
293 \r
294 \r
295 /**\r
296   * @brief Disable battery charging.\r
297   * @retval None\r
298   */\r
299 void HAL_PWREx_DisableBatteryCharging(void)\r
300 {\r
301   CLEAR_BIT(PWR->CR4, PWR_CR4_VBE);\r
302 }\r
303 \r
304 \r
305 #if defined(PWR_CR2_USV)\r
306 /**\r
307   * @brief Enable VDDUSB supply.\r
308   * @note  Remove VDDUSB electrical and logical isolation, once VDDUSB supply is present.\r
309   * @retval None\r
310   */\r
311 void HAL_PWREx_EnableVddUSB(void)\r
312 {\r
313   SET_BIT(PWR->CR2, PWR_CR2_USV);\r
314 }\r
315 \r
316 \r
317 /**\r
318   * @brief Disable VDDUSB supply.\r
319   * @retval None\r
320   */\r
321 void HAL_PWREx_DisableVddUSB(void)\r
322 {\r
323   CLEAR_BIT(PWR->CR2, PWR_CR2_USV);\r
324 }\r
325 #endif /* PWR_CR2_USV */\r
326 \r
327 #if defined(PWR_CR2_IOSV)\r
328 /**\r
329   * @brief Enable VDDIO2 supply.\r
330   * @note  Remove VDDIO2 electrical and logical isolation, once VDDIO2 supply is present.\r
331   * @retval None\r
332   */\r
333 void HAL_PWREx_EnableVddIO2(void)\r
334 {\r
335   SET_BIT(PWR->CR2, PWR_CR2_IOSV);\r
336 }\r
337 \r
338 \r
339 /**\r
340   * @brief Disable VDDIO2 supply.\r
341   * @retval None\r
342   */\r
343 void HAL_PWREx_DisableVddIO2(void)\r
344 {\r
345   CLEAR_BIT(PWR->CR2, PWR_CR2_IOSV);\r
346 }\r
347 #endif /* PWR_CR2_IOSV */\r
348 \r
349 \r
350 /**\r
351   * @brief Enable Internal Wake-up Line.\r
352   * @retval None\r
353   */\r
354 void HAL_PWREx_EnableInternalWakeUpLine(void)\r
355 {\r
356   SET_BIT(PWR->CR3, PWR_CR3_EIWF);\r
357 }\r
358 \r
359 \r
360 /**\r
361   * @brief Disable Internal Wake-up Line.\r
362   * @retval None\r
363   */\r
364 void HAL_PWREx_DisableInternalWakeUpLine(void)\r
365 {\r
366   CLEAR_BIT(PWR->CR3, PWR_CR3_EIWF);\r
367 }\r
368 \r
369 \r
370 \r
371 /**\r
372   * @brief Enable GPIO pull-up state in Standby and Shutdown modes.\r
373   * @note  Set the relevant PUy bits of PWR_PUCRx register to configure the I/O in\r
374   *        pull-up state in Standby and Shutdown modes.\r
375   * @note  This state is effective in Standby and Shutdown modes only if APC bit\r
376   *        is set through HAL_PWREx_EnablePullUpPullDownConfig() API.\r
377   * @note  The configuration is lost when exiting the Shutdown mode due to the\r
378   *        power-on reset, maintained when exiting the Standby mode.\r
379   * @note  To avoid any conflict at Standby and Shutdown modes exits, the corresponding\r
380   *        PDy bit of PWR_PDCRx register is cleared unless it is reserved.\r
381   * @note  Even if a PUy bit to set is reserved, the other PUy bits entered as input\r
382   *        parameter at the same time are set.\r
383   * @param  GPIO: Specify the IO port. This parameter can be PWR_GPIO_A, ..., PWR_GPIO_H\r
384   *         (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.\r
385   * @param  GPIONumber: Specify the I/O pins numbers.\r
386   *         This parameter can be one of the following values:\r
387   *         PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less\r
388   *         I/O pins are available) or the logical OR of several of them to set\r
389   *         several bits for a given port in a single API call.\r
390   * @retval HAL Status\r
391   */\r
392 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)\r
393 {\r
394   HAL_StatusTypeDef status = HAL_OK;\r
395 \r
396   assert_param(IS_PWR_GPIO(GPIO));\r
397   assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));\r
398 \r
399   switch (GPIO)\r
400   {\r
401     case PWR_GPIO_A:\r
402        SET_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));\r
403        CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));\r
404        break;\r
405     case PWR_GPIO_B:\r
406        SET_BIT(PWR->PUCRB, GPIONumber);\r
407        CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));\r
408        break;\r
409     case PWR_GPIO_C:\r
410        SET_BIT(PWR->PUCRC, GPIONumber);\r
411        CLEAR_BIT(PWR->PDCRC, GPIONumber);\r
412        break;\r
413 #if defined(GPIOD)\r
414     case PWR_GPIO_D:\r
415        SET_BIT(PWR->PUCRD, GPIONumber);\r
416        CLEAR_BIT(PWR->PDCRD, GPIONumber);\r
417        break;\r
418 #endif\r
419 #if defined(GPIOE)\r
420     case PWR_GPIO_E:\r
421        SET_BIT(PWR->PUCRE, GPIONumber);\r
422        CLEAR_BIT(PWR->PDCRE, GPIONumber);\r
423        break;\r
424 #endif\r
425 #if defined(GPIOF)\r
426     case PWR_GPIO_F:\r
427        SET_BIT(PWR->PUCRF, GPIONumber);\r
428        CLEAR_BIT(PWR->PDCRF, GPIONumber);\r
429        break;\r
430 #endif\r
431 #if defined(GPIOG)\r
432     case PWR_GPIO_G:\r
433        SET_BIT(PWR->PUCRG, GPIONumber);\r
434        CLEAR_BIT(PWR->PDCRG, GPIONumber);\r
435        break;\r
436 #endif\r
437     case PWR_GPIO_H:\r
438        SET_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));\r
439 #if defined (STM32L496xx) || defined (STM32L4A6xx)\r
440        CLEAR_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));\r
441 #else\r
442        CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));\r
443 #endif\r
444        break;\r
445 #if defined(GPIOI)\r
446     case PWR_GPIO_I:\r
447        SET_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));\r
448        CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));\r
449        break;\r
450 #endif\r
451     default:\r
452       status = HAL_ERROR;\r
453       break;\r
454   }\r
455 \r
456   return status;\r
457 }\r
458 \r
459 \r
460 /**\r
461   * @brief Disable GPIO pull-up state in Standby mode and Shutdown modes.\r
462   * @note  Reset the relevant PUy bits of PWR_PUCRx register used to configure the I/O\r
463   *        in pull-up state in Standby and Shutdown modes.\r
464   * @note  Even if a PUy bit to reset is reserved, the other PUy bits entered as input\r
465   *        parameter at the same time are reset.\r
466   * @param  GPIO: Specifies the IO port. This parameter can be PWR_GPIO_A, ..., PWR_GPIO_H\r
467   *          (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.\r
468   * @param  GPIONumber: Specify the I/O pins numbers.\r
469   *         This parameter can be one of the following values:\r
470   *         PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less\r
471   *         I/O pins are available) or the logical OR of several of them to reset\r
472   *         several bits for a given port in a single API call.\r
473   * @retval HAL Status\r
474   */\r
475 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)\r
476 {\r
477   HAL_StatusTypeDef status = HAL_OK;\r
478 \r
479   assert_param(IS_PWR_GPIO(GPIO));\r
480   assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));\r
481 \r
482   switch (GPIO)\r
483   {\r
484     case PWR_GPIO_A:\r
485        CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));\r
486        break;\r
487     case PWR_GPIO_B:\r
488        CLEAR_BIT(PWR->PUCRB, GPIONumber);\r
489        break;\r
490     case PWR_GPIO_C:\r
491        CLEAR_BIT(PWR->PUCRC, GPIONumber);\r
492        break;\r
493 #if defined(GPIOD)\r
494     case PWR_GPIO_D:\r
495        CLEAR_BIT(PWR->PUCRD, GPIONumber);\r
496        break;\r
497 #endif\r
498 #if defined(GPIOE)\r
499     case PWR_GPIO_E:\r
500        CLEAR_BIT(PWR->PUCRE, GPIONumber);\r
501        break;\r
502 #endif\r
503 #if defined(GPIOF)\r
504     case PWR_GPIO_F:\r
505        CLEAR_BIT(PWR->PUCRF, GPIONumber);\r
506        break;\r
507 #endif\r
508 #if defined(GPIOG)\r
509     case PWR_GPIO_G:\r
510        CLEAR_BIT(PWR->PUCRG, GPIONumber);\r
511        break;\r
512 #endif\r
513     case PWR_GPIO_H:\r
514        CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));\r
515        break;\r
516 #if defined(GPIOI)\r
517     case PWR_GPIO_I:\r
518        CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));\r
519        break;\r
520 #endif\r
521     default:\r
522        status = HAL_ERROR;\r
523        break;\r
524   }\r
525 \r
526   return status;\r
527 }\r
528 \r
529 \r
530 \r
531 /**\r
532   * @brief Enable GPIO pull-down state in Standby and Shutdown modes.\r
533   * @note  Set the relevant PDy bits of PWR_PDCRx register to configure the I/O in\r
534   *        pull-down state in Standby and Shutdown modes.\r
535   * @note  This state is effective in Standby and Shutdown modes only if APC bit\r
536   *        is set through HAL_PWREx_EnablePullUpPullDownConfig() API.\r
537   * @note  The configuration is lost when exiting the Shutdown mode due to the\r
538   *        power-on reset, maintained when exiting the Standby mode.\r
539   * @note  To avoid any conflict at Standby and Shutdown modes exits, the corresponding\r
540   *        PUy bit of PWR_PUCRx register is cleared unless it is reserved.\r
541   * @note  Even if a PDy bit to set is reserved, the other PDy bits entered as input\r
542   *        parameter at the same time are set.\r
543   * @param  GPIO: Specify the IO port. This parameter can be PWR_GPIO_A..PWR_GPIO_H\r
544   *         (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.\r
545   * @param  GPIONumber: Specify the I/O pins numbers.\r
546   *         This parameter can be one of the following values:\r
547   *         PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less\r
548   *         I/O pins are available) or the logical OR of several of them to set\r
549   *         several bits for a given port in a single API call.\r
550   * @retval HAL Status\r
551   */\r
552 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)\r
553 {\r
554   HAL_StatusTypeDef status = HAL_OK;\r
555 \r
556   assert_param(IS_PWR_GPIO(GPIO));\r
557   assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));\r
558 \r
559   switch (GPIO)\r
560   {\r
561     case PWR_GPIO_A:\r
562        SET_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));\r
563        CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));\r
564        break;\r
565     case PWR_GPIO_B:\r
566        SET_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));\r
567        CLEAR_BIT(PWR->PUCRB, GPIONumber);\r
568        break;\r
569     case PWR_GPIO_C:\r
570        SET_BIT(PWR->PDCRC, GPIONumber);\r
571        CLEAR_BIT(PWR->PUCRC, GPIONumber);\r
572        break;\r
573 #if defined(GPIOD)\r
574     case PWR_GPIO_D:\r
575        SET_BIT(PWR->PDCRD, GPIONumber);\r
576        CLEAR_BIT(PWR->PUCRD, GPIONumber);\r
577        break;\r
578 #endif\r
579 #if defined(GPIOE)\r
580     case PWR_GPIO_E:\r
581        SET_BIT(PWR->PDCRE, GPIONumber);\r
582        CLEAR_BIT(PWR->PUCRE, GPIONumber);\r
583        break;\r
584 #endif\r
585 #if defined(GPIOF)\r
586     case PWR_GPIO_F:\r
587        SET_BIT(PWR->PDCRF, GPIONumber);\r
588        CLEAR_BIT(PWR->PUCRF, GPIONumber);\r
589        break;\r
590 #endif\r
591 #if defined(GPIOG)\r
592     case PWR_GPIO_G:\r
593        SET_BIT(PWR->PDCRG, GPIONumber);\r
594        CLEAR_BIT(PWR->PUCRG, GPIONumber);\r
595        break;\r
596 #endif\r
597     case PWR_GPIO_H:\r
598 #if defined (STM32L496xx) || defined (STM32L4A6xx)\r
599        SET_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));\r
600 #else\r
601        SET_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));\r
602 #endif\r
603        CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));\r
604        break;\r
605 #if defined(GPIOI)\r
606     case PWR_GPIO_I:\r
607        SET_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));\r
608        CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));\r
609        break;\r
610 #endif\r
611     default:\r
612       status = HAL_ERROR;\r
613       break;\r
614   }\r
615 \r
616   return status;\r
617 }\r
618 \r
619 \r
620 /**\r
621   * @brief Disable GPIO pull-down state in Standby and Shutdown modes.\r
622   * @note  Reset the relevant PDy bits of PWR_PDCRx register used to configure the I/O\r
623   *        in pull-down state in Standby and Shutdown modes.\r
624   * @note  Even if a PDy bit to reset is reserved, the other PDy bits entered as input\r
625   *        parameter at the same time are reset.\r
626   * @param  GPIO: Specifies the IO port. This parameter can be PWR_GPIO_A..PWR_GPIO_H\r
627   *         (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.\r
628   * @param  GPIONumber: Specify the I/O pins numbers.\r
629   *         This parameter can be one of the following values:\r
630   *         PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less\r
631   *         I/O pins are available) or the logical OR of several of them to reset\r
632   *         several bits for a given port in a single API call.\r
633   * @retval HAL Status\r
634   */\r
635 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)\r
636 {\r
637   HAL_StatusTypeDef status = HAL_OK;\r
638 \r
639   assert_param(IS_PWR_GPIO(GPIO));\r
640   assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));\r
641 \r
642   switch (GPIO)\r
643   {\r
644     case PWR_GPIO_A:\r
645        CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));\r
646        break;\r
647     case PWR_GPIO_B:\r
648        CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));\r
649        break;\r
650     case PWR_GPIO_C:\r
651        CLEAR_BIT(PWR->PDCRC, GPIONumber);\r
652        break;\r
653 #if defined(GPIOD)\r
654     case PWR_GPIO_D:\r
655        CLEAR_BIT(PWR->PDCRD, GPIONumber);\r
656        break;\r
657 #endif\r
658 #if defined(GPIOE)\r
659     case PWR_GPIO_E:\r
660        CLEAR_BIT(PWR->PDCRE, GPIONumber);\r
661        break;\r
662 #endif\r
663 #if defined(GPIOF)\r
664     case PWR_GPIO_F:\r
665        CLEAR_BIT(PWR->PDCRF, GPIONumber);\r
666        break;\r
667 #endif\r
668 #if defined(GPIOG)\r
669     case PWR_GPIO_G:\r
670        CLEAR_BIT(PWR->PDCRG, GPIONumber);\r
671        break;\r
672 #endif\r
673     case PWR_GPIO_H:\r
674 #if defined (STM32L496xx) || defined (STM32L4A6xx)\r
675        CLEAR_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));\r
676 #else\r
677        CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));\r
678 #endif\r
679        break;\r
680 #if defined(GPIOI)\r
681     case PWR_GPIO_I:\r
682        CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));\r
683        break;\r
684 #endif\r
685     default:\r
686       status = HAL_ERROR;\r
687       break;\r
688   }\r
689 \r
690   return status;\r
691 }\r
692 \r
693 \r
694 \r
695 /**\r
696   * @brief Enable pull-up and pull-down configuration.\r
697   * @note  When APC bit is set, the I/O pull-up and pull-down configurations defined in\r
698   *        PWR_PUCRx and PWR_PDCRx registers are applied in Standby and Shutdown modes.\r
699   * @note  Pull-up set by PUy bit of PWR_PUCRx register is not activated if the corresponding\r
700   *        PDy bit of PWR_PDCRx register is also set (pull-down configuration priority is higher).\r
701   *        HAL_PWREx_EnableGPIOPullUp() and HAL_PWREx_EnableGPIOPullDown() API's ensure there\r
702   *        is no conflict when setting PUy or PDy bit.\r
703   * @retval None\r
704   */\r
705 void HAL_PWREx_EnablePullUpPullDownConfig(void)\r
706 {\r
707   SET_BIT(PWR->CR3, PWR_CR3_APC);\r
708 }\r
709 \r
710 \r
711 /**\r
712   * @brief Disable pull-up and pull-down configuration.\r
713   * @note  When APC bit is cleared, the I/O pull-up and pull-down configurations defined in\r
714   *        PWR_PUCRx and PWR_PDCRx registers are not applied in Standby and Shutdown modes.\r
715   * @retval None\r
716   */\r
717 void HAL_PWREx_DisablePullUpPullDownConfig(void)\r
718 {\r
719   CLEAR_BIT(PWR->CR3, PWR_CR3_APC);\r
720 }\r
721 \r
722 \r
723 \r
724 /**\r
725   * @brief Enable SRAM2 content retention in Standby mode.\r
726   * @note  When RRS bit is set, SRAM2 is powered by the low-power regulator in\r
727   *         Standby mode and its content is kept.\r
728   * @retval None\r
729   */\r
730 void HAL_PWREx_EnableSRAM2ContentRetention(void)\r
731 {\r
732   SET_BIT(PWR->CR3, PWR_CR3_RRS);\r
733 }\r
734 \r
735 \r
736 /**\r
737   * @brief Disable SRAM2 content retention in Standby mode.\r
738   * @note  When RRS bit is reset, SRAM2 is powered off in Standby mode\r
739   *        and its content is lost.\r
740   * @retval None\r
741   */\r
742 void HAL_PWREx_DisableSRAM2ContentRetention(void)\r
743 {\r
744   CLEAR_BIT(PWR->CR3, PWR_CR3_RRS);\r
745 }\r
746 \r
747 \r
748 #if defined(PWR_CR3_ENULP)\r
749 /**\r
750   * @brief Enable Ultra Low Power BORL, BORH and PVD for STOP2 and Standby modes.\r
751   * @note  All the other modes are not affected by this bit.\r
752   * @retval None\r
753   */\r
754 void HAL_PWREx_EnableBORPVD_ULP(void)\r
755 {\r
756   SET_BIT(PWR->CR3, PWR_CR3_ENULP);\r
757 }\r
758 \r
759 \r
760 /**\r
761   * @brief Disable Ultra Low Power BORL, BORH and PVD for STOP2 and Standby modes.\r
762   * @note  All the other modes are not affected by this bit\r
763   * @retval None\r
764   */\r
765 void HAL_PWREx_DisableBORPVD_ULP(void)\r
766 {\r
767   CLEAR_BIT(PWR->CR3, PWR_CR3_ENULP);\r
768 }\r
769 #endif /* PWR_CR3_ENULP */\r
770 \r
771 \r
772 #if defined(PWR_CR4_EXT_SMPS_ON)\r
773 /**\r
774   * @brief Enable the CFLDO working @ 0.95V.\r
775   * @note  When external SMPS is used & CFLDO operating in Range 2, the regulated voltage of the\r
776   *        internal CFLDO can be reduced to 0.95V.\r
777   * @retval None\r
778   */\r
779 void HAL_PWREx_EnableExtSMPS_0V95(void)\r
780 {\r
781   SET_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON);\r
782 }\r
783 \r
784 /**\r
785   * @brief Disable the CFLDO working @ 0.95V\r
786   * @note  Before SMPS is switched off, the regulated voltage of the\r
787   *        internal CFLDO shall be set to 1.00V.\r
788   *        1.00V. is also default operating Range 2 voltage.\r
789   * @retval None\r
790   */\r
791 void HAL_PWREx_DisableExtSMPS_0V95(void)\r
792 {\r
793   CLEAR_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON);\r
794 }\r
795 #endif /* PWR_CR4_EXT_SMPS_ON */\r
796 \r
797 \r
798 #if defined(PWR_CR1_RRSTP)\r
799 /**\r
800   * @brief Enable SRAM3 content retention in Stop 2 mode.\r
801   * @note  When RRSTP bit is set, SRAM3 is powered by the low-power regulator in\r
802   *        Stop 2 mode and its content is kept.\r
803   * @retval None\r
804   */\r
805 void HAL_PWREx_EnableSRAM3ContentRetention(void)\r
806 {\r
807   SET_BIT(PWR->CR1, PWR_CR1_RRSTP);\r
808 }\r
809 \r
810 \r
811 /**\r
812   * @brief Disable SRAM3 content retention in Stop 2 mode.\r
813   * @note  When RRSTP bit is reset, SRAM3 is powered off in Stop 2 mode\r
814   *        and its content is lost.\r
815   * @retval None\r
816   */\r
817 void HAL_PWREx_DisableSRAM3ContentRetention(void)\r
818 {\r
819   CLEAR_BIT(PWR->CR1, PWR_CR1_RRSTP);\r
820 }\r
821 #endif /* PWR_CR1_RRSTP */\r
822 \r
823 #if defined(PWR_CR3_DSIPDEN)\r
824 /**\r
825   * @brief Enable pull-down activation on DSI pins.\r
826   * @retval None\r
827   */\r
828 void HAL_PWREx_EnableDSIPinsPDActivation(void)\r
829 {\r
830   SET_BIT(PWR->CR3, PWR_CR3_DSIPDEN);\r
831 }\r
832 \r
833 \r
834 /**\r
835   * @brief Disable pull-down activation on DSI pins.\r
836   * @retval None\r
837   */\r
838 void HAL_PWREx_DisableDSIPinsPDActivation(void)\r
839 {\r
840   CLEAR_BIT(PWR->CR3, PWR_CR3_DSIPDEN);\r
841 }\r
842 #endif /* PWR_CR3_DSIPDEN */\r
843 \r
844 #if defined(PWR_CR2_PVME1)\r
845 /**\r
846   * @brief Enable the Power Voltage Monitoring 1: VDDUSB versus 1.2V.\r
847   * @retval None\r
848   */\r
849 void HAL_PWREx_EnablePVM1(void)\r
850 {\r
851   SET_BIT(PWR->CR2, PWR_PVM_1);\r
852 }\r
853 \r
854 /**\r
855   * @brief Disable the Power Voltage Monitoring 1: VDDUSB versus 1.2V.\r
856   * @retval None\r
857   */\r
858 void HAL_PWREx_DisablePVM1(void)\r
859 {\r
860   CLEAR_BIT(PWR->CR2, PWR_PVM_1);\r
861 }\r
862 #endif /* PWR_CR2_PVME1 */\r
863 \r
864 \r
865 #if defined(PWR_CR2_PVME2)\r
866 /**\r
867   * @brief Enable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V.\r
868   * @retval None\r
869   */\r
870 void HAL_PWREx_EnablePVM2(void)\r
871 {\r
872   SET_BIT(PWR->CR2, PWR_PVM_2);\r
873 }\r
874 \r
875 /**\r
876   * @brief Disable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V.\r
877   * @retval None\r
878   */\r
879 void HAL_PWREx_DisablePVM2(void)\r
880 {\r
881   CLEAR_BIT(PWR->CR2, PWR_PVM_2);\r
882 }\r
883 #endif /* PWR_CR2_PVME2 */\r
884 \r
885 \r
886 /**\r
887   * @brief Enable the Power Voltage Monitoring 3: VDDA versus 1.62V.\r
888   * @retval None\r
889   */\r
890 void HAL_PWREx_EnablePVM3(void)\r
891 {\r
892   SET_BIT(PWR->CR2, PWR_PVM_3);\r
893 }\r
894 \r
895 /**\r
896   * @brief Disable the Power Voltage Monitoring 3: VDDA versus 1.62V.\r
897   * @retval None\r
898   */\r
899 void HAL_PWREx_DisablePVM3(void)\r
900 {\r
901   CLEAR_BIT(PWR->CR2, PWR_PVM_3);\r
902 }\r
903 \r
904 \r
905 /**\r
906   * @brief Enable the Power Voltage Monitoring 4:  VDDA versus 2.2V.\r
907   * @retval None\r
908   */\r
909 void HAL_PWREx_EnablePVM4(void)\r
910 {\r
911   SET_BIT(PWR->CR2, PWR_PVM_4);\r
912 }\r
913 \r
914 /**\r
915   * @brief Disable the Power Voltage Monitoring 4:  VDDA versus 2.2V.\r
916   * @retval None\r
917   */\r
918 void HAL_PWREx_DisablePVM4(void)\r
919 {\r
920   CLEAR_BIT(PWR->CR2, PWR_PVM_4);\r
921 }\r
922 \r
923 \r
924 \r
925 \r
926 /**\r
927   * @brief Configure the Peripheral Voltage Monitoring (PVM).\r
928   * @param sConfigPVM: pointer to a PWR_PVMTypeDef structure that contains the\r
929   *        PVM configuration information.\r
930   * @note The API configures a single PVM according to the information contained\r
931   *       in the input structure. To configure several PVMs, the API must be singly\r
932   *       called for each PVM used.\r
933   * @note Refer to the electrical characteristics of your device datasheet for\r
934   *         more details about the voltage thresholds corresponding to each\r
935   *         detection level and to each monitored supply.\r
936   * @retval HAL status\r
937   */\r
938 HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM)\r
939 {\r
940   HAL_StatusTypeDef status = HAL_OK;\r
941 \r
942   /* Check the parameters */\r
943   assert_param(IS_PWR_PVM_TYPE(sConfigPVM->PVMType));\r
944   assert_param(IS_PWR_PVM_MODE(sConfigPVM->Mode));\r
945 \r
946 \r
947   /* Configure EXTI 35 to 38 interrupts if so required:\r
948      scan thru PVMType to detect which PVMx is set and\r
949      configure the corresponding EXTI line accordingly. */\r
950   switch (sConfigPVM->PVMType)\r
951   {\r
952 #if defined(PWR_CR2_PVME1)\r
953     case PWR_PVM_1:\r
954       /* Clear any previous config. Keep it clear if no event or IT mode is selected */\r
955       __HAL_PWR_PVM1_EXTI_DISABLE_EVENT();\r
956       __HAL_PWR_PVM1_EXTI_DISABLE_IT();\r
957       __HAL_PWR_PVM1_EXTI_DISABLE_FALLING_EDGE();\r
958       __HAL_PWR_PVM1_EXTI_DISABLE_RISING_EDGE();\r
959 \r
960       /* Configure interrupt mode */\r
961       if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)\r
962       {\r
963         __HAL_PWR_PVM1_EXTI_ENABLE_IT();\r
964       }\r
965 \r
966       /* Configure event mode */\r
967       if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)\r
968       {\r
969         __HAL_PWR_PVM1_EXTI_ENABLE_EVENT();\r
970       }\r
971 \r
972       /* Configure the edge */\r
973       if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)\r
974       {\r
975         __HAL_PWR_PVM1_EXTI_ENABLE_RISING_EDGE();\r
976       }\r
977 \r
978       if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)\r
979       {\r
980         __HAL_PWR_PVM1_EXTI_ENABLE_FALLING_EDGE();\r
981       }\r
982       break;\r
983 #endif /* PWR_CR2_PVME1 */\r
984 \r
985 #if defined(PWR_CR2_PVME2)\r
986     case PWR_PVM_2:\r
987       /* Clear any previous config. Keep it clear if no event or IT mode is selected */\r
988       __HAL_PWR_PVM2_EXTI_DISABLE_EVENT();\r
989       __HAL_PWR_PVM2_EXTI_DISABLE_IT();\r
990       __HAL_PWR_PVM2_EXTI_DISABLE_FALLING_EDGE();\r
991       __HAL_PWR_PVM2_EXTI_DISABLE_RISING_EDGE();\r
992 \r
993       /* Configure interrupt mode */\r
994       if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)\r
995       {\r
996         __HAL_PWR_PVM2_EXTI_ENABLE_IT();\r
997       }\r
998 \r
999       /* Configure event mode */\r
1000       if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)\r
1001       {\r
1002         __HAL_PWR_PVM2_EXTI_ENABLE_EVENT();\r
1003       }\r
1004 \r
1005       /* Configure the edge */\r
1006       if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)\r
1007       {\r
1008         __HAL_PWR_PVM2_EXTI_ENABLE_RISING_EDGE();\r
1009       }\r
1010 \r
1011       if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)\r
1012       {\r
1013         __HAL_PWR_PVM2_EXTI_ENABLE_FALLING_EDGE();\r
1014       }\r
1015       break;\r
1016 #endif /* PWR_CR2_PVME2 */\r
1017 \r
1018     case PWR_PVM_3:\r
1019       /* Clear any previous config. Keep it clear if no event or IT mode is selected */\r
1020       __HAL_PWR_PVM3_EXTI_DISABLE_EVENT();\r
1021       __HAL_PWR_PVM3_EXTI_DISABLE_IT();\r
1022       __HAL_PWR_PVM3_EXTI_DISABLE_FALLING_EDGE();\r
1023       __HAL_PWR_PVM3_EXTI_DISABLE_RISING_EDGE();\r
1024 \r
1025       /* Configure interrupt mode */\r
1026       if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)\r
1027       {\r
1028         __HAL_PWR_PVM3_EXTI_ENABLE_IT();\r
1029       }\r
1030 \r
1031       /* Configure event mode */\r
1032       if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)\r
1033       {\r
1034         __HAL_PWR_PVM3_EXTI_ENABLE_EVENT();\r
1035       }\r
1036 \r
1037       /* Configure the edge */\r
1038       if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)\r
1039       {\r
1040         __HAL_PWR_PVM3_EXTI_ENABLE_RISING_EDGE();\r
1041       }\r
1042 \r
1043       if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)\r
1044       {\r
1045         __HAL_PWR_PVM3_EXTI_ENABLE_FALLING_EDGE();\r
1046       }\r
1047       break;\r
1048 \r
1049     case PWR_PVM_4:\r
1050       /* Clear any previous config. Keep it clear if no event or IT mode is selected */\r
1051       __HAL_PWR_PVM4_EXTI_DISABLE_EVENT();\r
1052       __HAL_PWR_PVM4_EXTI_DISABLE_IT();\r
1053       __HAL_PWR_PVM4_EXTI_DISABLE_FALLING_EDGE();\r
1054       __HAL_PWR_PVM4_EXTI_DISABLE_RISING_EDGE();\r
1055 \r
1056       /* Configure interrupt mode */\r
1057       if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)\r
1058       {\r
1059         __HAL_PWR_PVM4_EXTI_ENABLE_IT();\r
1060       }\r
1061 \r
1062       /* Configure event mode */\r
1063       if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)\r
1064       {\r
1065         __HAL_PWR_PVM4_EXTI_ENABLE_EVENT();\r
1066       }\r
1067 \r
1068       /* Configure the edge */\r
1069       if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)\r
1070       {\r
1071         __HAL_PWR_PVM4_EXTI_ENABLE_RISING_EDGE();\r
1072       }\r
1073 \r
1074       if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)\r
1075       {\r
1076         __HAL_PWR_PVM4_EXTI_ENABLE_FALLING_EDGE();\r
1077       }\r
1078       break;\r
1079 \r
1080     default:\r
1081       status = HAL_ERROR;\r
1082       break;\r
1083   }\r
1084 \r
1085   return status;\r
1086 }\r
1087 \r
1088 \r
1089 \r
1090 /**\r
1091   * @brief Enter Low-power Run mode\r
1092   * @note  In Low-power Run mode, all I/O pins keep the same state as in Run mode.\r
1093   * @note  When Regulator is set to PWR_LOWPOWERREGULATOR_ON, the user can optionally configure the\r
1094   *        Flash in power-down monde in setting the RUN_PD bit in FLASH_ACR register.\r
1095   *        Additionally, the clock frequency must be reduced below 2 MHz.\r
1096   *        Setting RUN_PD in FLASH_ACR then appropriately reducing the clock frequency must\r
1097   *        be done before calling HAL_PWREx_EnableLowPowerRunMode() API.\r
1098   * @retval None\r
1099   */\r
1100 void HAL_PWREx_EnableLowPowerRunMode(void)\r
1101 {\r
1102   /* Set Regulator parameter */\r
1103   SET_BIT(PWR->CR1, PWR_CR1_LPR);\r
1104 }\r
1105 \r
1106 \r
1107 /**\r
1108   * @brief Exit Low-power Run mode.\r
1109   * @note  Before HAL_PWREx_DisableLowPowerRunMode() completion, the function checks that\r
1110   *        REGLPF has been properly reset (otherwise, HAL_PWREx_DisableLowPowerRunMode\r
1111   *        returns HAL_TIMEOUT status). The system clock frequency can then be\r
1112   *        increased above 2 MHz.\r
1113   * @retval HAL Status\r
1114   */\r
1115 HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)\r
1116 {\r
1117   uint32_t wait_loop_index;\r
1118 \r
1119   /* Clear LPR bit */\r
1120   CLEAR_BIT(PWR->CR1, PWR_CR1_LPR);\r
1121 \r
1122   /* Wait until REGLPF is reset */\r
1123   wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U;\r
1124   while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF)) && (wait_loop_index != 0U))\r
1125   {\r
1126     wait_loop_index--;\r
1127   }\r
1128   if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))\r
1129   {\r
1130     return HAL_TIMEOUT;\r
1131   }\r
1132 \r
1133   return HAL_OK;\r
1134 }\r
1135 \r
1136 \r
1137 /**\r
1138   * @brief Enter Stop 0 mode.\r
1139   * @note  In Stop 0 mode, main and low voltage regulators are ON.\r
1140   * @note  In Stop 0 mode, all I/O pins keep the same state as in Run mode.\r
1141   * @note  All clocks in the VCORE domain are stopped; the PLL, the MSI,\r
1142   *        the HSI and the HSE oscillators are disabled. Some peripherals with the wakeup capability\r
1143   *        (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI\r
1144   *        after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated\r
1145   *        only to the peripheral requesting it.\r
1146   *        SRAM1, SRAM2 and register contents are preserved.\r
1147   *        The BOR is available.\r
1148   * @note  When exiting Stop 0 mode by issuing an interrupt or a wakeup event,\r
1149   *         the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register\r
1150   *         is set; the MSI oscillator is selected if STOPWUCK is cleared.\r
1151   * @note  By keeping the internal regulator ON during Stop 0 mode, the consumption\r
1152   *         is higher although the startup time is reduced.\r
1153   * @param STOPEntry  specifies if Stop mode in entered with WFI or WFE instruction.\r
1154   *          This parameter can be one of the following values:\r
1155   *            @arg @ref PWR_STOPENTRY_WFI  Enter Stop mode with WFI instruction\r
1156   *            @arg @ref PWR_STOPENTRY_WFE  Enter Stop mode with WFE instruction\r
1157   * @retval None\r
1158   */\r
1159 void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry)\r
1160 {\r
1161   /* Check the parameters */\r
1162   assert_param(IS_PWR_STOP_ENTRY(STOPEntry));\r
1163 \r
1164   /* Stop 0 mode with Main Regulator */\r
1165   MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP0);\r
1166 \r
1167   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
1168   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
1169 \r
1170   /* Select Stop mode entry --------------------------------------------------*/\r
1171   if(STOPEntry == PWR_STOPENTRY_WFI)\r
1172   {\r
1173     /* Request Wait For Interrupt */\r
1174     __WFI();\r
1175   }\r
1176   else\r
1177   {\r
1178     /* Request Wait For Event */\r
1179     __SEV();\r
1180     __WFE();\r
1181     __WFE();\r
1182   }\r
1183 \r
1184   /* Reset SLEEPDEEP bit of Cortex System Control Register */\r
1185   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
1186 }\r
1187 \r
1188 \r
1189 /**\r
1190   * @brief Enter Stop 1 mode.\r
1191   * @note  In Stop 1 mode, only low power voltage regulator is ON.\r
1192   * @note  In Stop 1 mode, all I/O pins keep the same state as in Run mode.\r
1193   * @note  All clocks in the VCORE domain are stopped; the PLL, the MSI,\r
1194   *        the HSI and the HSE oscillators are disabled. Some peripherals with the wakeup capability\r
1195   *        (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI\r
1196   *        after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated\r
1197   *        only to the peripheral requesting it.\r
1198   *        SRAM1, SRAM2 and register contents are preserved.\r
1199   *        The BOR is available.\r
1200   * @note  When exiting Stop 1 mode by issuing an interrupt or a wakeup event,\r
1201   *         the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register\r
1202   *         is set; the MSI oscillator is selected if STOPWUCK is cleared.\r
1203   * @note  Due to low power mode, an additional startup delay is incurred when waking up from Stop 1 mode.\r
1204   * @param STOPEntry  specifies if Stop mode in entered with WFI or WFE instruction.\r
1205   *          This parameter can be one of the following values:\r
1206   *            @arg @ref PWR_STOPENTRY_WFI  Enter Stop mode with WFI instruction\r
1207   *            @arg @ref PWR_STOPENTRY_WFE  Enter Stop mode with WFE instruction\r
1208   * @retval None\r
1209   */\r
1210 void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)\r
1211 {\r
1212   /* Check the parameters */\r
1213   assert_param(IS_PWR_STOP_ENTRY(STOPEntry));\r
1214 \r
1215   /* Stop 1 mode with Low-Power Regulator */\r
1216   MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP1);\r
1217 \r
1218   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
1219   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
1220 \r
1221   /* Select Stop mode entry --------------------------------------------------*/\r
1222   if(STOPEntry == PWR_STOPENTRY_WFI)\r
1223   {\r
1224     /* Request Wait For Interrupt */\r
1225     __WFI();\r
1226   }\r
1227   else\r
1228   {\r
1229     /* Request Wait For Event */\r
1230     __SEV();\r
1231     __WFE();\r
1232     __WFE();\r
1233   }\r
1234 \r
1235   /* Reset SLEEPDEEP bit of Cortex System Control Register */\r
1236   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
1237 }\r
1238 \r
1239 \r
1240 /**\r
1241   * @brief Enter Stop 2 mode.\r
1242   * @note  In Stop 2 mode, only low power voltage regulator is ON.\r
1243   * @note  In Stop 2 mode, all I/O pins keep the same state as in Run mode.\r
1244   * @note  All clocks in the VCORE domain are stopped, the PLL, the MSI,\r
1245   *        the HSI and the HSE oscillators are disabled. Some peripherals with wakeup capability\r
1246   *        (LCD, LPTIM1, I2C3 and LPUART) can switch on the HSI to receive a frame, and switch off the HSI after\r
1247   *        receiving the frame if it is not a wakeup frame. In this case the HSI clock is propagated only\r
1248   *        to the peripheral requesting it.\r
1249   *        SRAM1, SRAM2 and register contents are preserved.\r
1250   *        The BOR is available.\r
1251   *        The voltage regulator is set in low-power mode but LPR bit must be cleared to enter stop 2 mode.\r
1252   *        Otherwise, Stop 1 mode is entered.\r
1253   * @note  When exiting Stop 2 mode by issuing an interrupt or a wakeup event,\r
1254   *         the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register\r
1255   *         is set; the MSI oscillator is selected if STOPWUCK is cleared.\r
1256   * @param STOPEntry  specifies if Stop mode in entered with WFI or WFE instruction.\r
1257   *          This parameter can be one of the following values:\r
1258   *            @arg @ref PWR_STOPENTRY_WFI  Enter Stop mode with WFI instruction\r
1259   *            @arg @ref PWR_STOPENTRY_WFE  Enter Stop mode with WFE instruction\r
1260   * @retval None\r
1261   */\r
1262 void HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry)\r
1263 {\r
1264   /* Check the parameter */\r
1265   assert_param(IS_PWR_STOP_ENTRY(STOPEntry));\r
1266 \r
1267   /* Set Stop mode 2 */\r
1268   MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP2);\r
1269 \r
1270   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
1271   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
1272 \r
1273   /* Select Stop mode entry --------------------------------------------------*/\r
1274   if(STOPEntry == PWR_STOPENTRY_WFI)\r
1275   {\r
1276     /* Request Wait For Interrupt */\r
1277     __WFI();\r
1278   }\r
1279   else\r
1280   {\r
1281     /* Request Wait For Event */\r
1282     __SEV();\r
1283     __WFE();\r
1284     __WFE();\r
1285   }\r
1286 \r
1287   /* Reset SLEEPDEEP bit of Cortex System Control Register */\r
1288   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
1289 }\r
1290 \r
1291 \r
1292 \r
1293 \r
1294 \r
1295 /**\r
1296   * @brief Enter Shutdown mode.\r
1297   * @note  In Shutdown mode, the PLL, the HSI, the MSI, the LSI and the HSE oscillators are switched\r
1298   *        off. The voltage regulator is disabled and Vcore domain is powered off.\r
1299   *        SRAM1, SRAM2 and registers contents are lost except for registers in the Backup domain.\r
1300   *        The BOR is not available.\r
1301   * @note  The I/Os can be configured either with a pull-up or pull-down or can be kept in analog state.\r
1302   * @retval None\r
1303   */\r
1304 void HAL_PWREx_EnterSHUTDOWNMode(void)\r
1305 {\r
1306 \r
1307   /* Set Shutdown mode */\r
1308   MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_SHUTDOWN);\r
1309 \r
1310   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
1311   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
1312 \r
1313 /* This option is used to ensure that store operations are completed */\r
1314 #if defined ( __CC_ARM)\r
1315   __force_stores();\r
1316 #endif\r
1317   /* Request Wait For Interrupt */\r
1318   __WFI();\r
1319 }\r
1320 \r
1321 \r
1322 \r
1323 \r
1324 /**\r
1325   * @brief This function handles the PWR PVD/PVMx interrupt request.\r
1326   * @note This API should be called under the PVD_PVM_IRQHandler().\r
1327   * @retval None\r
1328   */\r
1329 void HAL_PWREx_PVD_PVM_IRQHandler(void)\r
1330 {\r
1331   /* Check PWR exti flag */\r
1332   if(__HAL_PWR_PVD_EXTI_GET_FLAG() != 0x0U)\r
1333   {\r
1334     /* PWR PVD interrupt user callback */\r
1335     HAL_PWR_PVDCallback();\r
1336 \r
1337     /* Clear PVD exti pending bit */\r
1338     __HAL_PWR_PVD_EXTI_CLEAR_FLAG();\r
1339   }\r
1340   /* Next, successively check PVMx exti flags */\r
1341 #if defined(PWR_CR2_PVME1)\r
1342   if(__HAL_PWR_PVM1_EXTI_GET_FLAG() != 0x0U)\r
1343   {\r
1344     /* PWR PVM1 interrupt user callback */\r
1345     HAL_PWREx_PVM1Callback();\r
1346 \r
1347     /* Clear PVM1 exti pending bit */\r
1348     __HAL_PWR_PVM1_EXTI_CLEAR_FLAG();\r
1349   }\r
1350 #endif /* PWR_CR2_PVME1 */\r
1351 #if defined(PWR_CR2_PVME2)\r
1352   if(__HAL_PWR_PVM2_EXTI_GET_FLAG() != 0x0U)\r
1353   {\r
1354     /* PWR PVM2 interrupt user callback */\r
1355     HAL_PWREx_PVM2Callback();\r
1356 \r
1357     /* Clear PVM2 exti pending bit */\r
1358     __HAL_PWR_PVM2_EXTI_CLEAR_FLAG();\r
1359   }\r
1360 #endif /* PWR_CR2_PVME2 */\r
1361   if(__HAL_PWR_PVM3_EXTI_GET_FLAG() != 0x0U)\r
1362   {\r
1363     /* PWR PVM3 interrupt user callback */\r
1364     HAL_PWREx_PVM3Callback();\r
1365 \r
1366     /* Clear PVM3 exti pending bit */\r
1367     __HAL_PWR_PVM3_EXTI_CLEAR_FLAG();\r
1368   }\r
1369   if(__HAL_PWR_PVM4_EXTI_GET_FLAG() != 0x0U)\r
1370   {\r
1371     /* PWR PVM4 interrupt user callback */\r
1372     HAL_PWREx_PVM4Callback();\r
1373 \r
1374     /* Clear PVM4 exti pending bit */\r
1375     __HAL_PWR_PVM4_EXTI_CLEAR_FLAG();\r
1376   }\r
1377 }\r
1378 \r
1379 \r
1380 #if defined(PWR_CR2_PVME1)\r
1381 /**\r
1382   * @brief PWR PVM1 interrupt callback\r
1383   * @retval None\r
1384   */\r
1385 __weak void HAL_PWREx_PVM1Callback(void)\r
1386 {\r
1387   /* NOTE : This function should not be modified; when the callback is needed,\r
1388             HAL_PWREx_PVM1Callback() API can be implemented in the user file\r
1389    */\r
1390 }\r
1391 #endif /* PWR_CR2_PVME1 */\r
1392 \r
1393 #if defined(PWR_CR2_PVME2)\r
1394 /**\r
1395   * @brief PWR PVM2 interrupt callback\r
1396   * @retval None\r
1397   */\r
1398 __weak void HAL_PWREx_PVM2Callback(void)\r
1399 {\r
1400   /* NOTE : This function should not be modified; when the callback is needed,\r
1401             HAL_PWREx_PVM2Callback() API can be implemented in the user file\r
1402    */\r
1403 }\r
1404 #endif /* PWR_CR2_PVME2 */\r
1405 \r
1406 /**\r
1407   * @brief PWR PVM3 interrupt callback\r
1408   * @retval None\r
1409   */\r
1410 __weak void HAL_PWREx_PVM3Callback(void)\r
1411 {\r
1412   /* NOTE : This function should not be modified; when the callback is needed,\r
1413             HAL_PWREx_PVM3Callback() API can be implemented in the user file\r
1414    */\r
1415 }\r
1416 \r
1417 /**\r
1418   * @brief PWR PVM4 interrupt callback\r
1419   * @retval None\r
1420   */\r
1421 __weak void HAL_PWREx_PVM4Callback(void)\r
1422 {\r
1423   /* NOTE : This function should not be modified; when the callback is needed,\r
1424             HAL_PWREx_PVM4Callback() API can be implemented in the user file\r
1425    */\r
1426 }\r
1427 \r
1428 \r
1429 /**\r
1430   * @}\r
1431   */\r
1432 \r
1433 /**\r
1434   * @}\r
1435   */\r
1436 \r
1437 #endif /* HAL_PWR_MODULE_ENABLED */\r
1438 /**\r
1439   * @}\r
1440   */\r
1441 \r
1442 /**\r
1443   * @}\r
1444   */\r
1445 \r
1446 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r