You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1265 lines
39 KiB

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