stm32g4xx_hal_pwr_ex.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_hal_pwr_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended PWR HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Power Controller (PWR) peripheral:
  8. * + Extended Initialization and de-initialization functions
  9. * + Extended Peripheral Control functions
  10. *
  11. ******************************************************************************
  12. * @attention
  13. *
  14. * Copyright (c) 2019 STMicroelectronics.
  15. * All rights reserved.
  16. *
  17. * This software is licensed under terms that can be found in the LICENSE file
  18. * in the root directory of this software component.
  19. * If no LICENSE file comes with this software, it is provided AS-IS.
  20. *
  21. ******************************************************************************
  22. */
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32g4xx_hal.h"
  25. /** @addtogroup STM32G4xx_HAL_Driver
  26. * @{
  27. */
  28. /** @defgroup PWREx PWREx
  29. * @brief PWR Extended HAL module driver
  30. * @{
  31. */
  32. #ifdef HAL_PWR_MODULE_ENABLED
  33. /* Private typedef -----------------------------------------------------------*/
  34. /* Private define ------------------------------------------------------------*/
  35. #if defined (STM32G471xx) || defined (STM32G473xx) || defined (STM32G414xx) || defined (STM32G474xx) || defined (STM32G483xx) || defined (STM32G484xx)
  36. #define PWR_PORTF_AVAILABLE_PINS 0x0000FFFFU /* PF0..PF15 */
  37. #define PWR_PORTG_AVAILABLE_PINS 0x000007FFU /* PG0..PG10 */
  38. #elif defined (STM32G411xB) || defined (STM32G411xC) || defined (STM32G431xx) || defined (STM32G441xx) || defined (STM32GBK1CB) || defined (STM32G491xx) || defined (STM32G4A1xx)
  39. #define PWR_PORTF_AVAILABLE_PINS 0x00000607U /* PF0..PF2 and PF9 and PF10 */
  40. #define PWR_PORTG_AVAILABLE_PINS 0x00000400U /* PG10 */
  41. #endif /* STM32G471xx || STM32G473xx || STM32G414xx || STM32G474xx || STM32G483xx || STM32G484xx */
  42. /** @defgroup PWR_Extended_Private_Defines PWR Extended Private Defines
  43. * @{
  44. */
  45. /** @defgroup PWREx_PVM_Mode_Mask PWR PVM Mode Mask
  46. * @{
  47. */
  48. #define PVM_MODE_IT 0x00010000U /*!< Mask for interruption yielded by PVM threshold crossing */
  49. #define PVM_MODE_EVT 0x00020000U /*!< Mask for event yielded by PVM threshold crossing */
  50. #define PVM_RISING_EDGE 0x00000001U /*!< Mask for rising edge set as PVM trigger */
  51. #define PVM_FALLING_EDGE 0x00000002U /*!< Mask for falling edge set as PVM trigger */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup PWREx_TimeOut_Value PWR Extended Flag Setting Time Out Value
  56. * @{
  57. */
  58. #define PWR_FLAG_SETTING_DELAY_US 50UL /*!< Time out value for REGLPF and VOSF flags setting */
  59. /**
  60. * @}
  61. */
  62. /**
  63. * @}
  64. */
  65. /* Private macro -------------------------------------------------------------*/
  66. /* Private variables ---------------------------------------------------------*/
  67. /* Private function prototypes -----------------------------------------------*/
  68. /* Exported functions --------------------------------------------------------*/
  69. /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
  70. * @{
  71. */
  72. /** @defgroup PWREx_Exported_Functions_Group1 Extended Peripheral Control functions
  73. * @brief Extended Peripheral Control functions
  74. *
  75. @verbatim
  76. ===============================================================================
  77. ##### Extended Peripheral Initialization and de-initialization functions #####
  78. ===============================================================================
  79. [..]
  80. @endverbatim
  81. * @{
  82. */
  83. /**
  84. * @brief Return Voltage Scaling Range.
  85. * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1 or PWR_REGULATOR_VOLTAGE_SCALE2
  86. * or PWR_REGULATOR_VOLTAGE_SCALE1_BOOST when applicable)
  87. */
  88. uint32_t HAL_PWREx_GetVoltageRange(void)
  89. {
  90. if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
  91. {
  92. return PWR_REGULATOR_VOLTAGE_SCALE2;
  93. }
  94. else if (READ_BIT(PWR->CR5, PWR_CR5_R1MODE) == PWR_CR5_R1MODE)
  95. {
  96. /* PWR_CR5_R1MODE bit set means that Range 1 Boost is disabled */
  97. return PWR_REGULATOR_VOLTAGE_SCALE1;
  98. }
  99. else
  100. {
  101. return PWR_REGULATOR_VOLTAGE_SCALE1_BOOST;
  102. }
  103. }
  104. /**
  105. * @brief Configure the main internal regulator output voltage.
  106. * @param VoltageScaling: specifies the regulator output voltage to achieve
  107. * a tradeoff between performance and power consumption.
  108. * This parameter can be one of the following values:
  109. * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1_BOOST when available, Regulator voltage output range 1 boost mode,
  110. * typical output voltage at 1.28 V,
  111. * system frequency up to 170 MHz.
  112. * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1 Regulator voltage output range 1 mode,
  113. * typical output voltage at 1.2 V,
  114. * system frequency up to 150 MHz.
  115. * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE2 Regulator voltage output range 2 mode,
  116. * typical output voltage at 1.0 V,
  117. * system frequency up to 26 MHz.
  118. * @note When moving from Range 1 to Range 2, the system frequency must be decreased to
  119. * a value below 26 MHz before calling HAL_PWREx_ControlVoltageScaling() API.
  120. * When moving from Range 2 to Range 1, the system frequency can be increased to
  121. * a value up to 150 MHz after calling HAL_PWREx_ControlVoltageScaling() API.
  122. * When moving from Range 1 to Boost Mode Range 1, the system frequency can be increased to
  123. * a value up to 170 MHz after calling HAL_PWREx_ControlVoltageScaling() API.
  124. * @note When moving from Range 2 to Range 1, the API waits for VOSF flag to be
  125. * cleared before returning the status. If the flag is not cleared within
  126. * 50 microseconds, HAL_TIMEOUT status is reported.
  127. * @retval HAL Status
  128. */
  129. HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
  130. {
  131. uint32_t wait_loop_index;
  132. assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
  133. if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1_BOOST)
  134. {
  135. /* If current range is range 2 */
  136. if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
  137. {
  138. /* Make sure Range 1 Boost is enabled */
  139. CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);
  140. /* Set Range 1 */
  141. MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
  142. /* Wait until VOSF is cleared */
  143. wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U;
  144. while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))
  145. {
  146. wait_loop_index--;
  147. }
  148. if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
  149. {
  150. return HAL_TIMEOUT;
  151. }
  152. }
  153. /* If current range is range 1 normal or boost mode */
  154. else
  155. {
  156. /* Enable Range 1 Boost (no issue if bit already reset) */
  157. CLEAR_BIT(PWR->CR5, PWR_CR5_R1MODE);
  158. }
  159. }
  160. else if (VoltageScaling == PWR_REGULATOR_VOLTAGE_SCALE1)
  161. {
  162. /* If current range is range 2 */
  163. if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
  164. {
  165. /* Make sure Range 1 Boost is disabled */
  166. SET_BIT(PWR->CR5, PWR_CR5_R1MODE);
  167. /* Set Range 1 */
  168. MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE1);
  169. /* Wait until VOSF is cleared */
  170. wait_loop_index = ((PWR_FLAG_SETTING_DELAY_US * SystemCoreClock) / 1000000U) + 1U;
  171. while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF)) && (wait_loop_index != 0U))
  172. {
  173. wait_loop_index--;
  174. }
  175. if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_VOSF))
  176. {
  177. return HAL_TIMEOUT;
  178. }
  179. }
  180. /* If current range is range 1 normal or boost mode */
  181. else
  182. {
  183. /* Disable Range 1 Boost (no issue if bit already set) */
  184. SET_BIT(PWR->CR5, PWR_CR5_R1MODE);
  185. }
  186. }
  187. else
  188. {
  189. /* Set Range 2 */
  190. MODIFY_REG(PWR->CR1, PWR_CR1_VOS, PWR_REGULATOR_VOLTAGE_SCALE2);
  191. /* No need to wait for VOSF to be cleared for this transition */
  192. /* PWR_CR5_R1MODE bit setting has no effect in Range 2 */
  193. }
  194. return HAL_OK;
  195. }
  196. /**
  197. * @brief Enable battery charging.
  198. * When VDD is present, charge the external battery on VBAT through an internal resistor.
  199. * @param ResistorSelection: specifies the resistor impedance.
  200. * This parameter can be one of the following values:
  201. * @arg @ref PWR_BATTERY_CHARGING_RESISTOR_5 5 kOhms resistor
  202. * @arg @ref PWR_BATTERY_CHARGING_RESISTOR_1_5 1.5 kOhms resistor
  203. * @retval None
  204. */
  205. void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection)
  206. {
  207. assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorSelection));
  208. /* Specify resistor selection */
  209. MODIFY_REG(PWR->CR4, PWR_CR4_VBRS, ResistorSelection);
  210. /* Enable battery charging */
  211. SET_BIT(PWR->CR4, PWR_CR4_VBE);
  212. }
  213. /**
  214. * @brief Disable battery charging.
  215. * @retval None
  216. */
  217. void HAL_PWREx_DisableBatteryCharging(void)
  218. {
  219. CLEAR_BIT(PWR->CR4, PWR_CR4_VBE);
  220. }
  221. /**
  222. * @brief Enable Internal Wake-up Line.
  223. * @retval None
  224. */
  225. void HAL_PWREx_EnableInternalWakeUpLine(void)
  226. {
  227. SET_BIT(PWR->CR3, PWR_CR3_EIWF);
  228. }
  229. /**
  230. * @brief Disable Internal Wake-up Line.
  231. * @retval None
  232. */
  233. void HAL_PWREx_DisableInternalWakeUpLine(void)
  234. {
  235. CLEAR_BIT(PWR->CR3, PWR_CR3_EIWF);
  236. }
  237. /**
  238. * @brief Enable GPIO pull-up state in Standby and Shutdown modes.
  239. * @note Set the relevant PUy bits of PWR_PUCRx register to configure the I/O in
  240. * pull-up state in Standby and Shutdown modes.
  241. * @note This state is effective in Standby and Shutdown modes only if APC bit
  242. * is set through HAL_PWREx_EnablePullUpPullDownConfig() API.
  243. * @note The configuration is lost when exiting the Shutdown mode due to the
  244. * power-on reset, maintained when exiting the Standby mode.
  245. * @note To avoid any conflict at Standby and Shutdown modes exits, the corresponding
  246. * PDy bit of PWR_PDCRx register is cleared unless it is reserved.
  247. * @note Even if a PUy bit to set is reserved, the other PUy bits entered as input
  248. * parameter at the same time are set.
  249. * @param GPIO: Specify the IO port. This parameter can be PWR_GPIO_A, ..., PWR_GPIO_G
  250. * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.
  251. * @param GPIONumber: Specify the I/O pins numbers.
  252. * This parameter can be one of the following values:
  253. * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less
  254. * I/O pins are available) or the logical OR of several of them to set
  255. * several bits for a given port in a single API call.
  256. * @retval HAL Status
  257. */
  258. HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
  259. {
  260. HAL_StatusTypeDef status = HAL_OK;
  261. assert_param(IS_PWR_GPIO(GPIO));
  262. assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
  263. switch (GPIO)
  264. {
  265. case PWR_GPIO_A:
  266. SET_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));
  267. CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));
  268. break;
  269. case PWR_GPIO_B:
  270. SET_BIT(PWR->PUCRB, GPIONumber);
  271. CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
  272. break;
  273. case PWR_GPIO_C:
  274. SET_BIT(PWR->PUCRC, GPIONumber);
  275. CLEAR_BIT(PWR->PDCRC, GPIONumber);
  276. break;
  277. case PWR_GPIO_D:
  278. SET_BIT(PWR->PUCRD, GPIONumber);
  279. CLEAR_BIT(PWR->PDCRD, GPIONumber);
  280. break;
  281. case PWR_GPIO_E:
  282. SET_BIT(PWR->PUCRE, GPIONumber);
  283. CLEAR_BIT(PWR->PDCRE, GPIONumber);
  284. break;
  285. case PWR_GPIO_F:
  286. SET_BIT(PWR->PUCRF, (GPIONumber & PWR_PORTF_AVAILABLE_PINS));
  287. CLEAR_BIT(PWR->PDCRF, (GPIONumber & PWR_PORTF_AVAILABLE_PINS));
  288. break;
  289. case PWR_GPIO_G:
  290. SET_BIT(PWR->PUCRG, (GPIONumber & PWR_PORTG_AVAILABLE_PINS));
  291. CLEAR_BIT(PWR->PDCRG, ((GPIONumber & PWR_PORTG_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_10))));
  292. break;
  293. default:
  294. status = HAL_ERROR;
  295. break;
  296. }
  297. return status;
  298. }
  299. /**
  300. * @brief Disable GPIO pull-up state in Standby mode and Shutdown modes.
  301. * @note Reset the relevant PUy bits of PWR_PUCRx register used to configure the I/O
  302. * in pull-up state in Standby and Shutdown modes.
  303. * @note Even if a PUy bit to reset is reserved, the other PUy bits entered as input
  304. * parameter at the same time are reset.
  305. * @param GPIO: Specifies the IO port. This parameter can be PWR_GPIO_A, ..., PWR_GPIO_G
  306. * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.
  307. * @param GPIONumber: Specify the I/O pins numbers.
  308. * This parameter can be one of the following values:
  309. * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less
  310. * I/O pins are available) or the logical OR of several of them to reset
  311. * several bits for a given port in a single API call.
  312. * @retval HAL Status
  313. */
  314. HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber)
  315. {
  316. HAL_StatusTypeDef status = HAL_OK;
  317. assert_param(IS_PWR_GPIO(GPIO));
  318. assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
  319. switch (GPIO)
  320. {
  321. case PWR_GPIO_A:
  322. CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));
  323. break;
  324. case PWR_GPIO_B:
  325. CLEAR_BIT(PWR->PUCRB, GPIONumber);
  326. break;
  327. case PWR_GPIO_C:
  328. CLEAR_BIT(PWR->PUCRC, GPIONumber);
  329. break;
  330. case PWR_GPIO_D:
  331. CLEAR_BIT(PWR->PUCRD, GPIONumber);
  332. break;
  333. case PWR_GPIO_E:
  334. CLEAR_BIT(PWR->PUCRE, GPIONumber);
  335. break;
  336. case PWR_GPIO_F:
  337. CLEAR_BIT(PWR->PUCRF, (GPIONumber & PWR_PORTF_AVAILABLE_PINS));
  338. break;
  339. case PWR_GPIO_G:
  340. CLEAR_BIT(PWR->PUCRG, (GPIONumber & PWR_PORTG_AVAILABLE_PINS));
  341. break;
  342. default:
  343. status = HAL_ERROR;
  344. break;
  345. }
  346. return status;
  347. }
  348. /**
  349. * @brief Enable GPIO pull-down state in Standby and Shutdown modes.
  350. * @note Set the relevant PDy bits of PWR_PDCRx register to configure the I/O in
  351. * pull-down state in Standby and Shutdown modes.
  352. * @note This state is effective in Standby and Shutdown modes only if APC bit
  353. * is set through HAL_PWREx_EnablePullUpPullDownConfig() API.
  354. * @note The configuration is lost when exiting the Shutdown mode due to the
  355. * power-on reset, maintained when exiting the Standby mode.
  356. * @note To avoid any conflict at Standby and Shutdown modes exits, the corresponding
  357. * PUy bit of PWR_PUCRx register is cleared unless it is reserved.
  358. * @note Even if a PDy bit to set is reserved, the other PDy bits entered as input
  359. * parameter at the same time are set.
  360. * @param GPIO: Specify the IO port. This parameter can be PWR_GPIO_A..PWR_GPIO_G
  361. * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.
  362. * @param GPIONumber: Specify the I/O pins numbers.
  363. * This parameter can be one of the following values:
  364. * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less
  365. * I/O pins are available) or the logical OR of several of them to set
  366. * several bits for a given port in a single API call.
  367. * @retval HAL Status
  368. */
  369. HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
  370. {
  371. HAL_StatusTypeDef status = HAL_OK;
  372. assert_param(IS_PWR_GPIO(GPIO));
  373. assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
  374. switch (GPIO)
  375. {
  376. case PWR_GPIO_A:
  377. SET_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));
  378. CLEAR_BIT(PWR->PUCRA, (GPIONumber & (~(PWR_GPIO_BIT_14))));
  379. break;
  380. case PWR_GPIO_B:
  381. SET_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
  382. CLEAR_BIT(PWR->PUCRB, GPIONumber);
  383. break;
  384. case PWR_GPIO_C:
  385. SET_BIT(PWR->PDCRC, GPIONumber);
  386. CLEAR_BIT(PWR->PUCRC, GPIONumber);
  387. break;
  388. case PWR_GPIO_D:
  389. SET_BIT(PWR->PDCRD, GPIONumber);
  390. CLEAR_BIT(PWR->PUCRD, GPIONumber);
  391. break;
  392. case PWR_GPIO_E:
  393. SET_BIT(PWR->PDCRE, GPIONumber);
  394. CLEAR_BIT(PWR->PUCRE, GPIONumber);
  395. break;
  396. case PWR_GPIO_F:
  397. SET_BIT(PWR->PDCRF, (GPIONumber & PWR_PORTF_AVAILABLE_PINS));
  398. CLEAR_BIT(PWR->PUCRF, (GPIONumber & PWR_PORTF_AVAILABLE_PINS));
  399. break;
  400. case PWR_GPIO_G:
  401. SET_BIT(PWR->PDCRG, ((GPIONumber & PWR_PORTG_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_10))));
  402. CLEAR_BIT(PWR->PUCRG, (GPIONumber & PWR_PORTG_AVAILABLE_PINS));
  403. break;
  404. default:
  405. status = HAL_ERROR;
  406. break;
  407. }
  408. return status;
  409. }
  410. /**
  411. * @brief Disable GPIO pull-down state in Standby and Shutdown modes.
  412. * @note Reset the relevant PDy bits of PWR_PDCRx register used to configure the I/O
  413. * in pull-down state in Standby and Shutdown modes.
  414. * @note Even if a PDy bit to reset is reserved, the other PDy bits entered as input
  415. * parameter at the same time are reset.
  416. * @param GPIO: Specifies the IO port. This parameter can be PWR_GPIO_A..PWR_GPIO_G
  417. * (or PWR_GPIO_I depending on the devices) to select the GPIO peripheral.
  418. * @param GPIONumber: Specify the I/O pins numbers.
  419. * This parameter can be one of the following values:
  420. * PWR_GPIO_BIT_0, ..., PWR_GPIO_BIT_15 (except for the port where less
  421. * I/O pins are available) or the logical OR of several of them to reset
  422. * several bits for a given port in a single API call.
  423. * @retval HAL Status
  424. */
  425. HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber)
  426. {
  427. HAL_StatusTypeDef status = HAL_OK;
  428. assert_param(IS_PWR_GPIO(GPIO));
  429. assert_param(IS_PWR_GPIO_BIT_NUMBER(GPIONumber));
  430. switch (GPIO)
  431. {
  432. case PWR_GPIO_A:
  433. CLEAR_BIT(PWR->PDCRA, (GPIONumber & (~(PWR_GPIO_BIT_13|PWR_GPIO_BIT_15))));
  434. break;
  435. case PWR_GPIO_B:
  436. CLEAR_BIT(PWR->PDCRB, (GPIONumber & (~(PWR_GPIO_BIT_4))));
  437. break;
  438. case PWR_GPIO_C:
  439. CLEAR_BIT(PWR->PDCRC, GPIONumber);
  440. break;
  441. case PWR_GPIO_D:
  442. CLEAR_BIT(PWR->PDCRD, GPIONumber);
  443. break;
  444. case PWR_GPIO_E:
  445. CLEAR_BIT(PWR->PDCRE, GPIONumber);
  446. break;
  447. case PWR_GPIO_F:
  448. CLEAR_BIT(PWR->PDCRF, (GPIONumber & PWR_PORTF_AVAILABLE_PINS));
  449. break;
  450. case PWR_GPIO_G:
  451. CLEAR_BIT(PWR->PDCRG, ((GPIONumber & PWR_PORTG_AVAILABLE_PINS) & (~(PWR_GPIO_BIT_10))));
  452. break;
  453. default:
  454. status = HAL_ERROR;
  455. break;
  456. }
  457. return status;
  458. }
  459. /**
  460. * @brief Enable pull-up and pull-down configuration.
  461. * @note When APC bit is set, the I/O pull-up and pull-down configurations defined in
  462. * PWR_PUCRx and PWR_PDCRx registers are applied in Standby and Shutdown modes.
  463. * @note Pull-up set by PUy bit of PWR_PUCRx register is not activated if the corresponding
  464. * PDy bit of PWR_PDCRx register is also set (pull-down configuration priority is higher).
  465. * HAL_PWREx_EnableGPIOPullUp() and HAL_PWREx_EnableGPIOPullDown() API's ensure there
  466. * is no conflict when setting PUy or PDy bit.
  467. * @retval None
  468. */
  469. void HAL_PWREx_EnablePullUpPullDownConfig(void)
  470. {
  471. SET_BIT(PWR->CR3, PWR_CR3_APC);
  472. }
  473. /**
  474. * @brief Disable pull-up and pull-down configuration.
  475. * @note When APC bit is cleared, the I/O pull-up and pull-down configurations defined in
  476. * PWR_PUCRx and PWR_PDCRx registers are not applied in Standby and Shutdown modes.
  477. * @retval None
  478. */
  479. void HAL_PWREx_DisablePullUpPullDownConfig(void)
  480. {
  481. CLEAR_BIT(PWR->CR3, PWR_CR3_APC);
  482. }
  483. #if defined (SRAM2_BASE)
  484. /**
  485. * @brief Enable SRAM2 content retention in Standby mode.
  486. * @note When RRS bit is set, SRAM2 is powered by the low-power regulator in
  487. * Standby mode and its content is kept.
  488. * @retval None
  489. */
  490. void HAL_PWREx_EnableSRAM2ContentRetention(void)
  491. {
  492. SET_BIT(PWR->CR3, PWR_CR3_RRS);
  493. }
  494. /**
  495. * @brief Disable SRAM2 content retention in Standby mode.
  496. * @note When RRS bit is reset, SRAM2 is powered off in Standby mode
  497. * and its content is lost.
  498. * @retval None
  499. */
  500. void HAL_PWREx_DisableSRAM2ContentRetention(void)
  501. {
  502. CLEAR_BIT(PWR->CR3, PWR_CR3_RRS);
  503. }
  504. #endif /* SRAM2_BASE */
  505. #if defined(PWR_CR2_PVME1)
  506. /**
  507. * @brief Enable the Power Voltage Monitoring 1: VDDA versus FASTCOMP minimum voltage.
  508. * @retval None
  509. */
  510. void HAL_PWREx_EnablePVM1(void)
  511. {
  512. SET_BIT(PWR->CR2, PWR_PVM_1);
  513. }
  514. /**
  515. * @brief Disable the Power Voltage Monitoring 1: VDDA versus FASTCOMP minimum voltage.
  516. * @retval None
  517. */
  518. void HAL_PWREx_DisablePVM1(void)
  519. {
  520. CLEAR_BIT(PWR->CR2, PWR_PVM_1);
  521. }
  522. #endif /* PWR_CR2_PVME1 */
  523. #if defined(PWR_CR2_PVME2)
  524. /**
  525. * @brief Enable the Power Voltage Monitoring 2: VDDA versus FASTDAC minimum voltage.
  526. * @retval None
  527. */
  528. void HAL_PWREx_EnablePVM2(void)
  529. {
  530. SET_BIT(PWR->CR2, PWR_PVM_2);
  531. }
  532. /**
  533. * @brief Disable the Power Voltage Monitoring 2: VDDA versus FASTDAC minimum voltage.
  534. * @retval None
  535. */
  536. void HAL_PWREx_DisablePVM2(void)
  537. {
  538. CLEAR_BIT(PWR->CR2, PWR_PVM_2);
  539. }
  540. #endif /* PWR_CR2_PVME2 */
  541. /**
  542. * @brief Enable the Power Voltage Monitoring 3: VDDA versus ADC minimum voltage 1.62V.
  543. * @retval None
  544. */
  545. void HAL_PWREx_EnablePVM3(void)
  546. {
  547. SET_BIT(PWR->CR2, PWR_PVM_3);
  548. }
  549. /**
  550. * @brief Disable the Power Voltage Monitoring 3: VDDA versus ADC minimum voltage 1.62V.
  551. * @retval None
  552. */
  553. void HAL_PWREx_DisablePVM3(void)
  554. {
  555. CLEAR_BIT(PWR->CR2, PWR_PVM_3);
  556. }
  557. /**
  558. * @brief Enable the Power Voltage Monitoring 4: VDDA versus OPAMP/DAC minimum voltage 1.8V.
  559. * @retval None
  560. */
  561. void HAL_PWREx_EnablePVM4(void)
  562. {
  563. SET_BIT(PWR->CR2, PWR_PVM_4);
  564. }
  565. /**
  566. * @brief Disable the Power Voltage Monitoring 4: VDDA versus OPAMP/DAC minimum voltage 1.8V.
  567. * @retval None
  568. */
  569. void HAL_PWREx_DisablePVM4(void)
  570. {
  571. CLEAR_BIT(PWR->CR2, PWR_PVM_4);
  572. }
  573. /**
  574. * @brief Configure the Peripheral Voltage Monitoring (PVM).
  575. * @param sConfigPVM: pointer to a PWR_PVMTypeDef structure that contains the
  576. * PVM configuration information.
  577. * @note The API configures a single PVM according to the information contained
  578. * in the input structure. To configure several PVMs, the API must be singly
  579. * called for each PVM used.
  580. * @note Refer to the electrical characteristics of your device datasheet for
  581. * more details about the voltage thresholds corresponding to each
  582. * detection level and to each monitored supply.
  583. * @retval HAL status
  584. */
  585. HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM)
  586. {
  587. HAL_StatusTypeDef status = HAL_OK;
  588. /* Check the parameters */
  589. assert_param(IS_PWR_PVM_TYPE(sConfigPVM->PVMType));
  590. assert_param(IS_PWR_PVM_MODE(sConfigPVM->Mode));
  591. /* Configure EXTI 35 to 38 interrupts if so required:
  592. scan through PVMType to detect which PVMx is set and
  593. configure the corresponding EXTI line accordingly. */
  594. switch (sConfigPVM->PVMType)
  595. {
  596. #if defined(PWR_CR2_PVME1)
  597. case PWR_PVM_1:
  598. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  599. __HAL_PWR_PVM1_EXTI_DISABLE_EVENT();
  600. __HAL_PWR_PVM1_EXTI_DISABLE_IT();
  601. __HAL_PWR_PVM1_EXTI_DISABLE_FALLING_EDGE();
  602. __HAL_PWR_PVM1_EXTI_DISABLE_RISING_EDGE();
  603. /* Configure interrupt mode */
  604. if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
  605. {
  606. __HAL_PWR_PVM1_EXTI_ENABLE_IT();
  607. }
  608. /* Configure event mode */
  609. if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
  610. {
  611. __HAL_PWR_PVM1_EXTI_ENABLE_EVENT();
  612. }
  613. /* Configure the edge */
  614. if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
  615. {
  616. __HAL_PWR_PVM1_EXTI_ENABLE_RISING_EDGE();
  617. }
  618. if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
  619. {
  620. __HAL_PWR_PVM1_EXTI_ENABLE_FALLING_EDGE();
  621. }
  622. break;
  623. #endif /* PWR_CR2_PVME1 */
  624. #if defined(PWR_CR2_PVME2)
  625. case PWR_PVM_2:
  626. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  627. __HAL_PWR_PVM2_EXTI_DISABLE_EVENT();
  628. __HAL_PWR_PVM2_EXTI_DISABLE_IT();
  629. __HAL_PWR_PVM2_EXTI_DISABLE_FALLING_EDGE();
  630. __HAL_PWR_PVM2_EXTI_DISABLE_RISING_EDGE();
  631. /* Configure interrupt mode */
  632. if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
  633. {
  634. __HAL_PWR_PVM2_EXTI_ENABLE_IT();
  635. }
  636. /* Configure event mode */
  637. if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
  638. {
  639. __HAL_PWR_PVM2_EXTI_ENABLE_EVENT();
  640. }
  641. /* Configure the edge */
  642. if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
  643. {
  644. __HAL_PWR_PVM2_EXTI_ENABLE_RISING_EDGE();
  645. }
  646. if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
  647. {
  648. __HAL_PWR_PVM2_EXTI_ENABLE_FALLING_EDGE();
  649. }
  650. break;
  651. #endif /* PWR_CR2_PVME2 */
  652. case PWR_PVM_3:
  653. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  654. __HAL_PWR_PVM3_EXTI_DISABLE_EVENT();
  655. __HAL_PWR_PVM3_EXTI_DISABLE_IT();
  656. __HAL_PWR_PVM3_EXTI_DISABLE_FALLING_EDGE();
  657. __HAL_PWR_PVM3_EXTI_DISABLE_RISING_EDGE();
  658. /* Configure interrupt mode */
  659. if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
  660. {
  661. __HAL_PWR_PVM3_EXTI_ENABLE_IT();
  662. }
  663. /* Configure event mode */
  664. if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
  665. {
  666. __HAL_PWR_PVM3_EXTI_ENABLE_EVENT();
  667. }
  668. /* Configure the edge */
  669. if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
  670. {
  671. __HAL_PWR_PVM3_EXTI_ENABLE_RISING_EDGE();
  672. }
  673. if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
  674. {
  675. __HAL_PWR_PVM3_EXTI_ENABLE_FALLING_EDGE();
  676. }
  677. break;
  678. case PWR_PVM_4:
  679. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  680. __HAL_PWR_PVM4_EXTI_DISABLE_EVENT();
  681. __HAL_PWR_PVM4_EXTI_DISABLE_IT();
  682. __HAL_PWR_PVM4_EXTI_DISABLE_FALLING_EDGE();
  683. __HAL_PWR_PVM4_EXTI_DISABLE_RISING_EDGE();
  684. /* Configure interrupt mode */
  685. if((sConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
  686. {
  687. __HAL_PWR_PVM4_EXTI_ENABLE_IT();
  688. }
  689. /* Configure event mode */
  690. if((sConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
  691. {
  692. __HAL_PWR_PVM4_EXTI_ENABLE_EVENT();
  693. }
  694. /* Configure the edge */
  695. if((sConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
  696. {
  697. __HAL_PWR_PVM4_EXTI_ENABLE_RISING_EDGE();
  698. }
  699. if((sConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
  700. {
  701. __HAL_PWR_PVM4_EXTI_ENABLE_FALLING_EDGE();
  702. }
  703. break;
  704. default:
  705. status = HAL_ERROR;
  706. break;
  707. }
  708. return status;
  709. }
  710. /**
  711. * @brief Enter Low-power Run mode
  712. * @note In Low-power Run mode, all I/O pins keep the same state as in Run mode.
  713. * @note When Regulator is set to PWR_LOWPOWERREGULATOR_ON, the user can optionally configure the
  714. * Flash in power-down monde in setting the RUN_PD bit in FLASH_ACR register.
  715. * Additionally, the clock frequency must be reduced below 2 MHz.
  716. * Setting RUN_PD in FLASH_ACR then appropriately reducing the clock frequency must
  717. * be done before calling HAL_PWREx_EnableLowPowerRunMode() API.
  718. * @retval None
  719. */
  720. void HAL_PWREx_EnableLowPowerRunMode(void)
  721. {
  722. /* Set Regulator parameter */
  723. SET_BIT(PWR->CR1, PWR_CR1_LPR);
  724. }
  725. /**
  726. * @brief Exit Low-power Run mode.
  727. * @note Before HAL_PWREx_DisableLowPowerRunMode() completion, the function checks that
  728. * REGLPF has been properly reset (otherwise, HAL_PWREx_DisableLowPowerRunMode
  729. * returns HAL_TIMEOUT status). The system clock frequency can then be
  730. * increased above 2 MHz.
  731. * @retval HAL Status
  732. */
  733. HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
  734. {
  735. uint32_t wait_loop_index;
  736. /* Clear LPR bit */
  737. CLEAR_BIT(PWR->CR1, PWR_CR1_LPR);
  738. /* Wait until REGLPF is reset */
  739. wait_loop_index = (PWR_FLAG_SETTING_DELAY_US * (SystemCoreClock / 1000000U));
  740. while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF)) && (wait_loop_index != 0U))
  741. {
  742. wait_loop_index--;
  743. }
  744. if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))
  745. {
  746. return HAL_TIMEOUT;
  747. }
  748. return HAL_OK;
  749. }
  750. /**
  751. * @brief Enter Stop 0 mode.
  752. * @note In Stop 0 mode, main and low voltage regulators are ON.
  753. * @note In Stop 0 mode, all I/O pins keep the same state as in Run mode.
  754. * @note All clocks in the VCORE domain are stopped; the PLL, the HSI
  755. * and the HSE oscillators are disabled. Some peripherals with the wakeup capability
  756. * (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI
  757. * after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated
  758. * only to the peripheral requesting it.
  759. * SRAM1, SRAM2 and register contents are preserved.
  760. * The BOR is available.
  761. * @note When exiting Stop 0 mode by issuing an interrupt or a wakeup event,
  762. * the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register
  763. * is set; the HSI oscillator is selected if STOPWUCK is cleared.
  764. * @note By keeping the internal regulator ON during Stop 0 mode, the consumption
  765. * is higher although the startup time is reduced.
  766. * @param STOPEntry specifies if Stop mode in entered with WFI or WFE instruction.
  767. * This parameter can be one of the following values:
  768. * @arg @ref PWR_STOPENTRY_WFI Enter Stop mode with WFI instruction
  769. * @arg @ref PWR_STOPENTRY_WFE Enter Stop mode with WFE instruction
  770. * @retval None
  771. */
  772. void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry)
  773. {
  774. /* Check the parameters */
  775. assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
  776. /* Stop 0 mode with Main Regulator */
  777. MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP0);
  778. /* Set SLEEPDEEP bit of Cortex System Control Register */
  779. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  780. /* Select Stop mode entry --------------------------------------------------*/
  781. if(STOPEntry == PWR_STOPENTRY_WFI)
  782. {
  783. /* Request Wait For Interrupt */
  784. __WFI();
  785. }
  786. else
  787. {
  788. /* Request Wait For Event */
  789. __SEV();
  790. __WFE();
  791. __WFE();
  792. }
  793. /* Reset SLEEPDEEP bit of Cortex System Control Register */
  794. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  795. }
  796. /**
  797. * @brief Enter Stop 1 mode.
  798. * @note In Stop 1 mode, only low power voltage regulator is ON.
  799. * @note In Stop 1 mode, all I/O pins keep the same state as in Run mode.
  800. * @note All clocks in the VCORE domain are stopped; the PLL, the HSI
  801. * and the HSE oscillators are disabled. Some peripherals with the wakeup capability
  802. * (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI
  803. * after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated
  804. * only to the peripheral requesting it.
  805. * SRAM1, SRAM2 and register contents are preserved.
  806. * The BOR is available.
  807. * @note When exiting Stop 1 mode by issuing an interrupt or a wakeup event,
  808. * the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register
  809. * is set.
  810. * @note Due to low power mode, an additional startup delay is incurred when waking up from Stop 1 mode.
  811. * @param STOPEntry specifies if Stop mode in entered with WFI or WFE instruction.
  812. * This parameter can be one of the following values:
  813. * @arg @ref PWR_STOPENTRY_WFI Enter Stop mode with WFI instruction
  814. * @arg @ref PWR_STOPENTRY_WFE Enter Stop mode with WFE instruction
  815. * @retval None
  816. */
  817. void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)
  818. {
  819. /* Check the parameters */
  820. assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
  821. /* Stop 1 mode with Low-Power Regulator */
  822. MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STOP1);
  823. /* Set SLEEPDEEP bit of Cortex System Control Register */
  824. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  825. /* Select Stop mode entry --------------------------------------------------*/
  826. if(STOPEntry == PWR_STOPENTRY_WFI)
  827. {
  828. /* Request Wait For Interrupt */
  829. __WFI();
  830. }
  831. else
  832. {
  833. /* Request Wait For Event */
  834. __SEV();
  835. __WFE();
  836. __WFE();
  837. }
  838. /* Reset SLEEPDEEP bit of Cortex System Control Register */
  839. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  840. }
  841. /**
  842. * @brief Enter Shutdown mode.
  843. * @note In Shutdown mode, the PLL, the HSI, the LSI and the HSE oscillators are switched
  844. * off. The voltage regulator is disabled and Vcore domain is powered off.
  845. * SRAM1, SRAM2 and registers contents are lost except for registers in the Backup domain.
  846. * The BOR is not available.
  847. * @note The I/Os can be configured either with a pull-up or pull-down or can be kept in analog state.
  848. * @retval None
  849. */
  850. void HAL_PWREx_EnterSHUTDOWNMode(void)
  851. {
  852. /* Set Shutdown mode */
  853. MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_SHUTDOWN);
  854. /* Set SLEEPDEEP bit of Cortex System Control Register */
  855. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  856. /* This option is used to ensure that store operations are completed */
  857. #if defined ( __CC_ARM)
  858. __force_stores();
  859. #endif
  860. /* Request Wait For Interrupt */
  861. __WFI();
  862. }
  863. /**
  864. * @brief This function handles the PWR PVD/PVMx interrupt request.
  865. * @note This API should be called under the PVD_PVM_IRQHandler().
  866. * @retval None
  867. */
  868. void HAL_PWREx_PVD_PVM_IRQHandler(void)
  869. {
  870. /* Check PWR exti flag */
  871. if(__HAL_PWR_PVD_EXTI_GET_FLAG() != 0U)
  872. {
  873. /* PWR PVD interrupt user callback */
  874. HAL_PWR_PVDCallback();
  875. /* Clear PVD exti pending bit */
  876. __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
  877. }
  878. /* Next, successively check PVMx exti flags */
  879. #if defined(PWR_CR2_PVME1)
  880. if(__HAL_PWR_PVM1_EXTI_GET_FLAG() != 0U)
  881. {
  882. /* PWR PVM1 interrupt user callback */
  883. HAL_PWREx_PVM1Callback();
  884. /* Clear PVM1 exti pending bit */
  885. __HAL_PWR_PVM1_EXTI_CLEAR_FLAG();
  886. }
  887. #endif /* PWR_CR2_PVME1 */
  888. #if defined(PWR_CR2_PVME2)
  889. if(__HAL_PWR_PVM2_EXTI_GET_FLAG() != 0U)
  890. {
  891. /* PWR PVM2 interrupt user callback */
  892. HAL_PWREx_PVM2Callback();
  893. /* Clear PVM2 exti pending bit */
  894. __HAL_PWR_PVM2_EXTI_CLEAR_FLAG();
  895. }
  896. #endif /* PWR_CR2_PVME2 */
  897. if(__HAL_PWR_PVM3_EXTI_GET_FLAG() != 0U)
  898. {
  899. /* PWR PVM3 interrupt user callback */
  900. HAL_PWREx_PVM3Callback();
  901. /* Clear PVM3 exti pending bit */
  902. __HAL_PWR_PVM3_EXTI_CLEAR_FLAG();
  903. }
  904. if(__HAL_PWR_PVM4_EXTI_GET_FLAG() != 0U)
  905. {
  906. /* PWR PVM4 interrupt user callback */
  907. HAL_PWREx_PVM4Callback();
  908. /* Clear PVM4 exti pending bit */
  909. __HAL_PWR_PVM4_EXTI_CLEAR_FLAG();
  910. }
  911. }
  912. #if defined(PWR_CR2_PVME1)
  913. /**
  914. * @brief PWR PVM1 interrupt callback
  915. * @retval None
  916. */
  917. __weak void HAL_PWREx_PVM1Callback(void)
  918. {
  919. /* NOTE : This function should not be modified; when the callback is needed,
  920. HAL_PWREx_PVM1Callback() API can be implemented in the user file
  921. */
  922. }
  923. #endif /* PWR_CR2_PVME1 */
  924. #if defined(PWR_CR2_PVME2)
  925. /**
  926. * @brief PWR PVM2 interrupt callback
  927. * @retval None
  928. */
  929. __weak void HAL_PWREx_PVM2Callback(void)
  930. {
  931. /* NOTE : This function should not be modified; when the callback is needed,
  932. HAL_PWREx_PVM2Callback() API can be implemented in the user file
  933. */
  934. }
  935. #endif /* PWR_CR2_PVME2 */
  936. /**
  937. * @brief PWR PVM3 interrupt callback
  938. * @retval None
  939. */
  940. __weak void HAL_PWREx_PVM3Callback(void)
  941. {
  942. /* NOTE : This function should not be modified; when the callback is needed,
  943. HAL_PWREx_PVM3Callback() API can be implemented in the user file
  944. */
  945. }
  946. /**
  947. * @brief PWR PVM4 interrupt callback
  948. * @retval None
  949. */
  950. __weak void HAL_PWREx_PVM4Callback(void)
  951. {
  952. /* NOTE : This function should not be modified; when the callback is needed,
  953. HAL_PWREx_PVM4Callback() API can be implemented in the user file
  954. */
  955. }
  956. #if defined(PWR_CR3_UCPD_STDBY)
  957. /**
  958. * @brief Enable UCPD configuration memorization in Standby.
  959. * @retval None
  960. */
  961. void HAL_PWREx_EnableUCPDStandbyMode(void)
  962. {
  963. /* Memorize UCPD configuration when entering standby mode */
  964. SET_BIT(PWR->CR3, PWR_CR3_UCPD_STDBY);
  965. }
  966. /**
  967. * @brief Disable UCPD configuration memorization in Standby.
  968. * @note This function must be called on exiting the Standby mode and before any UCPD
  969. * configuration update.
  970. * @retval None
  971. */
  972. void HAL_PWREx_DisableUCPDStandbyMode(void)
  973. {
  974. /* Write 0 immediately after Standby exit when using UCPD,
  975. and before writing any UCPD registers */
  976. CLEAR_BIT(PWR->CR3, PWR_CR3_UCPD_STDBY);
  977. }
  978. #endif /* PWR_CR3_UCPD_STDBY */
  979. #if defined(PWR_CR3_UCPD_DBDIS)
  980. /**
  981. * @brief Enable the USB Type-C dead battery pull-down behavior
  982. * on UCPDx_CC1 and UCPDx_CC2 pins
  983. * @retval None
  984. */
  985. void HAL_PWREx_EnableUCPDDeadBattery(void)
  986. {
  987. /* Write 0 to enable the USB Type-C dead battery pull-down behavior */
  988. CLEAR_BIT(PWR->CR3, PWR_CR3_UCPD_DBDIS);
  989. }
  990. /**
  991. * @brief Disable the USB Type-C dead battery pull-down behavior
  992. * on UCPDx_CC1 and UCPDx_CC2 pins
  993. * @note After exiting reset, the USB Type-C dead battery behavior will be enabled,
  994. * which may have a pull-down effect on CC1 and CC2 pins.
  995. * It is recommended to disable it in all cases, either to stop this pull-down
  996. * or to hand over control to the UCPD (which should therefore be
  997. * initialized before doing the disable).
  998. * @retval None
  999. */
  1000. void HAL_PWREx_DisableUCPDDeadBattery(void)
  1001. {
  1002. /* Write 1 to disable the USB Type-C dead battery pull-down behavior */
  1003. SET_BIT(PWR->CR3, PWR_CR3_UCPD_DBDIS);
  1004. }
  1005. #endif /* PWR_CR3_UCPD_DBDIS */
  1006. /**
  1007. * @}
  1008. */
  1009. /**
  1010. * @}
  1011. */
  1012. #endif /* HAL_PWR_MODULE_ENABLED */
  1013. /**
  1014. * @}
  1015. */
  1016. /**
  1017. * @}
  1018. */