STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_pwr_ex.c 00004 * @author MCD Application Team 00005 * @brief Extended PWR HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Power Controller (PWR) peripheral: 00008 * + Extended Initialization and de-initialization functions 00009 * + Extended Peripheral Control functions 00010 * 00011 ****************************************************************************** 00012 * @attention 00013 * 00014 * Copyright (c) 2017 STMicroelectronics. 00015 * All rights reserved. 00016 * 00017 * This software is licensed under terms that can be found in the LICENSE file 00018 * in the root directory of this software component. 00019 * If no LICENSE file comes with this software, it is provided AS-IS. 00020 * 00021 ****************************************************************************** 00022 */ 00023 00024 /* Includes ------------------------------------------------------------------*/ 00025 #include "stm32l4xx_hal.h" 00026 00027 /** @addtogroup STM32L4xx_HAL_Driver 00028 * @{ 00029 */ 00030 00031 /** @defgroup PWREx PWREx 00032 * @brief PWR Extended HAL module driver 00033 * @{ 00034 */ 00035 00036 #ifdef HAL_PWR_MODULE_ENABLED 00037 00038 /* Private typedef -----------------------------------------------------------*/ 00039 /* Private define ------------------------------------------------------------*/ 00040 00041 #if defined (STM32L412xx) || defined (STM32L422xx) || defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) 00042 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x0000000B) /* PH0/PH1/PH3 */ 00043 #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 00044 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x0000000B) /* PH0/PH1/PH3 */ 00045 #elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) 00046 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x00000003) /* PH0/PH1 */ 00047 #elif defined (STM32L496xx) || defined (STM32L4A6xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 00048 #define PWR_PORTH_AVAILABLE_PINS ((uint32_t)0x0000FFFF) /* PH0..PH15 */ 00049 #endif 00050 00051 #if defined (STM32L496xx) || defined (STM32L4A6xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 00052 #define PWR_PORTI_AVAILABLE_PINS ((uint32_t)0x00000FFF) /* PI0..PI11 */ 00053 #endif 00054 00055 /** @defgroup PWR_Extended_Private_Defines PWR Extended Private Defines 00056 * @{ 00057 */ 00058 00059 /** @defgroup PWREx_PVM_Mode_Mask PWR PVM Mode Mask 00060 * @{ 00061 */ 00062 #define PVM_MODE_IT ((uint32_t)0x00010000) /*!< Mask for interruption yielded by PVM threshold crossing */ 00063 #define PVM_MODE_EVT ((uint32_t)0x00020000) /*!< Mask for event yielded by PVM threshold crossing */ 00064 #define PVM_RISING_EDGE ((uint32_t)0x00000001) /*!< Mask for rising edge set as PVM trigger */ 00065 #define PVM_FALLING_EDGE ((uint32_t)0x00000002) /*!< Mask for falling edge set as PVM trigger */ 00066 /** 00067 * @} 00068 */ 00069 00070 /** @defgroup PWREx_TimeOut_Value PWR Extended Flag Setting Time Out Value 00071 * @{ 00072 */ 00073 #define PWR_FLAG_SETTING_DELAY_US 50UL /*!< Time out value for REGLPF and VOSF flags setting */ 00074 /** 00075 * @} 00076 */ 00077 00078 00079 00080 /** 00081 * @} 00082 */ 00083 00084 00085 00086 /* Private macro -------------------------------------------------------------*/ 00087 /* Private variables ---------------------------------------------------------*/ 00088 /* Private function prototypes -----------------------------------------------*/ 00089 /* Exported functions --------------------------------------------------------*/ 00090 00091 /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions 00092 * @{ 00093 */ 00094 00095 /** @defgroup PWREx_Exported_Functions_Group1 Extended Peripheral Control functions 00096 * @brief Extended Peripheral Control functions 00097 * 00098 @verbatim 00099 =============================================================================== 00100 ##### Extended Peripheral Initialization and de-initialization functions ##### 00101 =============================================================================== 00102 [..] 00103 00104 @endverbatim 00105 * @{ 00106 */ 00107 00108 00109 /** 00110 * @brief Return Voltage Scaling Range. 00111 * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1 or PWR_REGULATOR_VOLTAGE_SCALE2 00112 * or PWR_REGULATOR_VOLTAGE_SCALE1_BOOST when applicable) 00113 */ 00114 uint32_t HAL_PWREx_GetVoltageRange(void) 00115 { 00116 #if defined(PWR_CR5_R1MODE) 00117 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2) 00118 { 00119 return PWR_REGULATOR_VOLTAGE_SCALE2; 00120 } 00121 else if (READ_BIT(PWR->CR5, PWR_CR5_R1MODE) == PWR_CR5_R1MODE) 00122 { 00123 /* PWR_CR5_R1MODE bit set means that Range 1 Boost is disabled */ 00124 return PWR_REGULATOR_VOLTAGE_SCALE1; 00125 } 00126 else 00127 { 00128 return PWR_REGULATOR_VOLTAGE_SCALE1_BOOST; 00129 } 00130 #else 00131 return (PWR->CR1 & PWR_CR1_VOS); 00132 #endif 00133 } 00134 00135 00136 00137 /** 00138 * @brief Configure the main internal regulator output voltage. 00139 * @param VoltageScaling specifies the regulator output voltage to achieve 00140 * a tradeoff between performance and power consumption. 00141 * This parameter can be one of the following values: 00142 @if STM32L4S9xx 00143 * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1_BOOST when available, Regulator voltage output range 1 boost mode, 00144 * typical output voltage at 1.2 V, 00145 * system frequency up to 120 MHz. 00146 @endif 00147 * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1 Regulator voltage output range 1 mode, 00148 * typical output voltage at 1.2 V, 00149 * system frequency up to 80 MHz. 00150 * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE2 Regulator voltage output range 2 mode, 00151 * typical output voltage at 1.0 V, 00152 * system frequency up to 26 MHz. 00153 * @note When moving from Range 1 to Range 2, the system frequency must be decreased to 00154 * a value below 26 MHz before calling HAL_PWREx_ControlVoltageScaling() API. 00155 * When moving from Range 2 to Range 1, the system frequency can be increased to 00156 * a value up to 80 MHz after calling HAL_PWREx_ControlVoltageScaling() API. For 00157 * some devices, the system frequency can be increased up to 120 MHz. 00158 * @note When moving from Range 2 to Range 1, the API waits for VOSF flag to be 00159 * cleared before returning the status. If the flag is not cleared within 00160 * 50 microseconds, HAL_TIMEOUT status is reported. 00161 * @retval HAL Status 00162 */ 00163 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling) 00164 { 00165 uint32_t wait_loop_index; 00166 00167 assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling)); 00168 00169 #if defined(PWR_CR5_R1MODE) 00170 if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1_BOOST) 00171 { 00172 /* If current range is range 2 */ 00173 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2) 00174 { 00175 /* Make sure Range 1 Boost is enabled */ 00176 CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE); 00177 00178 /* Set Range 1 */ 00179 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1); 00180 00181 /* Wait until VOSF is cleared */ 00182 wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1; 00183 while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U)) 00184 { 00185 wait_loop_index--; 00186 } 00187 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) 00188 { 00189 return HAL_TIMEOUT; 00190 } 00191 } 00192 /* If current range is range 1 normal or boost mode */ 00193 else 00194 { 00195 /* Enable Range 1 Boost (no issue if bit already reset) */ 00196 CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE); 00197 } 00198 } 00199 else if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1) 00200 { 00201 /* If current range is range 2 */ 00202 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2) 00203 { 00204 /* Make sure Range 1 Boost is disabled */ 00205 SET_BIT(PWR->CR5, PWR_CR5_R1MODE); 00206 00207 /* Set Range 1 */ 00208 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1); 00209 00210 /* Wait until VOSF is cleared */ 00211 wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1; 00212 while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U)) 00213 { 00214 wait_loop_index--; 00215 } 00216 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) 00217 { 00218 return HAL_TIMEOUT; 00219 } 00220 } 00221 /* If current range is range 1 normal or boost mode */ 00222 else 00223 { 00224 /* Disable Range 1 Boost (no issue if bit already set) */ 00225 SET_BIT(PWR->CR5, PWR_CR5_R1MODE); 00226 } 00227 } 00228 else 00229 { 00230 /* Set Range 2 */ 00231 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE2); 00232 /* No need to wait for VOSF to be cleared for this transition */ 00233 /* PWR_CR5_R1MODE bit setting has no effect in Range 2 */ 00234 } 00235 00236 #else 00237 00238 /* If Set Range 1 */ 00239 if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1) 00240 { 00241 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE1) 00242 { 00243 /* Set Range 1 */ 00244 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1); 00245 00246 /* Wait until VOSF is cleared */ 00247 wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U; 00248 while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U)) 00249 { 00250 wait_loop_index--; 00251 } 00252 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) 00253 { 00254 return HAL_TIMEOUT; 00255 } 00256 } 00257 } 00258 else 00259 { 00260 if (READ_BIT(PWR->CR1, PWR_CR1_VOS) != PWR_REGULATOR_VOLTAGE_SCALE2) 00261 { 00262 /* Set Range 2 */ 00263 MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE2); 00264 /* No need to wait for VOSF to be cleared for this transition */ 00265 } 00266 } 00267 #endif 00268 00269 return HAL_OK; 00270 } 00271 00272 00273 /** 00274 * @brief Enable battery charging. 00275 * When VDD is present, charge the external battery on VBAT thru an internal resistor. 00276 * @param ResistorSelection specifies the resistor impedance. 00277 * This parameter can be one of the following values: 00278 * @arg @ref PWR_BATTERY_CHARGING_RESISTOR_5 5 kOhms resistor 00279 * @arg @ref PWR_BATTERY_CHARGING_RESISTOR_1_5 1.5 kOhms resistor 00280 * @retval None 00281 */ 00282 void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection) 00283 { 00284 assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorSelection)); 00285 00286 /* Specify resistor selection */ 00287 MODIFY_REG(PWR->CR4, PWR_CR4_VBRS, ResistorSelection); 00288 00289 /* Enable battery charging */ 00290 SET_BIT(PWR->CR4, PWR_CR4_VBE); 00291 } 00292 00293 00294 /** 00295 * @brief Disable battery charging. 00296 * @retval None 00297 */ 00298 void HAL_PWREx_DisableBatteryCharging(void) 00299 { 00300 CLEAR_BIT(PWR->CR4, PWR_CR4_VBE); 00301 } 00302 00303 00304 #if defined(PWR_CR2_USV) 00305 /** 00306 * @brief Enable VDDUSB supply. 00307 * @note Remove VDDUSB electrical and logical isolation, once VDDUSB supply is present. 00308 * @retval None 00309 */ 00310 void HAL_PWREx_EnableVddUSB(void) 00311 { 00312 SET_BIT(PWR->CR2, PWR_CR2_USV); 00313 } 00314 00315 00316 /** 00317 * @brief Disable VDDUSB supply. 00318 * @retval None 00319 */ 00320 void HAL_PWREx_DisableVddUSB(void) 00321 { 00322 CLEAR_BIT(PWR->CR2, PWR_CR2_USV); 00323 } 00324 #endif /* PWR_CR2_USV */ 00325 00326 #if defined(PWR_CR2_IOSV) 00327 /** 00328 * @brief Enable VDDIO2 supply. 00329 * @note Remove VDDIO2 electrical and logical isolation, once VDDIO2 supply is present. 00330 * @retval None 00331 */ 00332 void HAL_PWREx_EnableVddIO2(void) 00333 { 00334 SET_BIT(PWR->CR2, PWR_CR2_IOSV); 00335 } 00336 00337 00338 /** 00339 * @brief Disable VDDIO2 supply. 00340 * @retval None 00341 */ 00342 void HAL_PWREx_DisableVddIO2(void) 00343 { 00344 CLEAR_BIT(PWR->CR2, PWR_CR2_IOSV); 00345 } 00346 #endif /* PWR_CR2_IOSV */ 00347 00348 00349 /** 00350 * @brief Enable Internal Wake-up Line. 00351 * @retval None 00352 */ 00353 void HAL_PWREx_EnableInternalWakeUpLine(void) 00354 { 00355 SET_BIT(PWR->CR3, PWR_CR3_EIWF); 00356 } 00357 00358 00359 /** 00360 * @brief Disable Internal Wake-up Line. 00361 * @retval None 00362 */ 00363 void HAL_PWREx_DisableInternalWakeUpLine(void) 00364 { 00365 CLEAR_BIT(PWR->CR3, PWR_CR3_EIWF); 00366 } 00367 00368 00369 00370 /** 00371 * @brief Enable GPIO pull-up state in Standby and Shutdown modes. 00372 * @note Set the relevant PUy bits of PWR_PUCRx register to configure the I/O in 00373 * pull-up state in Standby and Shutdown modes. 00374 * @note This state is effective in Standby and Shutdown modes only if APC bit 00375 * is set through HAL_PWREx_EnablePullUpPullDownConfig() API. 00376 * @note The configuration is lost when exiting the Shutdown mode due to the 00377 * power-on reset, maintained when exiting the Standby mode. 00378 * @note To avoid any conflict at Standby and Shutdown modes exits, the corresponding 00379 * PDy bit of PWR_PDCRx register is cleared unless it is reserved. 00380 * @note Even if a PUy bit to set is reserved, the other PUy bits entered as input 00381 * parameter at the same time are set. 00382 * @param GPIO Specify the IO port. This parameter can be PWR_GPIO_A, ..., PWR_GPIO_H 00383 * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral. 00384 * @param GPIONumber Specify the I/O pins numbers. 00385 * This parameter can be one of the following values: 00386 * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less 00387 * I/O pins are available) or the logical OR of several of them to set 00388 * several bits for a given port in a single API call. 00389 * @retval HAL Status 00390 */ 00391 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber) 00392 { 00393 HAL_StatusTypeDef status = HAL_OK; 00394 00395 assert_param(IS_PWR_GPIO(GPIO)); 00396 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber)); 00397 00398 switch (GPIO) 00399 { 00400 case PWR_GPIO_A: 00401 SET_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14)))); 00402 CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15)))); 00403 break; 00404 case PWR_GPIO_B: 00405 SET_BIT(PWR->PUCRB, GPIONumber); 00406 CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4)))); 00407 break; 00408 case PWR_GPIO_C: 00409 SET_BIT(PWR->PUCRC, GPIONumber); 00410 CLEAR_BIT(PWR->PDCRC, GPIONumber); 00411 break; 00412 #if defined(GPIOD) 00413 case PWR_GPIO_D: 00414 SET_BIT(PWR->PUCRD, GPIONumber); 00415 CLEAR_BIT(PWR->PDCRD, GPIONumber); 00416 break; 00417 #endif 00418 #if defined(GPIOE) 00419 case PWR_GPIO_E: 00420 SET_BIT(PWR->PUCRE, GPIONumber); 00421 CLEAR_BIT(PWR->PDCRE, GPIONumber); 00422 break; 00423 #endif 00424 #if defined(GPIOF) 00425 case PWR_GPIO_F: 00426 SET_BIT(PWR->PUCRF, GPIONumber); 00427 CLEAR_BIT(PWR->PDCRF, GPIONumber); 00428 break; 00429 #endif 00430 #if defined(GPIOG) 00431 case PWR_GPIO_G: 00432 SET_BIT(PWR->PUCRG, GPIONumber); 00433 CLEAR_BIT(PWR->PDCRG, GPIONumber); 00434 break; 00435 #endif 00436 case PWR_GPIO_H: 00437 SET_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS)); 00438 #if defined (STM32L496xx) || defined (STM32L4A6xx) 00439 CLEAR_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3)))); 00440 #else 00441 CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS)); 00442 #endif 00443 break; 00444 #if defined(GPIOI) 00445 case PWR_GPIO_I: 00446 SET_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS)); 00447 CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS)); 00448 break; 00449 #endif 00450 default: 00451 status = HAL_ERROR; 00452 break; 00453 } 00454 00455 return status; 00456 } 00457 00458 00459 /** 00460 * @brief Disable GPIO pull-up state in Standby mode and Shutdown modes. 00461 * @note Reset the relevant PUy bits of PWR_PUCRx register used to configure the I/O 00462 * in pull-up state in Standby and Shutdown modes. 00463 * @note Even if a PUy bit to reset is reserved, the other PUy bits entered as input 00464 * parameter at the same time are reset. 00465 * @param GPIO Specifies the IO port. This parameter can be PWR_GPIO_A, ..., PWR_GPIO_H 00466 * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral. 00467 * @param GPIONumber Specify the I/O pins numbers. 00468 * This parameter can be one of the following values: 00469 * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less 00470 * I/O pins are available) or the logical OR of several of them to reset 00471 * several bits for a given port in a single API call. 00472 * @retval HAL Status 00473 */ 00474 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber) 00475 { 00476 HAL_StatusTypeDef status = HAL_OK; 00477 00478 assert_param(IS_PWR_GPIO(GPIO)); 00479 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber)); 00480 00481 switch (GPIO) 00482 { 00483 case PWR_GPIO_A: 00484 CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14)))); 00485 break; 00486 case PWR_GPIO_B: 00487 CLEAR_BIT(PWR->PUCRB, GPIONumber); 00488 break; 00489 case PWR_GPIO_C: 00490 CLEAR_BIT(PWR->PUCRC, GPIONumber); 00491 break; 00492 #if defined(GPIOD) 00493 case PWR_GPIO_D: 00494 CLEAR_BIT(PWR->PUCRD, GPIONumber); 00495 break; 00496 #endif 00497 #if defined(GPIOE) 00498 case PWR_GPIO_E: 00499 CLEAR_BIT(PWR->PUCRE, GPIONumber); 00500 break; 00501 #endif 00502 #if defined(GPIOF) 00503 case PWR_GPIO_F: 00504 CLEAR_BIT(PWR->PUCRF, GPIONumber); 00505 break; 00506 #endif 00507 #if defined(GPIOG) 00508 case PWR_GPIO_G: 00509 CLEAR_BIT(PWR->PUCRG, GPIONumber); 00510 break; 00511 #endif 00512 case PWR_GPIO_H: 00513 CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS)); 00514 break; 00515 #if defined(GPIOI) 00516 case PWR_GPIO_I: 00517 CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS)); 00518 break; 00519 #endif 00520 default: 00521 status = HAL_ERROR; 00522 break; 00523 } 00524 00525 return status; 00526 } 00527 00528 00529 00530 /** 00531 * @brief Enable GPIO pull-down state in Standby and Shutdown modes. 00532 * @note Set the relevant PDy bits of PWR_PDCRx register to configure the I/O in 00533 * pull-down state in Standby and Shutdown modes. 00534 * @note This state is effective in Standby and Shutdown modes only if APC bit 00535 * is set through HAL_PWREx_EnablePullUpPullDownConfig() API. 00536 * @note The configuration is lost when exiting the Shutdown mode due to the 00537 * power-on reset, maintained when exiting the Standby mode. 00538 * @note To avoid any conflict at Standby and Shutdown modes exits, the corresponding 00539 * PUy bit of PWR_PUCRx register is cleared unless it is reserved. 00540 * @note Even if a PDy bit to set is reserved, the other PDy bits entered as input 00541 * parameter at the same time are set. 00542 * @param GPIO Specify the IO port. This parameter can be PWR_GPIO_A..PWR_GPIO_H 00543 * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral. 00544 * @param GPIONumber Specify the I/O pins numbers. 00545 * This parameter can be one of the following values: 00546 * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less 00547 * I/O pins are available) or the logical OR of several of them to set 00548 * several bits for a given port in a single API call. 00549 * @retval HAL Status 00550 */ 00551 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber) 00552 { 00553 HAL_StatusTypeDef status = HAL_OK; 00554 00555 assert_param(IS_PWR_GPIO(GPIO)); 00556 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber)); 00557 00558 switch (GPIO) 00559 { 00560 case PWR_GPIO_A: 00561 SET_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15)))); 00562 CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14)))); 00563 break; 00564 case PWR_GPIO_B: 00565 SET_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4)))); 00566 CLEAR_BIT(PWR->PUCRB, GPIONumber); 00567 break; 00568 case PWR_GPIO_C: 00569 SET_BIT(PWR->PDCRC, GPIONumber); 00570 CLEAR_BIT(PWR->PUCRC, GPIONumber); 00571 break; 00572 #if defined(GPIOD) 00573 case PWR_GPIO_D: 00574 SET_BIT(PWR->PDCRD, GPIONumber); 00575 CLEAR_BIT(PWR->PUCRD, GPIONumber); 00576 break; 00577 #endif 00578 #if defined(GPIOE) 00579 case PWR_GPIO_E: 00580 SET_BIT(PWR->PDCRE, GPIONumber); 00581 CLEAR_BIT(PWR->PUCRE, GPIONumber); 00582 break; 00583 #endif 00584 #if defined(GPIOF) 00585 case PWR_GPIO_F: 00586 SET_BIT(PWR->PDCRF, GPIONumber); 00587 CLEAR_BIT(PWR->PUCRF, GPIONumber); 00588 break; 00589 #endif 00590 #if defined(GPIOG) 00591 case PWR_GPIO_G: 00592 SET_BIT(PWR->PDCRG, GPIONumber); 00593 CLEAR_BIT(PWR->PUCRG, GPIONumber); 00594 break; 00595 #endif 00596 case PWR_GPIO_H: 00597 #if defined (STM32L496xx) || defined (STM32L4A6xx) 00598 SET_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3)))); 00599 #else 00600 SET_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS)); 00601 #endif 00602 CLEAR_BIT(PWR->PUCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS)); 00603 break; 00604 #if defined(GPIOI) 00605 case PWR_GPIO_I: 00606 SET_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS)); 00607 CLEAR_BIT(PWR->PUCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS)); 00608 break; 00609 #endif 00610 default: 00611 status = HAL_ERROR; 00612 break; 00613 } 00614 00615 return status; 00616 } 00617 00618 00619 /** 00620 * @brief Disable GPIO pull-down state in Standby and Shutdown modes. 00621 * @note Reset the relevant PDy bits of PWR_PDCRx register used to configure the I/O 00622 * in pull-down state in Standby and Shutdown modes. 00623 * @note Even if a PDy bit to reset is reserved, the other PDy bits entered as input 00624 * parameter at the same time are reset. 00625 * @param GPIO Specifies the IO port. This parameter can be PWR_GPIO_A..PWR_GPIO_H 00626 * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral. 00627 * @param GPIONumber Specify the I/O pins numbers. 00628 * This parameter can be one of the following values: 00629 * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less 00630 * I/O pins are available) or the logical OR of several of them to reset 00631 * several bits for a given port in a single API call. 00632 * @retval HAL Status 00633 */ 00634 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber) 00635 { 00636 HAL_StatusTypeDef status = HAL_OK; 00637 00638 assert_param(IS_PWR_GPIO(GPIO)); 00639 assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber)); 00640 00641 switch (GPIO) 00642 { 00643 case PWR_GPIO_A: 00644 CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15)))); 00645 break; 00646 case PWR_GPIO_B: 00647 CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4)))); 00648 break; 00649 case PWR_GPIO_C: 00650 CLEAR_BIT(PWR->PDCRC, GPIONumber); 00651 break; 00652 #if defined(GPIOD) 00653 case PWR_GPIO_D: 00654 CLEAR_BIT(PWR->PDCRD, GPIONumber); 00655 break; 00656 #endif 00657 #if defined(GPIOE) 00658 case PWR_GPIO_E: 00659 CLEAR_BIT(PWR->PDCRE, GPIONumber); 00660 break; 00661 #endif 00662 #if defined(GPIOF) 00663 case PWR_GPIO_F: 00664 CLEAR_BIT(PWR->PDCRF, GPIONumber); 00665 break; 00666 #endif 00667 #if defined(GPIOG) 00668 case PWR_GPIO_G: 00669 CLEAR_BIT(PWR->PDCRG, GPIONumber); 00670 break; 00671 #endif 00672 case PWR_GPIO_H: 00673 #if defined (STM32L496xx) || defined (STM32L4A6xx) 00674 CLEAR_BIT(PWR->PDCRH, ((GPIONumber & PWR_PORTH_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_3)))); 00675 #else 00676 CLEAR_BIT(PWR->PDCRH, (GPIONumber & PWR_PORTH_AVAILABLE_PINS)); 00677 #endif 00678 break; 00679 #if defined(GPIOI) 00680 case PWR_GPIO_I: 00681 CLEAR_BIT(PWR->PDCRI, (GPIONumber & PWR_PORTI_AVAILABLE_PINS)); 00682 break; 00683 #endif 00684 default: 00685 status = HAL_ERROR; 00686 break; 00687 } 00688 00689 return status; 00690 } 00691 00692 00693 00694 /** 00695 * @brief Enable pull-up and pull-down configuration. 00696 * @note When APC bit is set, the I/O pull-up and pull-down configurations defined in 00697 * PWR_PUCRx and PWR_PDCRx registers are applied in Standby and Shutdown modes. 00698 * @note Pull-up set by PUy bit of PWR_PUCRx register is not activated if the corresponding 00699 * PDy bit of PWR_PDCRx register is also set (pull-down configuration priority is higher). 00700 * HAL_PWREx_EnableGPIOPullUp() and HAL_PWREx_EnableGPIOPullDown() API's ensure there 00701 * is no conflict when setting PUy or PDy bit. 00702 * @retval None 00703 */ 00704 void HAL_PWREx_EnablePullUpPullDownConfig(void) 00705 { 00706 SET_BIT(PWR->CR3, PWR_CR3_APC); 00707 } 00708 00709 00710 /** 00711 * @brief Disable pull-up and pull-down configuration. 00712 * @note When APC bit is cleared, the I/O pull-up and pull-down configurations defined in 00713 * PWR_PUCRx and PWR_PDCRx registers are not applied in Standby and Shutdown modes. 00714 * @retval None 00715 */ 00716 void HAL_PWREx_DisablePullUpPullDownConfig(void) 00717 { 00718 CLEAR_BIT(PWR->CR3, PWR_CR3_APC); 00719 } 00720 00721 00722 00723 /** 00724 * @brief Enable Full SRAM2 content retention in Standby mode. 00725 * @retval None 00726 */ 00727 void HAL_PWREx_EnableSRAM2ContentRetention(void) 00728 { 00729 (void) HAL_PWREx_SetSRAM2ContentRetention(PWR_FULL_SRAM2_RETENTION); 00730 } 00731 00732 /** 00733 * @brief Disable SRAM2 content retention in Standby mode. 00734 * @retval None 00735 */ 00736 void HAL_PWREx_DisableSRAM2ContentRetention(void) 00737 { 00738 (void) HAL_PWREx_SetSRAM2ContentRetention(PWR_NO_SRAM2_RETENTION); 00739 } 00740 00741 /** 00742 * @brief Enable SRAM2 content retention in Standby mode. 00743 * @param SRAM2Size: specifies the SRAM2 size kept in Standby mode 00744 * This parameter can be one of the following values: 00745 * @arg @ref PWR_NO_SRAM2_RETENTION SRAM2 is powered off in Standby mode (SRAM2 content is lost) 00746 * @arg @ref PWR_FULL_SRAM2_RETENTION Full SRAM2 is powered by the low-power regulator in Standby mode 00747 * @arg @ref PWR_4KBYTES_SRAM2_RETENTION Only 4 Kbytes of SRAM2 is powered by the low-power regulator in Standby mode 00748 * @note PWR_4KBYTES_SRAM2_RETENTION parameter is not available on all devices 00749 * @retval HAL Status 00750 */ 00751 HAL_StatusTypeDef HAL_PWREx_SetSRAM2ContentRetention(uint32_t SRAM2Size) 00752 { 00753 assert_param(IS_PWR_SRAM2_RETENTION(SRAM2Size)); 00754 00755 if (SRAM2Size == PWR_NO_SRAM2_RETENTION) 00756 { 00757 CLEAR_BIT(PWR->CR3, PWR_CR3_RRS); 00758 } 00759 else if (SRAM2Size == PWR_FULL_SRAM2_RETENTION) 00760 { 00761 MODIFY_REG(PWR->CR3, PWR_CR3_RRS, PWR_FULL_SRAM2_RETENTION); 00762 } 00763 #if defined(PWR_CR3_RRS_1) 00764 else if (SRAM2Size == PWR_4KBYTES_SRAM2_RETENTION) 00765 { 00766 MODIFY_REG(PWR->CR3, PWR_CR3_RRS, PWR_4KBYTES_SRAM2_RETENTION); 00767 } 00768 #endif /* PWR_CR3_RRS_1 */ 00769 else { 00770 return HAL_ERROR; 00771 } 00772 00773 return HAL_OK; 00774 } 00775 00776 00777 #if defined(PWR_CR3_ENULP) 00778 /** 00779 * @brief Enable Ultra Low Power BORL, BORH and PVD for STOP2 and Standby modes. 00780 * @note All the other modes are not affected by this bit. 00781 * @retval None 00782 */ 00783 void HAL_PWREx_EnableBORPVD_ULP(void) 00784 { 00785 SET_BIT(PWR->CR3, PWR_CR3_ENULP); 00786 } 00787 00788 00789 /** 00790 * @brief Disable Ultra Low Power BORL, BORH and PVD for STOP2 and Standby modes. 00791 * @note All the other modes are not affected by this bit 00792 * @retval None 00793 */ 00794 void HAL_PWREx_DisableBORPVD_ULP(void) 00795 { 00796 CLEAR_BIT(PWR->CR3, PWR_CR3_ENULP); 00797 } 00798 #endif /* PWR_CR3_ENULP */ 00799 00800 00801 #if defined(PWR_CR4_EXT_SMPS_ON) 00802 /** 00803 * @brief Enable the CFLDO working @ 0.95V. 00804 * @note When external SMPS is used & CFLDO operating in Range 2, the regulated voltage of the 00805 * internal CFLDO can be reduced to 0.95V. 00806 * @retval None 00807 */ 00808 void HAL_PWREx_EnableExtSMPS_0V95(void) 00809 { 00810 SET_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON); 00811 } 00812 00813 /** 00814 * @brief Disable the CFLDO working @ 0.95V 00815 * @note Before SMPS is switched off, the regulated voltage of the 00816 * internal CFLDO shall be set to 1.00V. 00817 * 1.00V. is also default operating Range 2 voltage. 00818 * @retval None 00819 */ 00820 void HAL_PWREx_DisableExtSMPS_0V95(void) 00821 { 00822 CLEAR_BIT(PWR->CR4, PWR_CR4_EXT_SMPS_ON); 00823 } 00824 #endif /* PWR_CR4_EXT_SMPS_ON */ 00825 00826 00827 #if defined(PWR_CR1_RRSTP) 00828 /** 00829 * @brief Enable SRAM3 content retention in Stop 2 mode. 00830 * @note When RRSTP bit is set, SRAM3 is powered by the low-power regulator in 00831 * Stop 2 mode and its content is kept. 00832 * @retval None 00833 */ 00834 void HAL_PWREx_EnableSRAM3ContentRetention(void) 00835 { 00836 SET_BIT(PWR->CR1, PWR_CR1_RRSTP); 00837 } 00838 00839 00840 /** 00841 * @brief Disable SRAM3 content retention in Stop 2 mode. 00842 * @note When RRSTP bit is reset, SRAM3 is powered off in Stop 2 mode 00843 * and its content is lost. 00844 * @retval None 00845 */ 00846 void HAL_PWREx_DisableSRAM3ContentRetention(void) 00847 { 00848 CLEAR_BIT(PWR->CR1, PWR_CR1_RRSTP); 00849 } 00850 #endif /* PWR_CR1_RRSTP */ 00851 00852 #if defined(PWR_CR3_DSIPDEN) 00853 /** 00854 * @brief Enable pull-down activation on DSI pins. 00855 * @retval None 00856 */ 00857 void HAL_PWREx_EnableDSIPinsPDActivation(void) 00858 { 00859 SET_BIT(PWR->CR3, PWR_CR3_DSIPDEN); 00860 } 00861 00862 00863 /** 00864 * @brief Disable pull-down activation on DSI pins. 00865 * @retval None 00866 */ 00867 void HAL_PWREx_DisableDSIPinsPDActivation(void) 00868 { 00869 CLEAR_BIT(PWR->CR3, PWR_CR3_DSIPDEN); 00870 } 00871 #endif /* PWR_CR3_DSIPDEN */ 00872 00873 #if defined(PWR_CR2_PVME1) 00874 /** 00875 * @brief Enable the Power Voltage Monitoring 1: VDDUSB versus 1.2V. 00876 * @retval None 00877 */ 00878 void HAL_PWREx_EnablePVM1(void) 00879 { 00880 SET_BIT(PWR->CR2, PWR_PVM_1); 00881 } 00882 00883 /** 00884 * @brief Disable the Power Voltage Monitoring 1: VDDUSB versus 1.2V. 00885 * @retval None 00886 */ 00887 void HAL_PWREx_DisablePVM1(void) 00888 { 00889 CLEAR_BIT(PWR->CR2, PWR_PVM_1); 00890 } 00891 #endif /* PWR_CR2_PVME1 */ 00892 00893 00894 #if defined(PWR_CR2_PVME2) 00895 /** 00896 * @brief Enable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V. 00897 * @retval None 00898 */ 00899 void HAL_PWREx_EnablePVM2(void) 00900 { 00901 SET_BIT(PWR->CR2, PWR_PVM_2); 00902 } 00903 00904 /** 00905 * @brief Disable the Power Voltage Monitoring 2: VDDIO2 versus 0.9V. 00906 * @retval None 00907 */ 00908 void HAL_PWREx_DisablePVM2(void) 00909 { 00910 CLEAR_BIT(PWR->CR2, PWR_PVM_2); 00911 } 00912 #endif /* PWR_CR2_PVME2 */ 00913 00914 00915 /** 00916 * @brief Enable the Power Voltage Monitoring 3: VDDA versus 1.62V. 00917 * @retval None 00918 */ 00919 void HAL_PWREx_EnablePVM3(void) 00920 { 00921 SET_BIT(PWR->CR2, PWR_PVM_3); 00922 } 00923 00924 /** 00925 * @brief Disable the Power Voltage Monitoring 3: VDDA versus 1.62V. 00926 * @retval None 00927 */ 00928 void HAL_PWREx_DisablePVM3(void) 00929 { 00930 CLEAR_BIT(PWR->CR2, PWR_PVM_3); 00931 } 00932 00933 00934 /** 00935 * @brief Enable the Power Voltage Monitoring 4: VDDA versus 2.2V. 00936 * @retval None 00937 */ 00938 void HAL_PWREx_EnablePVM4(void) 00939 { 00940 SET_BIT(PWR->CR2, PWR_PVM_4); 00941 } 00942 00943 /** 00944 * @brief Disable the Power Voltage Monitoring 4: VDDA versus 2.2V. 00945 * @retval None 00946 */ 00947 void HAL_PWREx_DisablePVM4(void) 00948 { 00949 CLEAR_BIT(PWR->CR2, PWR_PVM_4); 00950 } 00951 00952 00953 00954 00955 /** 00956 * @brief Configure the Peripheral Voltage Monitoring (PVM). 00957 * @param sConfigPVM: pointer to a PWR_PVMTypeDef structure that contains the 00958 * PVM configuration information. 00959 * @note The API configures a single PVM according to the information contained 00960 * in the input structure. To configure several PVMs, the API must be singly 00961 * called for each PVM used. 00962 * @note Refer to the electrical characteristics of your device datasheet for 00963 * more details about the voltage thresholds corresponding to each 00964 * detection level and to each monitored supply. 00965 * @retval HAL status 00966 */ 00967 HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM) 00968 { 00969 HAL_StatusTypeDef status = HAL_OK; 00970 00971 /* Check the parameters */ 00972 assert_param(IS_PWR_PVM_TYPE(sConfigPVM->PVMType)); 00973 assert_param(IS_PWR_PVM_MODE(sConfigPVM->Mode)); 00974 00975 00976 /* Configure EXTI 35 to 38 interrupts if so required: 00977 scan thru PVMType to detect which PVMx is set and 00978 configure the corresponding EXTI line accordingly. */ 00979 switch (sConfigPVM->PVMType) 00980 { 00981 #if defined(PWR_CR2_PVME1) 00982 case PWR_PVM_1: 00983 /* Clear any previous config. Keep it clear if no event or IT mode is selected */ 00984 __HAL_PWR_PVM1_EXTI_DISABLE_EVENT(); 00985 __HAL_PWR_PVM1_EXTI_DISABLE_IT(); 00986 __HAL_PWR_PVM1_EXTI_DISABLE_FALLING_EDGE(); 00987 __HAL_PWR_PVM1_EXTI_DISABLE_RISING_EDGE(); 00988 00989 /* Configure interrupt mode */ 00990 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT) 00991 { 00992 __HAL_PWR_PVM1_EXTI_ENABLE_IT(); 00993 } 00994 00995 /* Configure event mode */ 00996 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT) 00997 { 00998 __HAL_PWR_PVM1_EXTI_ENABLE_EVENT(); 00999 } 01000 01001 /* Configure the edge */ 01002 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE) 01003 { 01004 __HAL_PWR_PVM1_EXTI_ENABLE_RISING_EDGE(); 01005 } 01006 01007 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE) 01008 { 01009 __HAL_PWR_PVM1_EXTI_ENABLE_FALLING_EDGE(); 01010 } 01011 break; 01012 #endif /* PWR_CR2_PVME1 */ 01013 01014 #if defined(PWR_CR2_PVME2) 01015 case PWR_PVM_2: 01016 /* Clear any previous config. Keep it clear if no event or IT mode is selected */ 01017 __HAL_PWR_PVM2_EXTI_DISABLE_EVENT(); 01018 __HAL_PWR_PVM2_EXTI_DISABLE_IT(); 01019 __HAL_PWR_PVM2_EXTI_DISABLE_FALLING_EDGE(); 01020 __HAL_PWR_PVM2_EXTI_DISABLE_RISING_EDGE(); 01021 01022 /* Configure interrupt mode */ 01023 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT) 01024 { 01025 __HAL_PWR_PVM2_EXTI_ENABLE_IT(); 01026 } 01027 01028 /* Configure event mode */ 01029 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT) 01030 { 01031 __HAL_PWR_PVM2_EXTI_ENABLE_EVENT(); 01032 } 01033 01034 /* Configure the edge */ 01035 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE) 01036 { 01037 __HAL_PWR_PVM2_EXTI_ENABLE_RISING_EDGE(); 01038 } 01039 01040 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE) 01041 { 01042 __HAL_PWR_PVM2_EXTI_ENABLE_FALLING_EDGE(); 01043 } 01044 break; 01045 #endif /* PWR_CR2_PVME2 */ 01046 01047 case PWR_PVM_3: 01048 /* Clear any previous config. Keep it clear if no event or IT mode is selected */ 01049 __HAL_PWR_PVM3_EXTI_DISABLE_EVENT(); 01050 __HAL_PWR_PVM3_EXTI_DISABLE_IT(); 01051 __HAL_PWR_PVM3_EXTI_DISABLE_FALLING_EDGE(); 01052 __HAL_PWR_PVM3_EXTI_DISABLE_RISING_EDGE(); 01053 01054 /* Configure interrupt mode */ 01055 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT) 01056 { 01057 __HAL_PWR_PVM3_EXTI_ENABLE_IT(); 01058 } 01059 01060 /* Configure event mode */ 01061 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT) 01062 { 01063 __HAL_PWR_PVM3_EXTI_ENABLE_EVENT(); 01064 } 01065 01066 /* Configure the edge */ 01067 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE) 01068 { 01069 __HAL_PWR_PVM3_EXTI_ENABLE_RISING_EDGE(); 01070 } 01071 01072 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE) 01073 { 01074 __HAL_PWR_PVM3_EXTI_ENABLE_FALLING_EDGE(); 01075 } 01076 break; 01077 01078 case PWR_PVM_4: 01079 /* Clear any previous config. Keep it clear if no event or IT mode is selected */ 01080 __HAL_PWR_PVM4_EXTI_DISABLE_EVENT(); 01081 __HAL_PWR_PVM4_EXTI_DISABLE_IT(); 01082 __HAL_PWR_PVM4_EXTI_DISABLE_FALLING_EDGE(); 01083 __HAL_PWR_PVM4_EXTI_DISABLE_RISING_EDGE(); 01084 01085 /* Configure interrupt mode */ 01086 if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT) 01087 { 01088 __HAL_PWR_PVM4_EXTI_ENABLE_IT(); 01089 } 01090 01091 /* Configure event mode */ 01092 if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT) 01093 { 01094 __HAL_PWR_PVM4_EXTI_ENABLE_EVENT(); 01095 } 01096 01097 /* Configure the edge */ 01098 if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE) 01099 { 01100 __HAL_PWR_PVM4_EXTI_ENABLE_RISING_EDGE(); 01101 } 01102 01103 if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE) 01104 { 01105 __HAL_PWR_PVM4_EXTI_ENABLE_FALLING_EDGE(); 01106 } 01107 break; 01108 01109 default: 01110 status = HAL_ERROR; 01111 break; 01112 } 01113 01114 return status; 01115 } 01116 01117 01118 01119 /** 01120 * @brief Enter Low-power Run mode 01121 * @note In Low-power Run mode, all I/O pins keep the same state as in Run mode. 01122 * @note When Regulator is set to PWR_LOWPOWERREGULATOR_ON, the user can optionally configure the 01123 * Flash in power-down monde in setting the RUN_PD bit in FLASH_ACR register. 01124 * Additionally, the clock frequency must be reduced below 2 MHz. 01125 * Setting RUN_PD in FLASH_ACR then appropriately reducing the clock frequency must 01126 * be done before calling HAL_PWREx_EnableLowPowerRunMode() API. 01127 * @retval None 01128 */ 01129 void HAL_PWREx_EnableLowPowerRunMode(void) 01130 { 01131 /* Set Regulator parameter */ 01132 SET_BIT(PWR->CR1, PWR_CR1_LPR); 01133 } 01134 01135 01136 /** 01137 * @brief Exit Low-power Run mode. 01138 * @note Before HAL_PWREx_DisableLowPowerRunMode() completion, the function checks that 01139 * REGLPF has been properly reset (otherwise, HAL_PWREx_DisableLowPowerRunMode 01140 * returns HAL_TIMEOUT status). The system clock frequency can then be 01141 * increased above 2 MHz. 01142 * @retval HAL Status 01143 */ 01144 HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void) 01145 { 01146 uint32_t wait_loop_index; 01147 01148 /* Clear LPR bit */ 01149 CLEAR_BIT(PWR->CR1, PWR_CR1_LPR); 01150 01151 /* Wait until REGLPF is reset */ 01152 wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U; 01153 while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF)) && (wait_loop_index != 0U)) 01154 { 01155 wait_loop_index--; 01156 } 01157 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF)) 01158 { 01159 return HAL_TIMEOUT; 01160 } 01161 01162 return HAL_OK; 01163 } 01164 01165 01166 /** 01167 * @brief Enter Stop 0 mode. 01168 * @note In Stop 0 mode, main and low voltage regulators are ON. 01169 * @note In Stop 0 mode, all I/O pins keep the same state as in Run mode. 01170 * @note All clocks in the VCORE domain are stopped; the PLL, the MSI, 01171 * the HSI and the HSE oscillators are disabled. Some peripherals with the wakeup capability 01172 * (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI 01173 * after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated 01174 * only to the peripheral requesting it. 01175 * SRAM1, SRAM2 and register contents are preserved. 01176 * The BOR is available. 01177 * @note When exiting Stop 0 mode by issuing an interrupt or a wakeup event, 01178 * the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register 01179 * is set; the MSI oscillator is selected if STOPWUCK is cleared. 01180 * @note By keeping the internal regulator ON during Stop 0 mode, the consumption 01181 * is higher although the startup time is reduced. 01182 * @param STOPEntry specifies if Stop mode in entered with WFI or WFE instruction. 01183 * This parameter can be one of the following values: 01184 * @arg @ref PWR_STOPENTRY_WFI Enter Stop mode with WFI instruction 01185 * @arg @ref PWR_STOPENTRY_WFE Enter Stop mode with WFE instruction 01186 * @retval None 01187 */ 01188 void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry) 01189 { 01190 /* Check the parameters */ 01191 assert_param(IS_PWR_STOP_ENTRY(STOPEntry)); 01192 01193 /* Stop 0 mode with Main Regulator */ 01194 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP0); 01195 01196 /* Set SLEEPDEEP bit of Cortex System Control Register */ 01197 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); 01198 01199 /* Select Stop mode entry --------------------------------------------------*/ 01200 if(STOPEntry == PWR_STOPENTRY_WFI) 01201 { 01202 /* Request Wait For Interrupt */ 01203 __WFI(); 01204 } 01205 else 01206 { 01207 /* Request Wait For Event */ 01208 __SEV(); 01209 __WFE(); 01210 __WFE(); 01211 } 01212 01213 /* Reset SLEEPDEEP bit of Cortex System Control Register */ 01214 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); 01215 } 01216 01217 01218 /** 01219 * @brief Enter Stop 1 mode. 01220 * @note In Stop 1 mode, only low power voltage regulator is ON. 01221 * @note In Stop 1 mode, all I/O pins keep the same state as in Run mode. 01222 * @note All clocks in the VCORE domain are stopped; the PLL, the MSI, 01223 * the HSI and the HSE oscillators are disabled. Some peripherals with the wakeup capability 01224 * (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI 01225 * after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated 01226 * only to the peripheral requesting it. 01227 * SRAM1, SRAM2 and register contents are preserved. 01228 * The BOR is available. 01229 * @note When exiting Stop 1 mode by issuing an interrupt or a wakeup event, 01230 * the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register 01231 * is set; the MSI oscillator is selected if STOPWUCK is cleared. 01232 * @note Due to low power mode, an additional startup delay is incurred when waking up from Stop 1 mode. 01233 * @param STOPEntry specifies if Stop mode in entered with WFI or WFE instruction. 01234 * This parameter can be one of the following values: 01235 * @arg @ref PWR_STOPENTRY_WFI Enter Stop mode with WFI instruction 01236 * @arg @ref PWR_STOPENTRY_WFE Enter Stop mode with WFE instruction 01237 * @retval None 01238 */ 01239 void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry) 01240 { 01241 /* Check the parameters */ 01242 assert_param(IS_PWR_STOP_ENTRY(STOPEntry)); 01243 01244 /* Stop 1 mode with Low-Power Regulator */ 01245 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP1); 01246 01247 /* Set SLEEPDEEP bit of Cortex System Control Register */ 01248 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); 01249 01250 /* Select Stop mode entry --------------------------------------------------*/ 01251 if(STOPEntry == PWR_STOPENTRY_WFI) 01252 { 01253 /* Request Wait For Interrupt */ 01254 __WFI(); 01255 } 01256 else 01257 { 01258 /* Request Wait For Event */ 01259 __SEV(); 01260 __WFE(); 01261 __WFE(); 01262 } 01263 01264 /* Reset SLEEPDEEP bit of Cortex System Control Register */ 01265 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); 01266 } 01267 01268 01269 /** 01270 * @brief Enter Stop 2 mode. 01271 * @note In Stop 2 mode, only low power voltage regulator is ON. 01272 * @note In Stop 2 mode, all I/O pins keep the same state as in Run mode. 01273 * @note All clocks in the VCORE domain are stopped, the PLL, the MSI, 01274 * the HSI and the HSE oscillators are disabled. Some peripherals with wakeup capability 01275 * (LCD, LPTIM1, I2C3 and LPUART) can switch on the HSI to receive a frame, and switch off the HSI after 01276 * receiving the frame if it is not a wakeup frame. In this case the HSI clock is propagated only 01277 * to the peripheral requesting it. 01278 * SRAM1, SRAM2 and register contents are preserved. 01279 * SRAM3 content is preserved depending on RRSTP bit setting (not available on all devices). 01280 * The BOR is available. 01281 * The voltage regulator is set in low-power mode but LPR bit must be cleared to enter stop 2 mode. 01282 * Otherwise, Stop 1 mode is entered. 01283 * @note When exiting Stop 2 mode by issuing an interrupt or a wakeup event, 01284 * the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register 01285 * is set; the MSI oscillator is selected if STOPWUCK is cleared. 01286 * @param STOPEntry specifies if Stop mode in entered with WFI or WFE instruction. 01287 * This parameter can be one of the following values: 01288 * @arg @ref PWR_STOPENTRY_WFI Enter Stop mode with WFI instruction 01289 * @arg @ref PWR_STOPENTRY_WFE Enter Stop mode with WFE instruction 01290 * @retval None 01291 */ 01292 void HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry) 01293 { 01294 /* Check the parameter */ 01295 assert_param(IS_PWR_STOP_ENTRY(STOPEntry)); 01296 01297 /* Set Stop mode 2 */ 01298 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP2); 01299 01300 /* Set SLEEPDEEP bit of Cortex System Control Register */ 01301 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); 01302 01303 /* Select Stop mode entry --------------------------------------------------*/ 01304 if(STOPEntry == PWR_STOPENTRY_WFI) 01305 { 01306 /* Request Wait For Interrupt */ 01307 __WFI(); 01308 } 01309 else 01310 { 01311 /* Request Wait For Event */ 01312 __SEV(); 01313 __WFE(); 01314 __WFE(); 01315 } 01316 01317 /* Reset SLEEPDEEP bit of Cortex System Control Register */ 01318 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); 01319 } 01320 01321 01322 01323 01324 01325 /** 01326 * @brief Enter Shutdown mode. 01327 * @note In Shutdown mode, the PLL, the HSI, the MSI, the LSI and the HSE oscillators are switched 01328 * off. The voltage regulator is disabled and Vcore domain is powered off. 01329 * SRAM1, SRAM2 and registers contents are lost except for registers in the Backup domain. 01330 * The BOR is not available. 01331 * @note The I/Os can be configured either with a pull-up or pull-down or can be kept in analog state. 01332 * @retval None 01333 */ 01334 void HAL_PWREx_EnterSHUTDOWNMode(void) 01335 { 01336 01337 /* Set Shutdown mode */ 01338 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_SHUTDOWN); 01339 01340 /* Set SLEEPDEEP bit of Cortex System Control Register */ 01341 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); 01342 01343 /* This option is used to ensure that store operations are completed */ 01344 #if defined ( __CC_ARM) 01345 __force_stores(); 01346 #endif 01347 /* Request Wait For Interrupt */ 01348 __WFI(); 01349 } 01350 01351 01352 01353 01354 /** 01355 * @brief This function handles the PWR PVD/PVMx interrupt request. 01356 * @note This API should be called under the PVD_PVM_IRQHandler(). 01357 * @retval None 01358 */ 01359 void HAL_PWREx_PVD_PVM_IRQHandler(void) 01360 { 01361 /* Check PWR exti flag */ 01362 if(__HAL_PWR_PVD_EXTI_GET_FLAG() != 0x0U) 01363 { 01364 /* PWR PVD interrupt user callback */ 01365 HAL_PWR_PVDCallback(); 01366 01367 /* Clear PVD exti pending bit */ 01368 __HAL_PWR_PVD_EXTI_CLEAR_FLAG(); 01369 } 01370 /* Next, successively check PVMx exti flags */ 01371 #if defined(PWR_CR2_PVME1) 01372 if(__HAL_PWR_PVM1_EXTI_GET_FLAG() != 0x0U) 01373 { 01374 /* PWR PVM1 interrupt user callback */ 01375 HAL_PWREx_PVM1Callback(); 01376 01377 /* Clear PVM1 exti pending bit */ 01378 __HAL_PWR_PVM1_EXTI_CLEAR_FLAG(); 01379 } 01380 #endif /* PWR_CR2_PVME1 */ 01381 #if defined(PWR_CR2_PVME2) 01382 if(__HAL_PWR_PVM2_EXTI_GET_FLAG() != 0x0U) 01383 { 01384 /* PWR PVM2 interrupt user callback */ 01385 HAL_PWREx_PVM2Callback(); 01386 01387 /* Clear PVM2 exti pending bit */ 01388 __HAL_PWR_PVM2_EXTI_CLEAR_FLAG(); 01389 } 01390 #endif /* PWR_CR2_PVME2 */ 01391 if(__HAL_PWR_PVM3_EXTI_GET_FLAG() != 0x0U) 01392 { 01393 /* PWR PVM3 interrupt user callback */ 01394 HAL_PWREx_PVM3Callback(); 01395 01396 /* Clear PVM3 exti pending bit */ 01397 __HAL_PWR_PVM3_EXTI_CLEAR_FLAG(); 01398 } 01399 if(__HAL_PWR_PVM4_EXTI_GET_FLAG() != 0x0U) 01400 { 01401 /* PWR PVM4 interrupt user callback */ 01402 HAL_PWREx_PVM4Callback(); 01403 01404 /* Clear PVM4 exti pending bit */ 01405 __HAL_PWR_PVM4_EXTI_CLEAR_FLAG(); 01406 } 01407 } 01408 01409 01410 #if defined(PWR_CR2_PVME1) 01411 /** 01412 * @brief PWR PVM1 interrupt callback 01413 * @retval None 01414 */ 01415 __weak void HAL_PWREx_PVM1Callback(void) 01416 { 01417 /* NOTE : This function should not be modified; when the callback is needed, 01418 HAL_PWREx_PVM1Callback() API can be implemented in the user file 01419 */ 01420 } 01421 #endif /* PWR_CR2_PVME1 */ 01422 01423 #if defined(PWR_CR2_PVME2) 01424 /** 01425 * @brief PWR PVM2 interrupt callback 01426 * @retval None 01427 */ 01428 __weak void HAL_PWREx_PVM2Callback(void) 01429 { 01430 /* NOTE : This function should not be modified; when the callback is needed, 01431 HAL_PWREx_PVM2Callback() API can be implemented in the user file 01432 */ 01433 } 01434 #endif /* PWR_CR2_PVME2 */ 01435 01436 /** 01437 * @brief PWR PVM3 interrupt callback 01438 * @retval None 01439 */ 01440 __weak void HAL_PWREx_PVM3Callback(void) 01441 { 01442 /* NOTE : This function should not be modified; when the callback is needed, 01443 HAL_PWREx_PVM3Callback() API can be implemented in the user file 01444 */ 01445 } 01446 01447 /** 01448 * @brief PWR PVM4 interrupt callback 01449 * @retval None 01450 */ 01451 __weak void HAL_PWREx_PVM4Callback(void) 01452 { 01453 /* NOTE : This function should not be modified; when the callback is needed, 01454 HAL_PWREx_PVM4Callback() API can be implemented in the user file 01455 */ 01456 } 01457 01458 01459 /** 01460 * @} 01461 */ 01462 01463 /** 01464 * @} 01465 */ 01466 01467 #endif /* HAL_PWR_MODULE_ENABLED */ 01468 /** 01469 * @} 01470 */ 01471 01472 /** 01473 * @} 01474 */