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
11 ******************************************************************************
\r
14 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
15 * All rights reserved.</center></h2>
\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
22 ******************************************************************************
\r
25 /* Includes ------------------------------------------------------------------*/
\r
26 #include "stm32l4xx_hal.h"
\r
28 /** @addtogroup STM32L4xx_HAL_Driver
\r
32 /** @defgroup PWREx PWREx
\r
33 * @brief PWR Extended HAL module driver
\r
37 #ifdef HAL_PWR_MODULE_ENABLED
\r
39 /* Private typedef -----------------------------------------------------------*/
\r
40 /* Private define ------------------------------------------------------------*/
\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
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
56 /** @defgroup PWR_Extended_Private_Defines PWR Extended Private Defines
\r
60 /** @defgroup PWREx_PVM_Mode_Mask PWR PVM Mode Mask
\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
71 /** @defgroup PWREx_TimeOut_Value PWR Extended Flag Setting Time Out Value
\r
74 #define PWR_FLAG_SETTING_DELAY_US 50UL /*!< Time out value for REGLPF and VOSF flags setting */
\r
87 /* Private macro -------------------------------------------------------------*/
\r
88 /* Private variables ---------------------------------------------------------*/
\r
89 /* Private function prototypes -----------------------------------------------*/
\r
90 /* Exported functions --------------------------------------------------------*/
\r
92 /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
\r
96 /** @defgroup PWREx_Exported_Functions_Group1 Extended Peripheral Control functions
\r
97 * @brief Extended Peripheral Control functions
\r
100 ===============================================================================
\r
101 ##### Extended Peripheral Initialization and de-initialization functions #####
\r
102 ===============================================================================
\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
115 uint32_t HAL_PWREx_GetVoltageRange(void)
\r
117 #if defined(PWR_CR5_R1MODE)
\r
118 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
\r
120 return PWR_REGULATOR_VOLTAGE_SCALE2;
\r
122 else if (READ_BIT(PWR->CR5, PWR_CR5_R1MODE) == PWR_CR5_R1MODE)
\r
124 /* PWR_CR5_R1MODE bit set means that Range 1 Boost is disabled */
\r
125 return PWR_REGULATOR_VOLTAGE_SCALE1;
\r
129 return PWR_REGULATOR_VOLTAGE_SCALE1_BOOST;
\r
132 return (PWR->CR1 & PWR_CR1_VOS);
\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
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
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
164 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
\r
166 uint32_t wait_loop_index;
\r
168 assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
\r
170 #if defined(PWR_CR5_R1MODE)
\r
171 if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1_BOOST)
\r
173 /* If current range is range 2 */
\r
174 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
\r
176 /* Make sure Range 1 Boost is enabled */
\r
177 CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);
\r
180 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
\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
188 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
\r
190 return HAL_TIMEOUT;
\r
193 /* If current range is range 1 normal or boost mode */
\r
196 /* Enable Range 1 Boost (no issue if bit already reset) */
\r
197 CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);
\r
200 else if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1)
\r
202 /* If current range is range 2 */
\r
203 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
\r
205 /* Make sure Range 1 Boost is disabled */
\r
206 SET_BIT(PWR->CR5, PWR_CR5_R1MODE);
\r
209 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
\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
217 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
\r
219 return HAL_TIMEOUT;
\r
222 /* If current range is range 1 normal or boost mode */
\r
225 /* Disable Range 1 Boost (no issue if bit already set) */
\r
226 SET_BIT(PWR->CR5, PWR_CR5_R1MODE);
\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
239 /* If Set Range 1 */
\r
240 if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1)
\r
242 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE1)
\r
245 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
\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
253 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
\r
255 return HAL_TIMEOUT;
\r
261 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE2)
\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
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
283 void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection)
\r
285 assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorSelection));
\r
287 /* Specify resistor selection */
\r
288 MODIFY_REG(PWR->CR4, PWR_CR4_VBRS, ResistorSelection);
\r
290 /* Enable battery charging */
\r
291 SET_BIT(PWR->CR4, PWR_CR4_VBE);
\r
296 * @brief Disable battery charging.
\r
299 void HAL_PWREx_DisableBatteryCharging(void)
\r
301 CLEAR_BIT(PWR->CR4, PWR_CR4_VBE);
\r
305 #if defined(PWR_CR2_USV)
\r
307 * @brief Enable VDDUSB supply.
\r
308 * @note Remove VDDUSB electrical and logical isolation, once VDDUSB supply is present.
\r
311 void HAL_PWREx_EnableVddUSB(void)
\r
313 SET_BIT(PWR->CR2, PWR_CR2_USV);
\r
318 * @brief Disable VDDUSB supply.
\r
321 void HAL_PWREx_DisableVddUSB(void)
\r
323 CLEAR_BIT(PWR->CR2, PWR_CR2_USV);
\r
325 #endif /* PWR_CR2_USV */
\r
327 #if defined(PWR_CR2_IOSV)
\r
329 * @brief Enable VDDIO2 supply.
\r
330 * @note Remove VDDIO2 electrical and logical isolation, once VDDIO2 supply is present.
\r
333 void HAL_PWREx_EnableVddIO2(void)
\r
335 SET_BIT(PWR->CR2, PWR_CR2_IOSV);
\r
340 * @brief Disable VDDIO2 supply.
\r
343 void HAL_PWREx_DisableVddIO2(void)
\r
345 CLEAR_BIT(PWR->CR2, PWR_CR2_IOSV);
\r
347 #endif /* PWR_CR2_IOSV */
\r
351 * @brief Enable Internal Wake-up Line.
\r
354 void HAL_PWREx_EnableInternalWakeUpLine(void)
\r
356 SET_BIT(PWR->CR3, PWR_CR3_EIWF);
\r
361 * @brief Disable Internal Wake-up Line.
\r
364 void HAL_PWREx_DisableInternalWakeUpLine(void)
\r
366 CLEAR_BIT(PWR->CR3, PWR_CR3_EIWF);
\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
392 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
\r
394 HAL_StatusTypeDef status = HAL_OK;
\r
396 assert_param(IS_PWR_GPIO(GPIO));
\r
397 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
\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
406 SET_BIT(PWR->PUCRB, GPIONumber);
\r
407 CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
\r
410 SET_BIT(PWR->PUCRC, GPIONumber);
\r
411 CLEAR_BIT(PWR->PDCRC, GPIONumber);
\r
415 SET_BIT(PWR->PUCRD, GPIONumber);
\r
416 CLEAR_BIT(PWR->PDCRD, GPIONumber);
\r
421 SET_BIT(PWR->PUCRE, GPIONumber);
\r
422 CLEAR_BIT(PWR->PDCRE, GPIONumber);
\r
427 SET_BIT(PWR->PUCRF, GPIONumber);
\r
428 CLEAR_BIT(PWR->PDCRF, GPIONumber);
\r
433 SET_BIT(PWR->PUCRG, GPIONumber);
\r
434 CLEAR_BIT(PWR->PDCRG, GPIONumber);
\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
442 CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
\r
447 SET_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
\r
448 CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
\r
452 status = HAL_ERROR;
\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
475 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
\r
477 HAL_StatusTypeDef status = HAL_OK;
\r
479 assert_param(IS_PWR_GPIO(GPIO));
\r
480 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
\r
485 CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));
\r
488 CLEAR_BIT(PWR->PUCRB, GPIONumber);
\r
491 CLEAR_BIT(PWR->PUCRC, GPIONumber);
\r
495 CLEAR_BIT(PWR->PUCRD, GPIONumber);
\r
500 CLEAR_BIT(PWR->PUCRE, GPIONumber);
\r
505 CLEAR_BIT(PWR->PUCRF, GPIONumber);
\r
510 CLEAR_BIT(PWR->PUCRG, GPIONumber);
\r
514 CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
\r
518 CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
\r
522 status = HAL_ERROR;
\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
552 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
\r
554 HAL_StatusTypeDef status = HAL_OK;
\r
556 assert_param(IS_PWR_GPIO(GPIO));
\r
557 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
\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
566 SET_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
\r
567 CLEAR_BIT(PWR->PUCRB, GPIONumber);
\r
570 SET_BIT(PWR->PDCRC, GPIONumber);
\r
571 CLEAR_BIT(PWR->PUCRC, GPIONumber);
\r
575 SET_BIT(PWR->PDCRD, GPIONumber);
\r
576 CLEAR_BIT(PWR->PUCRD, GPIONumber);
\r
581 SET_BIT(PWR->PDCRE, GPIONumber);
\r
582 CLEAR_BIT(PWR->PUCRE, GPIONumber);
\r
587 SET_BIT(PWR->PDCRF, GPIONumber);
\r
588 CLEAR_BIT(PWR->PUCRF, GPIONumber);
\r
593 SET_BIT(PWR->PDCRG, GPIONumber);
\r
594 CLEAR_BIT(PWR->PUCRG, GPIONumber);
\r
598 #if defined (STM32L496xx) || defined (STM32L4A6xx)
\r
599 SET_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));
\r
601 SET_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
\r
603 CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
\r
607 SET_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
\r
608 CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
\r
612 status = HAL_ERROR;
\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
635 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
\r
637 HAL_StatusTypeDef status = HAL_OK;
\r
639 assert_param(IS_PWR_GPIO(GPIO));
\r
640 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
\r
645 CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));
\r
648 CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
\r
651 CLEAR_BIT(PWR->PDCRC, GPIONumber);
\r
655 CLEAR_BIT(PWR->PDCRD, GPIONumber);
\r
660 CLEAR_BIT(PWR->PDCRE, GPIONumber);
\r
665 CLEAR_BIT(PWR->PDCRF, GPIONumber);
\r
670 CLEAR_BIT(PWR->PDCRG, GPIONumber);
\r
674 #if defined (STM32L496xx) || defined (STM32L4A6xx)
\r
675 CLEAR_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3))));
\r
677 CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS));
\r
682 CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS));
\r
686 status = HAL_ERROR;
\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
705 void HAL_PWREx_EnablePullUpPullDownConfig(void)
\r
707 SET_BIT(PWR->CR3, PWR_CR3_APC);
\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
717 void HAL_PWREx_DisablePullUpPullDownConfig(void)
\r
719 CLEAR_BIT(PWR->CR3, PWR_CR3_APC);
\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
730 void HAL_PWREx_EnableSRAM2ContentRetention(void)
\r
732 SET_BIT(PWR->CR3, PWR_CR3_RRS);
\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
742 void HAL_PWREx_DisableSRAM2ContentRetention(void)
\r
744 CLEAR_BIT(PWR->CR3, PWR_CR3_RRS);
\r
748 #if defined(PWR_CR3_ENULP)
\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
754 void HAL_PWREx_EnableBORPVD_ULP(void)
\r
756 SET_BIT(PWR->CR3, PWR_CR3_ENULP);
\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
765 void HAL_PWREx_DisableBORPVD_ULP(void)
\r
767 CLEAR_BIT(PWR->CR3, PWR_CR3_ENULP);
\r
769 #endif /* PWR_CR3_ENULP */
\r
772 #if defined(PWR_CR4_EXT_SMPS_ON)
\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
779 void HAL_PWREx_EnableExtSMPS_0V95(void)
\r
781 SET_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON);
\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
791 void HAL_PWREx_DisableExtSMPS_0V95(void)
\r
793 CLEAR_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON);
\r
795 #endif /* PWR_CR4_EXT_SMPS_ON */
\r
798 #if defined(PWR_CR1_RRSTP)
\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
805 void HAL_PWREx_EnableSRAM3ContentRetention(void)
\r
807 SET_BIT(PWR->CR1, PWR_CR1_RRSTP);
\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
817 void HAL_PWREx_DisableSRAM3ContentRetention(void)
\r
819 CLEAR_BIT(PWR->CR1, PWR_CR1_RRSTP);
\r
821 #endif /* PWR_CR1_RRSTP */
\r
823 #if defined(PWR_CR3_DSIPDEN)
\r
825 * @brief Enable pull-down activation on DSI pins.
\r
828 void HAL_PWREx_EnableDSIPinsPDActivation(void)
\r
830 SET_BIT(PWR->CR3, PWR_CR3_DSIPDEN);
\r
835 * @brief Disable pull-down activation on DSI pins.
\r
838 void HAL_PWREx_DisableDSIPinsPDActivation(void)
\r
840 CLEAR_BIT(PWR->CR3, PWR_CR3_DSIPDEN);
\r
842 #endif /* PWR_CR3_DSIPDEN */
\r
844 #if defined(PWR_CR2_PVME1)
\r
846 * @brief Enable the Power Voltage Monitoring 1: VDDUSB versus 1.2V.
\r
849 void HAL_PWREx_EnablePVM1(void)
\r
851 SET_BIT(PWR->CR2, PWR_PVM_1);
\r
855 * @brief Disable the Power Voltage Monitoring 1: VDDUSB versus 1.2V.
\r
858 void HAL_PWREx_DisablePVM1(void)
\r
860 CLEAR_BIT(PWR->CR2, PWR_PVM_1);
\r
862 #endif /* PWR_CR2_PVME1 */
\r
865 #if defined(PWR_CR2_PVME2)
\r
867 * @brief Enable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V.
\r
870 void HAL_PWREx_EnablePVM2(void)
\r
872 SET_BIT(PWR->CR2, PWR_PVM_2);
\r
876 * @brief Disable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V.
\r
879 void HAL_PWREx_DisablePVM2(void)
\r
881 CLEAR_BIT(PWR->CR2, PWR_PVM_2);
\r
883 #endif /* PWR_CR2_PVME2 */
\r
887 * @brief Enable the Power Voltage Monitoring 3: VDDA versus 1.62V.
\r
890 void HAL_PWREx_EnablePVM3(void)
\r
892 SET_BIT(PWR->CR2, PWR_PVM_3);
\r
896 * @brief Disable the Power Voltage Monitoring 3: VDDA versus 1.62V.
\r
899 void HAL_PWREx_DisablePVM3(void)
\r
901 CLEAR_BIT(PWR->CR2, PWR_PVM_3);
\r
906 * @brief Enable the Power Voltage Monitoring 4: VDDA versus 2.2V.
\r
909 void HAL_PWREx_EnablePVM4(void)
\r
911 SET_BIT(PWR->CR2, PWR_PVM_4);
\r
915 * @brief Disable the Power Voltage Monitoring 4: VDDA versus 2.2V.
\r
918 void HAL_PWREx_DisablePVM4(void)
\r
920 CLEAR_BIT(PWR->CR2, PWR_PVM_4);
\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
938 HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM)
\r
940 HAL_StatusTypeDef status = HAL_OK;
\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
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
952 #if defined(PWR_CR2_PVME1)
\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
960 /* Configure interrupt mode */
\r
961 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
\r
963 __HAL_PWR_PVM1_EXTI_ENABLE_IT();
\r
966 /* Configure event mode */
\r
967 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
\r
969 __HAL_PWR_PVM1_EXTI_ENABLE_EVENT();
\r
972 /* Configure the edge */
\r
973 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
\r
975 __HAL_PWR_PVM1_EXTI_ENABLE_RISING_EDGE();
\r
978 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
\r
980 __HAL_PWR_PVM1_EXTI_ENABLE_FALLING_EDGE();
\r
983 #endif /* PWR_CR2_PVME1 */
\r
985 #if defined(PWR_CR2_PVME2)
\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
993 /* Configure interrupt mode */
\r
994 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
\r
996 __HAL_PWR_PVM2_EXTI_ENABLE_IT();
\r
999 /* Configure event mode */
\r
1000 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
\r
1002 __HAL_PWR_PVM2_EXTI_ENABLE_EVENT();
\r
1005 /* Configure the edge */
\r
1006 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
\r
1008 __HAL_PWR_PVM2_EXTI_ENABLE_RISING_EDGE();
\r
1011 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
\r
1013 __HAL_PWR_PVM2_EXTI_ENABLE_FALLING_EDGE();
\r
1016 #endif /* PWR_CR2_PVME2 */
\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
1025 /* Configure interrupt mode */
\r
1026 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
\r
1028 __HAL_PWR_PVM3_EXTI_ENABLE_IT();
\r
1031 /* Configure event mode */
\r
1032 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
\r
1034 __HAL_PWR_PVM3_EXTI_ENABLE_EVENT();
\r
1037 /* Configure the edge */
\r
1038 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
\r
1040 __HAL_PWR_PVM3_EXTI_ENABLE_RISING_EDGE();
\r
1043 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
\r
1045 __HAL_PWR_PVM3_EXTI_ENABLE_FALLING_EDGE();
\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
1056 /* Configure interrupt mode */
\r
1057 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
\r
1059 __HAL_PWR_PVM4_EXTI_ENABLE_IT();
\r
1062 /* Configure event mode */
\r
1063 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
\r
1065 __HAL_PWR_PVM4_EXTI_ENABLE_EVENT();
\r
1068 /* Configure the edge */
\r
1069 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
\r
1071 __HAL_PWR_PVM4_EXTI_ENABLE_RISING_EDGE();
\r
1074 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
\r
1076 __HAL_PWR_PVM4_EXTI_ENABLE_FALLING_EDGE();
\r
1081 status = HAL_ERROR;
\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
1100 void HAL_PWREx_EnableLowPowerRunMode(void)
\r
1102 /* Set Regulator parameter */
\r
1103 SET_BIT(PWR->CR1, PWR_CR1_LPR);
\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
1115 HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
\r
1117 uint32_t wait_loop_index;
\r
1119 /* Clear LPR bit */
\r
1120 CLEAR_BIT(PWR->CR1, PWR_CR1_LPR);
\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
1126 wait_loop_index--;
\r
1128 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))
\r
1130 return HAL_TIMEOUT;
\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
1159 void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry)
\r
1161 /* Check the parameters */
\r
1162 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
\r
1164 /* Stop 0 mode with Main Regulator */
\r
1165 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP0);
\r
1167 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
1168 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
\r
1170 /* Select Stop mode entry --------------------------------------------------*/
\r
1171 if(STOPEntry == PWR_STOPENTRY_WFI)
\r
1173 /* Request Wait For Interrupt */
\r
1178 /* Request Wait For Event */
\r
1184 /* Reset SLEEPDEEP bit of Cortex System Control Register */
\r
1185 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
\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
1210 void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)
\r
1212 /* Check the parameters */
\r
1213 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
\r
1215 /* Stop 1 mode with Low-Power Regulator */
\r
1216 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP1);
\r
1218 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
1219 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
\r
1221 /* Select Stop mode entry --------------------------------------------------*/
\r
1222 if(STOPEntry == PWR_STOPENTRY_WFI)
\r
1224 /* Request Wait For Interrupt */
\r
1229 /* Request Wait For Event */
\r
1235 /* Reset SLEEPDEEP bit of Cortex System Control Register */
\r
1236 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
\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
1262 void HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry)
\r
1264 /* Check the parameter */
\r
1265 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
\r
1267 /* Set Stop mode 2 */
\r
1268 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP2);
\r
1270 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
1271 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
\r
1273 /* Select Stop mode entry --------------------------------------------------*/
\r
1274 if(STOPEntry == PWR_STOPENTRY_WFI)
\r
1276 /* Request Wait For Interrupt */
\r
1281 /* Request Wait For Event */
\r
1287 /* Reset SLEEPDEEP bit of Cortex System Control Register */
\r
1288 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
\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
1304 void HAL_PWREx_EnterSHUTDOWNMode(void)
\r
1307 /* Set Shutdown mode */
\r
1308 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_SHUTDOWN);
\r
1310 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
1311 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
\r
1313 /* This option is used to ensure that store operations are completed */
\r
1314 #if defined ( __CC_ARM)
\r
1317 /* Request Wait For Interrupt */
\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
1329 void HAL_PWREx_PVD_PVM_IRQHandler(void)
\r
1331 /* Check PWR exti flag */
\r
1332 if(__HAL_PWR_PVD_EXTI_GET_FLAG() != 0x0U)
\r
1334 /* PWR PVD interrupt user callback */
\r
1335 HAL_PWR_PVDCallback();
\r
1337 /* Clear PVD exti pending bit */
\r
1338 __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
\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
1344 /* PWR PVM1 interrupt user callback */
\r
1345 HAL_PWREx_PVM1Callback();
\r
1347 /* Clear PVM1 exti pending bit */
\r
1348 __HAL_PWR_PVM1_EXTI_CLEAR_FLAG();
\r
1350 #endif /* PWR_CR2_PVME1 */
\r
1351 #if defined(PWR_CR2_PVME2)
\r
1352 if(__HAL_PWR_PVM2_EXTI_GET_FLAG() != 0x0U)
\r
1354 /* PWR PVM2 interrupt user callback */
\r
1355 HAL_PWREx_PVM2Callback();
\r
1357 /* Clear PVM2 exti pending bit */
\r
1358 __HAL_PWR_PVM2_EXTI_CLEAR_FLAG();
\r
1360 #endif /* PWR_CR2_PVME2 */
\r
1361 if(__HAL_PWR_PVM3_EXTI_GET_FLAG() != 0x0U)
\r
1363 /* PWR PVM3 interrupt user callback */
\r
1364 HAL_PWREx_PVM3Callback();
\r
1366 /* Clear PVM3 exti pending bit */
\r
1367 __HAL_PWR_PVM3_EXTI_CLEAR_FLAG();
\r
1369 if(__HAL_PWR_PVM4_EXTI_GET_FLAG() != 0x0U)
\r
1371 /* PWR PVM4 interrupt user callback */
\r
1372 HAL_PWREx_PVM4Callback();
\r
1374 /* Clear PVM4 exti pending bit */
\r
1375 __HAL_PWR_PVM4_EXTI_CLEAR_FLAG();
\r
1380 #if defined(PWR_CR2_PVME1)
\r
1382 * @brief PWR PVM1 interrupt callback
\r
1385 __weak void HAL_PWREx_PVM1Callback(void)
\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
1391 #endif /* PWR_CR2_PVME1 */
\r
1393 #if defined(PWR_CR2_PVME2)
\r
1395 * @brief PWR PVM2 interrupt callback
\r
1398 __weak void HAL_PWREx_PVM2Callback(void)
\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
1404 #endif /* PWR_CR2_PVME2 */
\r
1407 * @brief PWR PVM3 interrupt callback
\r
1410 __weak void HAL_PWREx_PVM3Callback(void)
\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
1418 * @brief PWR PVM4 interrupt callback
\r
1421 __weak void HAL_PWREx_PVM4Callback(void)
\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
1437 #endif /* HAL_PWR_MODULE_ENABLED */
\r
1446 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r