1 /**
2 ******************************************************************************
3 * @file stm32u5xx_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 extension peripheral :
8 * + Power Supply Control Functions
9 * + Low Power Control Functions
10 * + Voltage Monitoring Functions
11 * + Memories Retention Functions
12 * + I/O Pull-Up Pull-Down Configuration Functions
13 *
14 ******************************************************************************
15 * @attention
16 *
17 * Copyright (c) 2021 STMicroelectronics.
18 * All rights reserved.
19 *
20 * This software is licensed under terms that can be found in the LICENSE file
21 * in the root directory of this software component.
22 * If no LICENSE file comes with this software, it is provided AS-IS.
23 *
24 ******************************************************************************
25 @verbatim
26 ==============================================================================
27 ##### How to use this driver #####
28 ==============================================================================
29 [..]
30 (#) Call HAL_PWREx_ControlVoltageScaling() and HAL_PWREx_GetVoltageRange() to
31 set / get the voltage scaling range.
32 (+) Voltage scaling can be one of the following values :
33 (++) voltage output scale 1 : 1V2
34 => Used when system clock frequency is up to 160 MHz
35 (++) voltage output scale 2 : 1V1
36 => Used when system clock frequency is up to 100 MHz
37 (++) voltage output scale 3 : 1V0
38 => Used when system clock frequency is up to 50 MHz
39 (++) voltage output scale 4 : 0V9
40 => Used when system clock frequency is up to 24 MHz
41
42 (#) Call HAL_PWREx_EnableFastSoftStart() and HAL_PWREx_DisableFastSoftStart()
43 to enable / disable the fast software startup for the current regulator.
44
45 (#) Call HAL_PWREx_EnterSTOP1Mode() function to enter the whole system to
46 Stop 1 mode. Wake-up from Stop 1 mode could be following to an event or
47 an interrupt according to low power mode intrinsic request called
48 (__WFI() or __WFE()). (Regulator state on U5 devices is managed
49 internally but regulator parameter is kept for product compatibility).
50
51 (#) Call HAL_PWREx_EnterSTOP2Mode() function to enter the whole system to
52 Stop 2 mode. Wake-up from Stop 2 mode could be following to an event or
53 an interrupt according to low power mode intrinsic request called
54 (__WFI() or __WFE()). (Regulator state on U5 devices is managed
55 internally but regulator parameter is kept for product compatibility).
56
57 (#) Call HAL_PWREx_EnterSTOP3Mode() function to enter the whole system to
58 Stop 3 mode. Wake-up from Stop 3 mode could be following to an event or
59 an interrupt according to low power mode intrinsic request called
60 (__WFI() or __WFE()). (Regulator state on U5 devices is managed
61 internally but regulator parameter is kept for product compatibility).
62
63 (#) Call HAL_PWREx_EnterSHUTDOWNMode() function to enter the whole system in
64 Shutdown mode. Wake-up from Shutdown mode can be following to an external
65 reset (NRST pin), a WKUP pin event (configurable rising or falling edge),
66 or an RTC event occurs (alarm, periodic wakeup, timestamp), or a tamper
67 detection.
68
69 (#) Call HAL_PWREx_ConfigSRDDomain() to force in Run mode or to enter in Stop
70 mode Smart Run Domain when the system enters Stop mode (Stop 0/1/2).
71
72 (#) Call HAL_PWREx_EnableUltraLowPowerMode() and
73 HAL_PWREx_DisableUltraLowPowerMode() to enable / disable the BOR ultra
74 low power mode.
75
76 (#) Call HAL_PWREx_S3WU_IRQHandler() function to handle the PWR Stop 3 wake
77 up interrupt request.
78
79 (#) Call HAL_PWREx_EnableBatteryCharging() and
80 HAL_PWREx_DisableBatteryCharging() to enable / disable the battery
81 charging capability when VDD alimentation is available.
82
83 (#) Call HAL_PWREx_EnableVddUSB(), HAL_PWREx_EnableVddIO2() and
84 HAL_PWREx_EnableVddA() to enable respectively VDDUSB, VDDIO2 and VDDA
85 electrical and logical isolation.
86 It is recommended to disable VDDUSB, VDDIO2 and VDDA electrical and
87 logical isolation through HAL_PWREx_DisableVddUSB(),
88 HAL_PWREx_DisableVddIO2() and HAL_PWREx_DisableVddA().
89
90 (#) Call HAL_PWREx_ConfigPVM() after setting parameters to be configured
91 (event mode and PVD type) in order to set up the Peripheral Voltage
92 Monitor, then use HAL_PWREx_EnableUVM(), HAL_PWREx_EnableIO2VM(),
93 HAL_PWREx_EnableAVM1() and HAL_PWREx_EnableAVM2() functions to start the
94 PVM VDDx monitoring and use HAL_PWREx_DisableUVM(),
95 HAL_PWREx_DisableIO2VM(), HAL_PWREx_DisableAVM1() and
96 HAL_PWREx_DisableAVM2() to stop the PVM VDDx monitoring.
97 (+) PVM monitored voltages are :
98 (++) VDDUSB versus 1V2
99 (++) VDDIO2 versus 0V9
100 (++) VDDA versus 1V6
101 (++) VDDA versus 1V8
102
103 (#) Call HAL_PWREx_EnableUSBHSTranceiverSupply() and
104 HAL_PWREx_DisableUSBHSTranceiverSupply() to enable / disable the internal
105 USB HS transceiver supply.
106 (+) This feature is available only for STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
107 and STM32U5Gxxx devices
108
109 (#) Call HAL_PWREx_EnableOTGHSPHYLowPowerRetention() and
110 HAL_PWREx_DisableOTGHSPHYLowPowerRetention() to enable / disable OTG_HS PHY power during
111 low power modes (Stop2, Stop3 and Standby).
112 (+) This feature is available only for STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
113 and STM32U5Gxxx devices
114
115 (#) Call HAL_PWREx_EnableVDD11USB() and
116 HAL_PWREx_DisableVDD11USB() to enable/ disable the VDD11USB.
117 (+) This feature is available only for STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
118 and STM32U5Gxxx devices
119
120 (#) Call HAL_PWREx_EnableMonitoring() and HAL_PWREx_DisableMonitoring() to
121 enable / disable the VBAT and temperature monitoring.
122
123 (#) Call HAL_PWREx_EnableUCPDStandbyMode() and
124 HAL_PWREx_DisableUCPDStandbyMode() to enable / disable the UCPD
125 configuration memorization in Standby mode.
126
127 (#) Call HAL_PWREx_EnableUCPDDeadBattery() and
128 HAL_PWREx_DisableUCPDDeadBattery() to enable / disable the dead battery
129 behavior.
130
131 (#) Call HAL_PWREx_PVD_PVM_IRQHandler() function to handle the PWR PVD and
132 PVM interrupt request.
133
134 (#) Call HAL_PWREx_EnableSRAM2ContentStandbyRetention() and
135 HAL_PWREx_DisableSRAM2ContentStandbyRetention() to
136 enable / disable the SRAM2 content retention in Stop 3 and Standby low
137 power modes.
138
139 (#) Call HAL_PWREx_EnableRAMsContentStopRetention() and
140 HAL_PWREx_DisableRAMsContentStopRetention() to
141 enable / disable the RAMs content retention in Stop mode (Stop 0/1/2/3).
142 (+) Retained RAM can be one of the following RAMs :
143 (++) SRAM1
144 (++) SRAM2
145 (++) SRAM3 (available only for STM32U575xx, STM32U585xx, STM32U59xxx,
146 STM32U5Axxx, STM32U5Fxxx and STM32U5Gxxx devices)
147 (++) SRAM4
148 (++) SRAM5 (available only for STM32U59xxx, STM32U5Axxx,
149 STM32U5Fxxx and STM32U5Gxxx devices)
150 (++) SRAM6 (available only for STM32U5Fxxx and STM32U5Gxxx devices)
151 (++) ICACHE
152 (++) DMA2DRAM (available only for STM32U575xx, STM32U585xx, STM32U59xxx,
153 STM32U5Axxx, STM32U5Fxxx and STM32U5Gxxx devices)
154 (++) PKA32RAM
155 (++) DCACHE1
156 (++) FMAC
157 (++) FDCAN
158 (++) USB
159 (++) DCACHE2 (available only for STM32U59xxx, STM32U5Axxx,
160 STM32U5Fxxx and STM32U5Gxxx devices)
161 (++) LTDC (available only for STM32U59xxx, STM32U5Axxx,
162 STM32U5Fxxx and STM32U5Gxxx devices)
163 (++) GFXMMU (available only for STM32U59xxx, STM32U5Axxx,
164 STM32U5Fxxx and STM32U5Gxxx devices)
165 (++) DSI (available only for STM32U59xxx, STM32U5Axxx,
166 STM32U5Fxxx and STM32U5Gxxx devices)
167 (++) JPEG (available only for STM32U5Fxxx and STM32U5Gxxx devices)
168
169 (#) Call HAL_PWREx_EnableRAMsContentRunRetention() and
170 HAL_PWREx_DisableRAMsContentRunRetention() to
171 enable / disable the RAMs content retention in Run mode.
172 (+) Retained RAM can be one of the following RAMs :
173 (++) SRAM1
174 (++) SRAM2
175 (++) SRAM3 (available only for STM32U575xx, STM32U585xx, STM32U59xxx,
176 STM32U5Axxx, STM32U5Fxxx and STM32U5Gxxx devices)
177 (++) SRAM4
178 (++) SRAM5 (available only for STM32U59xxx, STM32U5Axxx,
179 STM32U5Fxxx and STM32U5Gxxx devices)
180 (++) SRAM6 (available only for STM32U5Fxxx and STM32U5Gxxx devices)
181
182 (#) Call HAL_PWREx_EnableFlashFastWakeUp() and
183 HAL_PWREx_DisableFlashFastWakeUp() to enable / disable the flash memory
184 fast wakeup from Stop mode (Stop 0/1).
185
186 (#) Call HAL_PWREx_EnableSRAM4FastWakeUp() and
187 HAL_PWREx_DisableSRAM4FastWakeUp() to enable / disable the SRAM4 memory
188 fast wakeup from Stop mode (Stop 0/1/2).
189
190 (#) Call HAL_PWREx_EnableBkupRAMRetention() and
191 HAL_PWREx_DisableBkupRAMRetention() to enable / disable the Backup RAM
192 content retention in Standby, Shutdown and VBAT modes.
193
194 (#) Call HAL_PWREx_EnablePullUpPullDownConfig() and
195 HAL_PWREx_DisablePullUpPullDownConfig() to I/O enable / disable pull-up
196 and pull-down configuration.
197
198 (#) Call HAL_PWREx_EnableGPIOPullUp() and HAL_PWREx_EnableGPIOPullDown() to
199 apply respectively pull-up and pull-down to selected I/O.
200 Call HAL_PWREx_DisableGPIOPullUp() and HAL_PWREx_DisableGPIOPullDown() to
201 disable applied respectively pull-up and pull-down to selected I/O.
202
203 @endverbatim
204 ******************************************************************************
205 */
206
207 /* Includes ------------------------------------------------------------------*/
208 #include "stm32u5xx_hal.h"
209
210 /** @addtogroup STM32U5xx_HAL_Driver
211 * @{
212 */
213
214 /** @defgroup PWREx PWREx
215 * @brief PWR Extended HAL module driver
216 * @{
217 */
218
219 #if defined (HAL_PWR_MODULE_ENABLED)
220
221 /* Private typedef -----------------------------------------------------------*/
222 /* Private define ------------------------------------------------------------*/
223
224 /** @defgroup PWR_Extended_Private_Defines PWR Extended Private Defines
225 * @{
226 */
227 #if defined (PWR_PUCRJ_PU0)
228 /* PORTI pins mask */
229 #define PWR_PORTI_AVAILABLE_PINS (0xFFFFU)
230 /* PORTJ pins mask */
231 #define PWR_PORTJ_AVAILABLE_PINS (0x0FFFU)
232 #else
233 /* PORTI pins mask */
234 #define PWR_PORTI_AVAILABLE_PINS (0x00FFU)
235 #endif /* defined (PWR_PUCRJ_PU0) */
236
237 /* Time out value of flags setting */
238 #define PWR_FLAG_SETTING_DELAY (0x32U)
239
240 /** @defgroup PWR_PVM_Mode_Mask PWR PVM Mode Mask
241 * @{
242 */
243 #define PVM_RISING_EDGE (0x01U) /*!< Mask for rising edge set as PVM trigger */
244 #define PVM_FALLING_EDGE (0x02U) /*!< Mask for falling edge set as PVM trigger */
245 #define PVM_MODE_IT (0x04U) /*!< Mask for interruption yielded by PVM threshold crossing */
246 #define PVM_MODE_EVT (0x08U) /*!< Mask for event yielded by PVM threshold crossing */
247 /**
248 * @}
249 */
250
251 /**
252 * @}
253 */
254
255 /* Private macro -------------------------------------------------------------*/
256 /* Private variables ---------------------------------------------------------*/
257 /* Private function prototypes -----------------------------------------------*/
258 /* Exported functions --------------------------------------------------------*/
259
260 /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
261 * @{
262 */
263
264 /** @defgroup PWREx_Exported_Functions_Group1 Power Supply Control Functions
265 * @brief Power supply control functions
266 *
267 @verbatim
268 ===============================================================================
269 ##### Power supply control functions #####
270 ===============================================================================
271 [..]
272 This section provides functions allowing to control power supply.
273
274 [..]
275 (+) The STM32U5 Series devices embed two regulators : one LDO (linear
276 voltage regulator) and one SMPS (step down converter) in parallel to
277 provide the VCORE supply for digital peripherals, SRAM1, SRAM2, SRAM3
278 and SRAM4 and embedded Flash memory.
279
280 (+) The SMPS allows the power consumption to be reduced but some
281 peripherals can be perturbed by the noise generated by the SMPS,
282 requiring the application to switch to LDO when running this
283 peripheral in order to reach the best performances.
284
285 (+) The LDO and the SMPS regulators have two modes: Main regulator mode
286 (used when performance is needed), and Low-power regulator mode. LDO
287 or SMPS can be used in all voltage scaling ranges, and in all Stop
288 modes.
289
290 (+) After reset, the regulator is the LDO, in Range 4. Switching to SMPS
291 provides lower consumption in particular at high VDD voltage. It is
292 possible to switch from LDO to SMPS, or from SMPS to LDO on the fly in
293 any range, by configuring the REGSEL bit. It is recommended to switch
294 first to SMPS before changing the voltage range.
295
296 (+) When exiting the Stop or Standby modes, the regulator is the same than
297 when entering low power modes. The voltage range is the Range 4.
298
299 (+) Both regulators can provide four different voltages (voltage scaling)
300 and can operate in Stop modes.
301 Voltage scaling ranges can be one of the following values :
302 (++) voltage output scale 1 : 1V2
303 => Used when system clock frequency is up to 160 MHz
304 (++) voltage output scale 2 : 1V1
305 => Used when system clock frequency is up to 100 MHz
306 (++) voltage output scale 3 : 1V0
307 => Used when system clock frequency is up to 50 MHz
308 (++) voltage output scale 4 : 0V9
309 => Used when system clock frequency is up to 24 MHz
310
311 @endverbatim
312 * @{
313 */
314
315 /**
316 * @brief Configure the main internal regulator output voltage to achieve
317 * a tradeoff between performance and power consumption.
318 * @param VoltageScaling : Specifies the regulator output voltage scale.
319 * This parameter can be one of the following values :
320 * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1 : Regulator voltage output scale 1.
321 * Provides a typical output voltage at 1.2 V.
322 * Used when system clock frequency is up to 160 MHz.
323 * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE2 : Regulator voltage output scale 2.
324 * Provides a typical output voltage at 1.1 V.
325 * Used when system clock frequency is up to 100 MHz.
326 * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE3 : Regulator voltage output scale 3.
327 * Provides a typical output voltage at 1.0 V.
328 * Used when system clock frequency is up to 50 MHz.
329 * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE4 : Regulator voltage output scale 4.
330 * Provides a typical output voltage at 0.9 V.
331 * Used when system clock frequency is up to 24 MHz.
332 * @note Before moving to voltage scaling 2, it is mandatory to ensure that
333 * the system frequency is between 50 MHz and 100 MHz.
334 * @note Before moving to voltage scaling 3, it is mandatory to ensure that
335 * the system frequency is between 24 MHz and 50 MHz.
336 * @note Before moving to voltage scaling 4, it is mandatory to ensure that
337 * the system frequency is below 24 MHz.
338 * @retval HAL Status.
339 */
HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)340 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
341 {
342 uint32_t timeout;
343 uint32_t vos_old;
344
345 /* Check the parameter */
346 assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
347
348 /* Get the current voltage scale applied */
349 vos_old = READ_BIT(PWR->SVMSR, PWR_SVMSR_ACTVOS);
350
351 /* No change, nothing to do */
352 if (vos_old == VoltageScaling)
353 {
354 /* Enable USB BOOST after wake up from Stop mode */
355 if (VoltageScaling > PWR_REGULATOR_VOLTAGE_SCALE3)
356 {
357 /* Enable USB BOOST */
358 SET_BIT(PWR->VOSR, PWR_VOSR_BOOSTEN);
359 }
360
361 return HAL_OK;
362 }
363
364 /* Check voltage scaling level */
365 /*
366 * The Embedded power distribution (EPOD) must be enabled before switching to
367 * voltage scale 1 / 2 from voltage scale lower.
368 */
369 if (VoltageScaling > PWR_REGULATOR_VOLTAGE_SCALE3)
370 {
371 MODIFY_REG(PWR->VOSR, (PWR_VOSR_VOS | PWR_VOSR_BOOSTEN), (VoltageScaling | PWR_VOSR_BOOSTEN));
372 }
373 else
374 {
375 MODIFY_REG(PWR->VOSR, (PWR_VOSR_VOS | PWR_VOSR_BOOSTEN), VoltageScaling);
376 }
377
378 /* Wait until VOSRDY is raised */
379 timeout = ((PWR_FLAG_SETTING_DELAY * (SystemCoreClock / 1000U)) / 1000U) + 1U;
380 while (HAL_IS_BIT_CLR(PWR->VOSR, PWR_VOSR_VOSRDY) && (timeout != 0U))
381 {
382 timeout--;
383 }
384
385 /* Check time out */
386 if (timeout != 0U)
387 {
388 /* Wait until ACTVOSRDY is raised */
389 timeout = ((PWR_FLAG_SETTING_DELAY * (SystemCoreClock / 1000U)) / 1000U) + 1U;
390 while ((HAL_IS_BIT_CLR(PWR->SVMSR, PWR_SVMSR_ACTVOSRDY)) && (timeout != 0U))
391 {
392 timeout--;
393 }
394 }
395
396 /* Check time out */
397 if (timeout == 0U)
398 {
399 return HAL_TIMEOUT;
400 }
401
402 return HAL_OK;
403 }
404
405 /**
406 * @brief Return Voltage Scaling Range.
407 * @retval Applied voltage scaling value.
408 */
HAL_PWREx_GetVoltageRange(void)409 uint32_t HAL_PWREx_GetVoltageRange(void)
410 {
411 return (PWR->SVMSR & PWR_SVMSR_ACTVOS);
412 }
413
414 /**
415 * @brief Configure the system Power Supply.
416 * @param SupplySource : Specifies the Power Supply source to set after a
417 * system startup.
418 * This parameter can be one of the following values :
419 * @arg PWR_LDO_SUPPLY : The LDO regulator supplies the Vcore Power Domains.
420 * @arg PWR_SMPS_SUPPLY : The SMPS regulator supplies the Vcore Power Domains.
421 * @retval HAL Status.
422 */
HAL_PWREx_ConfigSupply(uint32_t SupplySource)423 HAL_StatusTypeDef HAL_PWREx_ConfigSupply(uint32_t SupplySource)
424 {
425 uint32_t timeout;
426
427 /* Check the parameter */
428 assert_param(IS_PWR_SUPPLY(SupplySource));
429
430 /* Set maximum time out */
431 timeout = ((PWR_FLAG_SETTING_DELAY * (SystemCoreClock / 1000U)) / 1000U) + 1U;
432
433 /* Configure the LDO as system regulator supply */
434 if (SupplySource == PWR_LDO_SUPPLY)
435 {
436 /* Set the power supply configuration */
437 CLEAR_BIT(PWR->CR3, PWR_CR3_REGSEL);
438
439 /* Wait until system switch on new regulator */
440 while (HAL_IS_BIT_SET(PWR->SVMSR, PWR_SVMSR_REGS) && (timeout != 0U))
441 {
442 timeout--;
443 }
444 }
445 /* Configure the SMPS as system regulator supply */
446 else
447 {
448 /* Set the power supply configuration */
449 SET_BIT(PWR->CR3, PWR_CR3_REGSEL);
450
451 /* Wait until system switch on new regulator */
452 while (HAL_IS_BIT_CLR(PWR->SVMSR, PWR_SVMSR_REGS) && (timeout != 0U))
453 {
454 timeout--;
455 }
456 }
457
458 /* Check time out */
459 if (timeout == 0U)
460 {
461 return HAL_TIMEOUT;
462 }
463
464 return HAL_OK;
465 }
466
467 /**
468 * @brief Get the power supply configuration.
469 * @retval The supply configured.
470 */
HAL_PWREx_GetSupplyConfig(void)471 uint32_t HAL_PWREx_GetSupplyConfig(void)
472 {
473 return (PWR->SVMSR & PWR_SVMSR_REGS);
474 }
475
476 /**
477 * @brief Enable fast soft start for the current regulator.
478 * @retval None.
479 */
HAL_PWREx_EnableFastSoftStart(void)480 void HAL_PWREx_EnableFastSoftStart(void)
481 {
482 SET_BIT(PWR->CR3, PWR_CR3_FSTEN);
483 }
484
485 /**
486 * @brief Disable fast soft start for the current regulator.
487 * @retval None.
488 */
HAL_PWREx_DisableFastSoftStart(void)489 void HAL_PWREx_DisableFastSoftStart(void)
490 {
491 CLEAR_BIT(PWR->CR3, PWR_CR3_FSTEN);
492 }
493 /**
494 * @}
495 */
496
497
498 /** @defgroup PWREx_Exported_Functions_Group2 Low Power Control Functions
499 * @brief Low power control functions
500 *
501 @verbatim
502 ===============================================================================
503 ##### Low power control functions #####
504 ===============================================================================
505 [..]
506 This section provides functions allowing to control low power modes.
507
508 *** Low Power modes configuration ***
509 =====================================
510 [..]
511 This section presents 4 principles low power modes :
512 (+) Stop 1 mode : Cortex-M33 is stopped, clocks are stopped and the
513 regulator is in low power mode. Several peripheral can
514 operate in this mode.
515
516 (+) Stop 2 mode : Cortex-M33 is stopped, clocks are stopped and the
517 regulator is in low power mode. Only autonomous
518 peripherals can operate in this mode.
519
520 (+) Stop 3 mode : Cortex-M33 is stopped, clocks are stopped and the
521 regulator is in low power mode. No peripheral can
522 operate in this mode. Only RAMs content is preserved.
523
524 (+) Shutdown mode : All PWR domains enter Shutdown mode and the VCORE
525 supply regulator is powered off. The SRAMs and
526 register contents are lost except for registers in the
527 Backup domain.
528
529 *** Stop 1 mode ***
530 ===================
531 [..]
532 The Stop 1 mode is based on the Cortex-M33 Deepsleep mode combined with
533 the peripheral clock gating. The voltage regulator is configured in low
534 power mode. In Stop 1 mode, all clocks in the VCORE domain are stopped.
535 The PLL, MSIS, MSIK, HSI16 and HSE oscillators are disabled.
536 Some peripherals with the LPBAM capability can switch on HSI16 or MSIS or
537 MSIK for transferring data. All SRAMs and register contents are preserved,
538 but the SRAMs can be totally or partially switched off to further reduced
539 consumption.
540 The BOR is always available in Stop 1 mode.
541
542 (+) Entry:
543 The Stop 1 mode is entered by using the HAL_PWREx_EnterSTOP1Mode()
544 function.
545
546 (++) PWR_STOPENTRY_WFI: enter Stop 1 mode with WFI instruction.
547 (++) PWR_STOPENTRY_WFE: enter Stop 1 mode with WFE instruction.
548
549 (+) Exit:
550 Any EXTI line configured in interrupt mode (the corresponding EXTI
551 interrupt vector must be enabled in the NVIC). The interrupt source
552 can be external interrupts or peripherals with wakeup capability.
553 Any peripheral interrupt occurring when the AHB/APB clocks are present
554 due to an autonomous peripheral clock request (the peripheral vector
555 must be enabled in the NVIC)
556 Any EXTI line configured in event mode.
557
558 *** Stop 2 mode ***
559 ===================
560 [..]
561 The Stop 2 mode is based on the Cortex-M33 Deepsleep mode combined with
562 peripheral clock gating. In Stop 2 mode, all clocks in the VCORE domain
563 are stopped.
564 The PLL, MSIS, MSIK, HSI16 and HSE oscillators are disabled.
565 Some peripherals with the LPBAM capability can switch on HSI16 or MSIS or
566 MSIK for transferring data. All SRAMs and register contents are preserved,
567 but the SRAMs can be totally or partially switched off to further reduce
568 consumption.
569 The BOR is always available in Stop 2 mode.
570
571 (+) Entry:
572 The Stop 2 mode is entered by using the HAL_PWREx_EnterSTOP2Mode()
573 function.
574
575 (++) PWR_STOPENTRY_WFI: enter Stop 2 mode with WFI instruction.
576 (++) PWR_STOPENTRY_WFE: enter Stop 2 mode with WFE instruction.
577
578 (+) Exit:
579 Any EXTI line configured in interrupt mode (the corresponding EXTI
580 interrupt vector must be enabled in the NVIC). The interrupt source
581 can be external interrupts or peripherals with wakeup capability.
582 Any peripheral interrupt occurring when the AHB/APB clocks are present
583 due to an autonomous peripheral clock request (the peripheral vector
584 must be enabled in the NVIC)
585 Any EXTI line configured in event mode.
586
587 *** Stop 3 mode ***
588 ===================
589 [..]
590 The Stop 3 mode is based on the Cortex-M33 Deepsleep mode combined with
591 peripheral clock gating. In Stop 3 mode, all clocks in the VCORE domain
592 are stopped.
593 The PLL, MSIS, MSIK, HSI16 and HSE oscillators are disabled.
594 All SRAMs and register contents are preserved, but the SRAMs can be
595 totally or partially switched off to further reduce consumption.
596 The BOR is always available in Stop 3 mode.
597
598 (+) Entry:
599 The Stop 3 mode is entered by using the HAL_PWREx_EnterSTOP3Mode()
600 function.
601
602 (++) PWR_STOPENTRY_WFI: enter Stop 3 mode with WFI instruction.
603 (++) PWR_STOPENTRY_WFE: enter Stop 3 mode with WFE instruction.
604
605 (+) Exit:
606 WKUPx pin edge, RTC or TAMP event, external Reset in NRST pin, IWDG
607 Reset, BOR reset.
608
609 *** Shutdown mode ***
610 ====================
611 [..]
612 The lowest power consumption is reached in Shutdown mode. It is based on
613 the Deepsleep mode with the voltage regulator disabled. The VCORE domain
614 is consequently powered off.
615 The PLL, HSI16, MSIS, MSIK and HSE oscillators are also switched off.
616 The SRAMs and register contents are lost except for registers in the
617 Backup domain.
618 The BOR is not available in Shutdown mode.
619 No power voltage monitoring is possible in this mode, therefore the switch
620 to Backup domain is not supported.
621
622 (+) Entry:
623 The Shutdown mode is entered by using the HAL_PWREx_EnterSHUTDOWNMode()
624 function.
625
626 (+) Exit:
627 WKUPx pin edge, RTC/TAMP event, external Reset in NRST pin.
628
629 @endverbatim
630 * @{
631 */
632
633 /**
634 * @brief Enter the whole system to Stop 1 mode.
635 * @note Stop 1 offers the largest number of active peripherals and wakeup
636 * sources, a smaller wakeup time but a higher consumption.
637 * @note Stop mode achieves the lowest power consumption while retaining
638 * the content of SRAM and registers. All clocks in the VCORE domain
639 * are stopped. The PLL, the MSI (MSIS and MSIK) RC, the HSI16 RC and
640 * the HSE crystal oscillators are disabled. The LSE or LSI is still
641 * running.
642 * @note The system clock when exiting from Stop mode can be either MSIS up
643 * to 24 MHz or HSI16, depending on software configuration.
644 * @param STOPEntry : Specifies if Stop mode is entered with WFI or WFE
645 * instruction.
646 * This parameter can be one of the following values :
647 * @arg @ref PWR_STOPENTRY_WFI enter Stop mode with Wait
648 * For Interrupt request.
649 * @arg @ref PWR_STOPENTRY_WFE enter Stop mode with Wait
650 * For Event request.
651 * @retval None.
652 */
HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)653 void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)
654 {
655 /* Check the parameters */
656 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
657
658 /* Stop 1 mode */
659 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_0);
660
661 /* Set SLEEPDEEP bit of Cortex System Control Register */
662 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
663
664 /* Select Stop mode entry */
665 if (STOPEntry == PWR_STOPENTRY_WFI)
666 {
667 /* Request Wait For Interrupt */
668 __WFI();
669 }
670 else
671 {
672 /* Request Wait For Event */
673 __SEV();
674 __WFE();
675 __WFE();
676 }
677
678 /* Reset SLEEPDEEP bit of Cortex System Control Register */
679 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
680 }
681
682 /**
683 * @brief Enter the whole system to Stop 2 mode.
684 * @note In Stop 2 mode, all clocks in the VCORE domain are stopped. The PLL,
685 * MSIS, MSIK, HSI16 and HSE oscillators are disabled.
686 * @note Stop mode achieves the lowest power consumption while retaining
687 * the content of SRAM and registers. All clocks in the VCORE domain
688 * are stopped. The PLL, the MSI (MSIS and MSIK) RC, the HSI16 RC and
689 * the HSE crystal oscillators are disabled. The LSE or LSI is still
690 * running.
691 * @note The system clock when exiting from Stop mode can be either MSIS up
692 * to 24 MHz or HSI16, depending on software configuration.
693 * @param STOPEntry : Specifies if Stop mode is entered with WFI or WFE
694 * instruction.
695 * This parameter can be one of the following values :
696 * @arg @ref PWR_STOPENTRY_WFI enter Stop mode with Wait
697 * For Interrupt request.
698 * @arg @ref PWR_STOPENTRY_WFE enter Stop mode with Wait
699 * For Event request.
700 * @retval None.
701 */
HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry)702 void HAL_PWREx_EnterSTOP2Mode(uint8_t STOPEntry)
703 {
704 /* Check the parameters */
705 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
706
707 /* Stop 2 mode */
708 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_1);
709
710 /* Set SLEEPDEEP bit of Cortex System Control Register */
711 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
712
713 /* Select Stop mode entry */
714 if (STOPEntry == PWR_STOPENTRY_WFI)
715 {
716 /* Request Wait For Interrupt */
717 __WFI();
718 }
719 else
720 {
721 /* Request Wait For Event */
722 __SEV();
723 __WFE();
724 __WFE();
725 }
726
727 /* Reset SLEEPDEEP bit of Cortex System Control Register */
728 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
729 }
730
731 /**
732 * @brief Enter the whole system to Stop 3 mode.
733 * @note Stop 3 is the lowest power mode with full retention, but the
734 * functional peripherals and sources of wakeup are reduced to the same
735 * ones than in Standby mode.
736 * @note Stop mode achieves the lowest power consumption while retaining
737 * the content of SRAM and registers. All clocks in the VCORE domain
738 * are stopped. The PLL, the MSI (MSIS and MSIK) RC, the HSI16 RC and
739 * the HSE crystal oscillators are disabled. The LSE or LSI is still
740 * running.
741 * @note The system clock when exiting from Stop mode can be either MSIS up
742 * to 24 MHz or HSI16, depending on software configuration.
743 * @param STOPEntry : Specifies if Stop mode is entered with WFI or WFE
744 * instruction.
745 * This parameter can be one of the following values :
746 * @arg @ref PWR_STOPENTRY_WFI enter Stop mode with Wait
747 * For Interrupt request.
748 * @arg @ref PWR_STOPENTRY_WFE enter Stop mode with Wait
749 * For Event request.
750 * @retval None.
751 */
HAL_PWREx_EnterSTOP3Mode(uint8_t STOPEntry)752 void HAL_PWREx_EnterSTOP3Mode(uint8_t STOPEntry)
753 {
754 /* Check the parameter */
755 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
756
757 /* Set Stop mode 3 */
758 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, (PWR_CR1_LPMS_0 | PWR_CR1_LPMS_1));
759
760 /* Set SLEEPDEEP bit of Cortex System Control Register */
761 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
762
763 /* Select Stop mode entry */
764 if (STOPEntry == PWR_STOPENTRY_WFI)
765 {
766 /* Request Wait For Interrupt */
767 __WFI();
768 }
769 else
770 {
771 /* Request Wait For Event */
772 __SEV();
773 __WFE();
774 __WFE();
775 }
776
777 /* Reset SLEEPDEEP bit of Cortex System Control Register */
778 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
779 }
780
781 /**
782 * @brief Enter the whole system to Shutdown mode.
783 * @note Shutdown mode allows the lowest power consumption. The internal
784 * regulator is switched off so that the VCORE domain is powered off.
785 * The PLL, the HSI16, the MSI (MSIS and MSIK), the LSI and the HSE
786 * oscillators are also switched off.
787 * @note The SRAMs and register contents are lost except for registers in the
788 * Backup domain. The BOR is not available in Shutdown mode. No power
789 * voltage monitoring is possible in this mode, therefore the switch to
790 * Backup domain is not supported.
791 * @retval None.
792 */
HAL_PWREx_EnterSHUTDOWNMode(void)793 void HAL_PWREx_EnterSHUTDOWNMode(void)
794 {
795 /* Set Shutdown mode */
796 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, (PWR_CR1_LPMS_1 | PWR_CR1_LPMS_2));
797
798 /* Set SLEEPDEEP bit of Cortex System Control Register */
799 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
800
801 /* This option is used to ensure that store operations are completed */
802 #if defined (__CC_ARM)
803 __force_stores();
804 #endif /* (__CC_ARM)*/
805 /* Request Wait For Interrupt */
806 __WFI();
807 }
808
809 /**
810 * @brief Configure the SRD domain when the System in Stop 0/1/2 mode.
811 * @param SRDState : Specifies the SRD state.
812 * This parameter can be one of the following values :
813 * @arg PWR_SRD_DOMAIN_STOP : SRD in Stop mode when system
814 * goes to Stop 0/1/2 mode
815 * @arg PWR_SRD_DOMAIN_RUN : SRD in Run mode when system
816 * goes to Stop 0/1/2 mode
817 * @retval None.
818 */
HAL_PWREx_ConfigSRDDomain(uint32_t SRDState)819 void HAL_PWREx_ConfigSRDDomain(uint32_t SRDState)
820 {
821 /* Check the parameter */
822 assert_param(IS_PWR_SRD_STATE(SRDState));
823
824 /* Config the SRD domain */
825 MODIFY_REG(PWR->CR2, PWR_CR2_SRDRUN, SRDState);
826 }
827
828 /**
829 * @brief Enable BOR ultra-low power mode.
830 * @note BOR operating can be in discontinuous (ultra-low power) mode in
831 * Stop 1, Stop 2, Stop 3 and Standby modes and when the regulator is
832 * in Range 4 (Run, Sleep or Stop 0 mode).
833 * @retval None.
834 */
HAL_PWREx_EnableUltraLowPowerMode(void)835 void HAL_PWREx_EnableUltraLowPowerMode(void)
836 {
837 SET_BIT(PWR->CR1, PWR_CR1_ULPMEN);
838 }
839
840 /**
841 * @brief Disable BOR ultra-low power mode.
842 * @retval None.
843 */
HAL_PWREx_DisableUltraLowPowerMode(void)844 void HAL_PWREx_DisableUltraLowPowerMode(void)
845 {
846 CLEAR_BIT(PWR->CR1, PWR_CR1_ULPMEN);
847 }
848
849 /**
850 * @brief This function handles the PWR Wake up from Stop 3 interrupt request.
851 * @note This API should be called under the PWR_S3WU_IRQHandler().
852 * @param WakeUpPin : Specifies the wakeup pin interrupt to be handled.
853 * This parameter can be a combination of @ref PWR_WakeUp_Pins.
854 * @retval None.
855 */
HAL_PWREx_S3WU_IRQHandler(uint32_t WakeUpPin)856 void HAL_PWREx_S3WU_IRQHandler(uint32_t WakeUpPin)
857 {
858 /* Check PWR wake up line 1 */
859 if ((WakeUpPin & PWR_WAKEUP_PIN1) != 0U)
860 {
861 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF1) != 0U)
862 {
863 /* Clear PWR wake up flag line 1 */
864 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF1);
865
866 /* PWR S3WU interrupt user callback */
867 HAL_PWREx_S3WUCallback(WakeUpPin);
868 }
869 }
870
871 /* Check PWR wake up line 2 */
872 if ((WakeUpPin & PWR_WAKEUP_PIN2) != 0U)
873 {
874 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF2) != 0U)
875 {
876 /* Clear PWR wake up flag line 2 */
877 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF2);
878
879 /* PWR S3WU interrupt user callback */
880 HAL_PWREx_S3WUCallback(WakeUpPin);
881 }
882 }
883
884 /* Check PWR wake up line 3 */
885 if ((WakeUpPin & PWR_WAKEUP_PIN3) != 0U)
886 {
887 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF3) != 0U)
888 {
889 /* Clear PWR wake up flag line 3 */
890 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF3);
891
892 /* PWR S3WU interrupt user callback */
893 HAL_PWREx_S3WUCallback(WakeUpPin);
894 }
895 }
896
897 /* Check PWR wake up line 4 */
898 if ((WakeUpPin & PWR_WAKEUP_PIN4) != 0U)
899 {
900 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF4) != 0U)
901 {
902 /* Clear PWR wake up flag line 4 */
903 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF4);
904
905 /* PWR S3WU interrupt user callback */
906 HAL_PWREx_S3WUCallback(WakeUpPin);
907 }
908 }
909
910 /* Check PWR wake up line 5 */
911 if ((WakeUpPin & PWR_WAKEUP_PIN5) != 0U)
912 {
913 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF5) != 0U)
914 {
915 /* Clear PWR wake up flag line 5 */
916 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF5);
917
918 /* PWR S3WU interrupt user callback */
919 HAL_PWREx_S3WUCallback(WakeUpPin);
920 }
921 }
922
923 /* Check PWR wake up line 6 */
924 if ((WakeUpPin & PWR_WAKEUP_PIN6) != 0U)
925 {
926 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF6) != 0U)
927 {
928 /* Clear PWR wake up flag line 6 */
929 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF6);
930
931 /* PWR S3WU interrupt user callback */
932 HAL_PWREx_S3WUCallback(WakeUpPin);
933 }
934 }
935
936 /* Check PWR wake up line 7 */
937 if ((WakeUpPin & PWR_WAKEUP_PIN7) != 0U)
938 {
939 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF7) != 0U)
940 {
941 /* Clear PWR wake up flag line 7 */
942 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF7);
943
944 /* PWR S3WU interrupt user callback */
945 HAL_PWREx_S3WUCallback(WakeUpPin);
946 }
947 }
948
949 /* Check PWR wake up line 8 */
950 if ((WakeUpPin & PWR_WAKEUP_PIN8) != 0U)
951 {
952 if (READ_BIT(PWR->WUSR, PWR_WUSR_WUF8) != 0U)
953 {
954 /* Clear PWR wake up flag line 8 */
955 SET_BIT(PWR->WUSCR, PWR_WUSCR_CWUF8);
956
957 /* PWR S3WU interrupt user callback */
958 HAL_PWREx_S3WUCallback(WakeUpPin);
959 }
960 }
961 }
962
963 /**
964 * @brief PWR S3WU interrupt callback.
965 * @param WakeUpPin : Specifies the wakeup pin interrupt to be handled.
966 * This parameter can be a combination of @ref PWR_WakeUp_Pins.
967 * @retval None.
968 */
HAL_PWREx_S3WUCallback(uint32_t WakeUpPin)969 __weak void HAL_PWREx_S3WUCallback(uint32_t WakeUpPin)
970 {
971 /* Prevent unused argument(s) compilation warning */
972 UNUSED(WakeUpPin);
973
974 /* NOTE : This function should not be modified; when the callback is needed,
975 HAL_PWREx_S3WU_IRQHandler() API can be implemented in the user file
976 */
977 }
978 /**
979 * @}
980 */
981
982 /** @defgroup PWREx_Exported_Functions_Group3 Voltage Monitoring Functions
983 * @brief Voltage monitoring functions
984 *
985 @verbatim
986 ===============================================================================
987 ##### Voltage Monitoring Functions #####
988 ===============================================================================
989 [..]
990 This section provides functions allowing voltage monitoring.
991
992 *** PVM configuration ***
993 =========================
994 [..]
995 (+) The supplies (VDDA, VDDIO2 and VDDUSB) can be independent from VDD and
996 can be monitored with four peripheral voltage monitoring (PVM):
997
998 (++) The UVM monitors the USB supply VDDUSB. VDDUSBRDY indicates if
999 the VDDUSB independent power supply is higher or lower than the
1000 VUVM threshold.
1001 (++) The IO2VM monitors the PG[15:2] supply VDDIO2. VDDIO2RDY
1002 indicates if the VDDIO2 independent power supply is higher or
1003 lower than the VIO2VM threshold.
1004 (++) The AVM1 monitors the analog supply VDDA. VDDA1RDY indicates if
1005 the VDDA independent power supply is higher or lower than the
1006 VAVM1 threshold.
1007 (++) The AVM2 monitors the analog supply VDDA. VDDA2RDY indicates if
1008 the VDDA independent power supply is higher or lower than the
1009 VAVM2 threshold.
1010
1011 (+) Each PVM output is connected to an EXTI line and can generate an
1012 interrupt if enabled through the EXTI registers. The PVMx output
1013 interrupt is generated when the independent power supply drops below
1014 the PVM threshold and/or when it rises above the PVM threshold,
1015 depending on EXTI line rising/falling edge configuration.
1016
1017 (+) Each PVM can remain active in Stop 0, Stop 1, Stop 2 modes, and the
1018 PVM interrupt can wake up from the Stop mode. The PVM is not
1019 functional in Stop 3 mode.
1020
1021 *** VBAT charging ***
1022 =====================
1023 [..]
1024 When VDD is present, it is possible to charge the external battery on VBAT
1025 through an internal resistance.
1026 The VBAT charging is done either through a 5 kOhm resistor or through a 1.5
1027 kOhm resistor depending on the VBRS bit value in the PWR_BDCR2 register.
1028 The battery charging is enabled by setting VBE bit in the PWR_BDCR2
1029 register. It is automatically disabled in VBAT mode.
1030
1031 *** Backup domain monitoring ***
1032 ================================
1033 [..]
1034 When the Backup domain voltage and temperature monitoring is enabled
1035 (MONEN = 1 in the PWR_BDCR1 register), the Backup domain voltage and the
1036 temperature are monitored.
1037 If the Backup domain voltage monitoring internal tamper is enabled in the
1038 TAMP peripheral (ITAMP1E = 1 in the TAMP_CR1 register), a tamper event is
1039 generated when the Backup domain voltage is above the functional range.
1040 In case the Backup domain voltage is below the functional range,
1041 a Brownout reset is generated, erasing all device including Backup domain.
1042
1043 *** Backup domain battery ***
1044 =============================
1045 [..]
1046 (+) To retain the content of the backup registers and supply the RTC
1047 function when VDD is turned off, the VBAT pin can be connected to an
1048 optional backup voltage supplied by a battery or by another source.
1049 The VBAT pin powers the RTC unit, the LSE oscillator and the PC13 to
1050 PC15 I/Os, allowing the RTC to operate even when the main power supply
1051 is turned off. The backup SRAM is optionally powered by VBAT pin when
1052 the BREN bit is set in the PWR Backup domain control register 1
1053 (PWR_BDCR1).
1054 The switch to the VBAT supply is controlled by the power down reset
1055 embedded in the Reset block.
1056
1057 (+) After exiting reset, the USB Type-C (dead battery) behavior is enabled,
1058 which may have a pull-down effect on CC1 and CC2 pins. It is
1059 recommended to disable it in all cases, either to stop this pull-down
1060 or to handover control to the UCPD (the UCPD must be initialized
1061 before doing the disable).
1062
1063 @endverbatim
1064 * @{
1065 */
1066
1067 /**
1068 * @brief Configure the voltage monitor threshold detected by the Peripheral
1069 * voltage monitoring (PVM).
1070 * @param pConfigPVM : Pointer to a PWR_PVMTypeDef structure that contains the
1071 * PVM configuration information (PVMType and EventMode).
1072 * @retval HAL Status.
1073 */
HAL_PWREx_ConfigPVM(PWR_PVMTypeDef * pConfigPVM)1074 HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *pConfigPVM)
1075 {
1076 /* Check the PVM parameter */
1077 if (pConfigPVM == NULL)
1078 {
1079 return HAL_ERROR;
1080 }
1081
1082 /* Check the parameters */
1083 assert_param(IS_PWR_PVM_TYPE(pConfigPVM->PVMType));
1084 assert_param(IS_PWR_PVM_MODE(pConfigPVM->Mode));
1085
1086 /* Check the peripheral voltage monitor type */
1087 switch (pConfigPVM->PVMType)
1088 {
1089 case PWR_UVM: /* Independent USB voltage monitor */
1090
1091 /* Disable EXTI UVM event and interrupt */
1092 __HAL_PWR_UVM_EXTI_DISABLE_EVENT();
1093 __HAL_PWR_UVM_EXTI_DISABLE_IT();
1094 __HAL_PWR_UVM_EXTI_DISABLE_RISING_EDGE();
1095 __HAL_PWR_UVM_EXTI_DISABLE_FALLING_EDGE();
1096
1097 /* Configure the UVM in interrupt mode */
1098 if ((pConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
1099 {
1100 __HAL_PWR_UVM_EXTI_ENABLE_IT();
1101 }
1102
1103 /* Configure the UVM in event mode */
1104 if ((pConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
1105 {
1106 __HAL_PWR_UVM_EXTI_ENABLE_EVENT();
1107 }
1108
1109 /* Configure the UVM in rising edge */
1110 if ((pConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
1111 {
1112 __HAL_PWR_UVM_EXTI_ENABLE_RISING_EDGE();
1113 }
1114
1115 /* Configure the UVM in falling edge */
1116 if ((pConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
1117 {
1118 __HAL_PWR_UVM_EXTI_ENABLE_FALLING_EDGE();
1119 }
1120
1121 break;
1122
1123 case PWR_IO2VM: /* Independent I/Os voltage monitor */
1124
1125 /* Disable EXTI IO2VM event and interrupt */
1126 __HAL_PWR_IO2VM_EXTI_DISABLE_EVENT();
1127 __HAL_PWR_IO2VM_EXTI_DISABLE_IT();
1128 __HAL_PWR_IO2VM_EXTI_DISABLE_RISING_EDGE();
1129 __HAL_PWR_IO2VM_EXTI_DISABLE_FALLING_EDGE();
1130
1131 /* Configure the IO2VM in interrupt mode */
1132 if ((pConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
1133 {
1134 __HAL_PWR_IO2VM_EXTI_ENABLE_IT();
1135 }
1136
1137 /* Configure the IO2VM in event mode */
1138 if ((pConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
1139 {
1140 __HAL_PWR_IO2VM_EXTI_ENABLE_EVENT();
1141 }
1142
1143 /* Configure the IO2VM in rising edge */
1144 if ((pConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
1145 {
1146 __HAL_PWR_IO2VM_EXTI_ENABLE_RISING_EDGE();
1147 }
1148
1149 /* Configure the IO2VM in falling edge */
1150 if ((pConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
1151 {
1152 __HAL_PWR_IO2VM_EXTI_ENABLE_FALLING_EDGE();
1153 }
1154
1155 break;
1156
1157 case PWR_AVM1: /* VDDA Independent analog supply voltage monitor 1 (1.6V threshold) */
1158
1159 /* Disable EXTI AVM1 event and interrupt */
1160 __HAL_PWR_AVM1_EXTI_DISABLE_EVENT();
1161 __HAL_PWR_AVM1_EXTI_DISABLE_IT();
1162 __HAL_PWR_AVM1_EXTI_DISABLE_RISING_EDGE();
1163 __HAL_PWR_AVM1_EXTI_DISABLE_FALLING_EDGE();
1164
1165 /* Configure the AVM1 in interrupt mode */
1166 if ((pConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
1167 {
1168 __HAL_PWR_AVM1_EXTI_ENABLE_IT();
1169 }
1170
1171 /* Configure the AVM1 in event mode */
1172 if ((pConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
1173 {
1174 __HAL_PWR_AVM1_EXTI_ENABLE_EVENT();
1175 }
1176
1177 /* Configure the AVM1 in rising edge */
1178 if ((pConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
1179 {
1180 __HAL_PWR_AVM1_EXTI_ENABLE_RISING_EDGE();
1181 }
1182
1183 /* Configure the AVM1 in falling edge */
1184 if ((pConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
1185 {
1186 __HAL_PWR_AVM1_EXTI_ENABLE_FALLING_EDGE();
1187 }
1188
1189 break;
1190
1191 case PWR_AVM2: /* VDDA Independent analog supply voltage monitor 2 (1.8V threshold) */
1192
1193 /* Disable EXTI AVM2 event and interrupt */
1194 __HAL_PWR_AVM2_EXTI_DISABLE_EVENT();
1195 __HAL_PWR_AVM2_EXTI_DISABLE_IT();
1196 __HAL_PWR_AVM2_EXTI_DISABLE_RISING_EDGE();
1197 __HAL_PWR_AVM2_EXTI_DISABLE_FALLING_EDGE();
1198
1199 /* Configure the AVM2 in interrupt mode */
1200 if ((pConfigPVM->Mode & PVM_MODE_IT) == PVM_MODE_IT)
1201 {
1202 __HAL_PWR_AVM2_EXTI_ENABLE_IT();
1203 }
1204
1205 /* Configure the AVM2 in event mode */
1206 if ((pConfigPVM->Mode & PVM_MODE_EVT) == PVM_MODE_EVT)
1207 {
1208 __HAL_PWR_AVM2_EXTI_ENABLE_EVENT();
1209 }
1210
1211 /* Configure the AVM2 in rising edge */
1212 if ((pConfigPVM->Mode & PVM_RISING_EDGE) == PVM_RISING_EDGE)
1213 {
1214 __HAL_PWR_AVM2_EXTI_ENABLE_RISING_EDGE();
1215 }
1216
1217 /* Configure the AVM2 in falling edge */
1218 if ((pConfigPVM->Mode & PVM_FALLING_EDGE) == PVM_FALLING_EDGE)
1219 {
1220 __HAL_PWR_AVM2_EXTI_ENABLE_FALLING_EDGE();
1221 }
1222
1223 break;
1224
1225 default: /* No valid voltage monitor selected */
1226 return HAL_ERROR;
1227 break;
1228 }
1229
1230 return HAL_OK;
1231 }
1232
1233 /**
1234 * @brief Enable VDDUSB supply.
1235 * @note Remove VDDUSB electrical and logical isolation, once VDDUSB supply
1236 * is present for consumption saving.
1237 * @retval None.
1238 */
HAL_PWREx_EnableVddUSB(void)1239 void HAL_PWREx_EnableVddUSB(void)
1240 {
1241 SET_BIT(PWR->SVMCR, PWR_SVMCR_USV);
1242 }
1243
1244 /**
1245 * @brief Disable VDDUSB supply.
1246 * @retval None.
1247 */
HAL_PWREx_DisableVddUSB(void)1248 void HAL_PWREx_DisableVddUSB(void)
1249 {
1250 CLEAR_BIT(PWR->SVMCR, PWR_SVMCR_USV);
1251 }
1252
1253 /**
1254 * @brief Enable VDDIO2 supply.
1255 * @note Remove VDDIO2 electrical and logical isolation, once VDDIO2 supply
1256 * is present for consumption saving.
1257 * @retval None.
1258 */
HAL_PWREx_EnableVddIO2(void)1259 void HAL_PWREx_EnableVddIO2(void)
1260 {
1261 SET_BIT(PWR->SVMCR, PWR_SVMCR_IO2SV);
1262 }
1263
1264 /**
1265 * @brief Disable VDDIO2 supply.
1266 * @retval None.
1267 */
HAL_PWREx_DisableVddIO2(void)1268 void HAL_PWREx_DisableVddIO2(void)
1269 {
1270 CLEAR_BIT(PWR->SVMCR, PWR_SVMCR_IO2SV);
1271 }
1272
1273 /**
1274 * @brief Enable VDDA supply.
1275 * @note Remove VDDA electrical and logical isolation, once VDDA supply is
1276 * present for consumption saving.
1277 * @retval None.
1278 */
HAL_PWREx_EnableVddA(void)1279 void HAL_PWREx_EnableVddA(void)
1280 {
1281 SET_BIT(PWR->SVMCR, PWR_SVMCR_ASV);
1282 }
1283
1284 /**
1285 * @brief Disable VDDA supply.
1286 * @retval None.
1287 */
HAL_PWREx_DisableVddA(void)1288 void HAL_PWREx_DisableVddA(void)
1289 {
1290 CLEAR_BIT(PWR->SVMCR, PWR_SVMCR_ASV);
1291 }
1292
1293 /**
1294 * @brief Enable the UVM Voltage Monitoring : VDDUSB versus 1.2 V.
1295 * @retval None.
1296 */
HAL_PWREx_EnableUVM(void)1297 void HAL_PWREx_EnableUVM(void)
1298 {
1299 SET_BIT(PWR->SVMCR, PWR_SVMCR_UVMEN);
1300 }
1301
1302 /**
1303 * @brief Disable the UVM Voltage Monitoring : VDDUSB versus 1.2 V.
1304 * @retval None.
1305 */
HAL_PWREx_DisableUVM(void)1306 void HAL_PWREx_DisableUVM(void)
1307 {
1308 CLEAR_BIT(PWR->SVMCR, PWR_SVMCR_UVMEN);
1309 }
1310
1311 /**
1312 * @brief Enable the IO2VM Voltage Monitoring : VDDIO2 versus 0.9 V.
1313 * @retval None.
1314 */
HAL_PWREx_EnableIO2VM(void)1315 void HAL_PWREx_EnableIO2VM(void)
1316 {
1317 SET_BIT(PWR->SVMCR, PWR_SVMCR_IO2VMEN);
1318 }
1319
1320 /**
1321 * @brief Disable the IO2VM Voltage Monitoring : VDDIO2 versus 0.9 V.
1322 * @retval None.
1323 */
HAL_PWREx_DisableIO2VM(void)1324 void HAL_PWREx_DisableIO2VM(void)
1325 {
1326 CLEAR_BIT(PWR->SVMCR, PWR_SVMCR_IO2VMEN);
1327 }
1328
1329 /**
1330 * @brief Enable the AVM1 Voltage Monitoring : VDDA versus 1.6 V.
1331 * @retval None.
1332 */
HAL_PWREx_EnableAVM1(void)1333 void HAL_PWREx_EnableAVM1(void)
1334 {
1335 SET_BIT(PWR->SVMCR, PWR_SVMCR_AVM1EN);
1336 }
1337
1338 /**
1339 * @brief Disable the AVM1 Voltage Monitoring : VDDA versus 1.6 V.
1340 * @retval None.
1341 */
HAL_PWREx_DisableAVM1(void)1342 void HAL_PWREx_DisableAVM1(void)
1343 {
1344 CLEAR_BIT(PWR->SVMCR, PWR_SVMCR_AVM1EN);
1345 }
1346
1347 /**
1348 * @brief Enable the AVM2 Voltage Monitoring : VDDA versus 1.8 V.
1349 * @retval None.
1350 */
HAL_PWREx_EnableAVM2(void)1351 void HAL_PWREx_EnableAVM2(void)
1352 {
1353 SET_BIT(PWR->SVMCR, PWR_SVMCR_AVM2EN);
1354 }
1355
1356 /**
1357 * @brief Disable the AVM2 Voltage Monitoring : VDDA versus 1.8 V.
1358 * @retval None.
1359 */
HAL_PWREx_DisableAVM2(void)1360 void HAL_PWREx_DisableAVM2(void)
1361 {
1362 CLEAR_BIT(PWR->SVMCR, PWR_SVMCR_AVM2EN);
1363 }
1364
1365 /**
1366 * @brief Enable the VBAT and temperature monitoring.
1367 * @retval None.
1368 */
HAL_PWREx_EnableMonitoring(void)1369 void HAL_PWREx_EnableMonitoring(void)
1370 {
1371 SET_BIT(PWR->BDCR1, PWR_BDCR1_MONEN);
1372 }
1373
1374 /**
1375 * @brief Disable the VBAT and temperature monitoring.
1376 * @retval None.
1377 */
HAL_PWREx_DisableMonitoring(void)1378 void HAL_PWREx_DisableMonitoring(void)
1379 {
1380 CLEAR_BIT(PWR->BDCR1, PWR_BDCR1_MONEN);
1381 }
1382
1383 #if defined (PWR_VOSR_USBPWREN)
1384 /**
1385 * @brief Enable the internal USB HS transceiver supply.
1386 * @retval HAL status.
1387 */
HAL_PWREx_EnableUSBHSTranceiverSupply(void)1388 HAL_StatusTypeDef HAL_PWREx_EnableUSBHSTranceiverSupply(void)
1389 {
1390 uint32_t vos;
1391
1392 /* Get the system applied voltage scaling range */
1393 vos = HAL_PWREx_GetVoltageRange();
1394
1395 /* Check the system applied voltage scaling range */
1396 if ((vos == PWR_REGULATOR_VOLTAGE_SCALE1) || (vos == PWR_REGULATOR_VOLTAGE_SCALE2))
1397 {
1398 SET_BIT(PWR->VOSR, (PWR_VOSR_USBPWREN | PWR_VOSR_USBBOOSTEN));
1399 }
1400 else
1401 {
1402 return HAL_ERROR;
1403 }
1404
1405 return HAL_OK;
1406 }
1407
1408 /**
1409 * @brief Disable the internal USB HS transceiver supply.
1410 * @retval HAL status.
1411 */
HAL_PWREx_DisableUSBHSTranceiverSupply(void)1412 void HAL_PWREx_DisableUSBHSTranceiverSupply(void)
1413 {
1414 CLEAR_BIT(PWR->VOSR, (PWR_VOSR_USBPWREN | PWR_VOSR_USBBOOSTEN));
1415 }
1416 #endif /* defined (PWR_VOSR_USBPWREN) */
1417
1418 #if defined (PWR_CR1_FORCE_USBPWR)
1419 /**
1420 * @brief Enable OTG_HS PHY power during low power modes (Stop2, Stop3 and Standby).
1421 * @retval None.
1422 */
HAL_PWREx_EnableOTGHSPHYLowPowerRetention(void)1423 void HAL_PWREx_EnableOTGHSPHYLowPowerRetention(void)
1424 {
1425 /* Set FORCE_USBPWR bit */
1426 SET_BIT(PWR->CR1, PWR_CR1_FORCE_USBPWR);
1427 }
1428
1429 /**
1430 * @brief Disable OTG_HS PHY power during low power modes (Stop2, Stop3 and Standby).
1431 * @retval None.
1432 */
HAL_PWREx_DisableOTGHSPHYLowPowerRetention(void)1433 void HAL_PWREx_DisableOTGHSPHYLowPowerRetention(void)
1434 {
1435 /* Clear FORCE_USBPWR bit */
1436 CLEAR_BIT(PWR->CR1, PWR_CR1_FORCE_USBPWR);
1437 }
1438 #endif /* defined (PWR_CR1_FORCE_USBPWR) */
1439
1440 #if defined (PWR_VOSR_VDD11USBDIS)
1441 /**
1442 * @brief Enable the VDD11USB.
1443 * @retval None.
1444 */
HAL_PWREx_EnableVDD11USB(void)1445 void HAL_PWREx_EnableVDD11USB(void)
1446 {
1447 /* Clear VDD11USBDIS bit */
1448 CLEAR_BIT(PWR->VOSR, PWR_VOSR_VDD11USBDIS);
1449 }
1450
1451 /**
1452 * @brief Disable the VDD11USB.
1453 * @retval None.
1454 */
HAL_PWREx_DisableVDD11USB(void)1455 void HAL_PWREx_DisableVDD11USB(void)
1456 {
1457 /* Set VDD11USBDIS bit */
1458 SET_BIT(PWR->VOSR, PWR_VOSR_VDD11USBDIS);
1459 }
1460 #endif /* defined (PWR_VOSR_VDD11USBDIS) */
1461
1462 #ifdef UCPD1
1463 /**
1464 * @brief Enable UCPD configuration memorization in Standby mode.
1465 * @retval None.
1466 */
HAL_PWREx_EnableUCPDStandbyMode(void)1467 void HAL_PWREx_EnableUCPDStandbyMode(void)
1468 {
1469 SET_BIT(PWR->UCPDR, PWR_UCPDR_UCPD_STDBY);
1470 }
1471
1472 /**
1473 * @brief Disable UCPD configuration memorization in Standby mode.
1474 * @note This function must be called on exiting the Standby mode and before
1475 * any UCPD configuration update.
1476 * @retval None.
1477 */
HAL_PWREx_DisableUCPDStandbyMode(void)1478 void HAL_PWREx_DisableUCPDStandbyMode(void)
1479 {
1480 CLEAR_BIT(PWR->UCPDR, PWR_UCPDR_UCPD_STDBY);
1481 }
1482
1483 /**
1484 * @brief Enable dead battery behavior.
1485 * @note After exiting reset, the USB Type-C (dead battery) behavior is
1486 * enabled, which may have a pull-down effect on CC1 and CC2 pins.
1487 * It is recommended to disable it in all cases, either to stop this
1488 * pull-down or to handover control to the UCPD (the UCPD must be
1489 * initialized before doing the disable).
1490 * @retval None.
1491 */
HAL_PWREx_EnableUCPDDeadBattery(void)1492 void HAL_PWREx_EnableUCPDDeadBattery(void)
1493 {
1494 CLEAR_BIT(PWR->UCPDR, PWR_UCPDR_UCPD_DBDIS);
1495 }
1496
1497 /**
1498 * @brief Disable dead battery behavior.
1499 * @note After exiting reset, the USB Type-C (dead battery) behavior is
1500 * enabled, which may have a pull-down effect on CC1 and CC2 pins.
1501 * It is recommended to disable it in all cases, either to stop this
1502 * pull-down or to handover control to the UCPD (the UCPD must be
1503 * initialized before doing the disable).
1504 * @retval None.
1505 */
HAL_PWREx_DisableUCPDDeadBattery(void)1506 void HAL_PWREx_DisableUCPDDeadBattery(void)
1507 {
1508 SET_BIT(PWR->UCPDR, PWR_UCPDR_UCPD_DBDIS);
1509 }
1510 #endif /* UCPD1 */
1511
1512 /**
1513 * @brief Enable the Battery charging.
1514 * @note When VDD is present, charge the external battery through an internal
1515 * resistor.
1516 * @param ResistorValue : Specifies the charging resistor.
1517 * This parameter can be one of the following values :
1518 * @arg PWR_BATTERY_CHARGING_RESISTOR_5 : 5 KOhm resistor.
1519 * @arg PWR_BATTERY_CHARGING_RESISTOR_1_5 : 1.5 KOhm resistor.
1520 * @retval None.
1521 */
HAL_PWREx_EnableBatteryCharging(uint32_t ResistorValue)1522 void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorValue)
1523 {
1524 /* Check the parameter */
1525 assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorValue));
1526
1527 /* Specify the charging resistor */
1528 MODIFY_REG(PWR->BDCR2, PWR_BDCR2_VBRS, ResistorValue);
1529
1530 /* Enable the Battery charging */
1531 SET_BIT(PWR->BDCR2, PWR_BDCR2_VBE);
1532 }
1533
1534 /**
1535 * @brief Disable the Battery charging.
1536 * @retval None.
1537 */
HAL_PWREx_DisableBatteryCharging(void)1538 void HAL_PWREx_DisableBatteryCharging(void)
1539 {
1540 CLEAR_BIT(PWR->BDCR2, PWR_BDCR2_VBE);
1541 }
1542
1543 /**
1544 * @brief This function handles the PWR PVD/PVM interrupt request.
1545 * @note This API should be called under the PVD_PVM_IRQHandler().
1546 * @retval None.
1547 */
HAL_PWREx_PVD_PVM_IRQHandler(void)1548 void HAL_PWREx_PVD_PVM_IRQHandler(void)
1549 {
1550 uint32_t rising_flag;
1551 uint32_t falling_flag;
1552
1553 /* Get pending flags */
1554 rising_flag = READ_REG(EXTI->RPR1);
1555 falling_flag = READ_REG(EXTI->FPR1);
1556
1557 /* Check PWR exti flags for PVD */
1558 if (((rising_flag | falling_flag) & PWR_EXTI_LINE_PVD) != 0U)
1559 {
1560 /* PWR PVD interrupt user callback */
1561 HAL_PWR_PVDCallback();
1562
1563 /* Clear PVD exti pending bit */
1564 WRITE_REG(EXTI->RPR1, PWR_EXTI_LINE_PVD);
1565 WRITE_REG(EXTI->FPR1, PWR_EXTI_LINE_PVD);
1566 }
1567
1568 /* Check PWR exti flags for UVM */
1569 if (((rising_flag | falling_flag) & PWR_EXTI_LINE_UVM) != 0U)
1570 {
1571 /* PWR UVM interrupt user callback */
1572 HAL_PWREx_UVMCallback();
1573
1574 /* Clear UVM exti pending bit */
1575 WRITE_REG(EXTI->RPR1, PWR_EXTI_LINE_UVM);
1576 WRITE_REG(EXTI->FPR1, PWR_EXTI_LINE_UVM);
1577 }
1578
1579 /* Check PWR exti flags for IO2VM */
1580 if (((rising_flag | falling_flag) & PWR_EXTI_LINE_IO2VM) != 0U)
1581 {
1582 /* PWR IO2VM interrupt user callback */
1583 HAL_PWREx_IO2VMCallback();
1584
1585 /* Clear IO2VM exti pending bit */
1586 WRITE_REG(EXTI->RPR1, PWR_EXTI_LINE_IO2VM);
1587 WRITE_REG(EXTI->FPR1, PWR_EXTI_LINE_IO2VM);
1588 }
1589
1590 /* Check PWR exti flags for AVM1 */
1591 if (((rising_flag | falling_flag) & PWR_EXTI_LINE_AVM1) != 0U)
1592 {
1593 /* PWR AVM1 interrupt user callback */
1594 HAL_PWREx_AVM1Callback();
1595
1596 /* Clear AVM1 exti pending bit */
1597 WRITE_REG(EXTI->RPR1, PWR_EXTI_LINE_AVM1);
1598 WRITE_REG(EXTI->FPR1, PWR_EXTI_LINE_AVM1);
1599 }
1600
1601 /* Check PWR exti flags for AVM2 */
1602 if (((rising_flag | falling_flag) & PWR_EXTI_LINE_AVM2) != 0U)
1603 {
1604 /* PWR AVM2 interrupt user callback */
1605 HAL_PWREx_AVM2Callback();
1606
1607 /* Clear AVM2 exti pending bit */
1608 WRITE_REG(EXTI->RPR1, PWR_EXTI_LINE_AVM2);
1609 WRITE_REG(EXTI->FPR1, PWR_EXTI_LINE_AVM2);
1610 }
1611 }
1612
1613 /**
1614 * @brief PWR UVM interrupt callback.
1615 * @retval None.
1616 */
HAL_PWREx_UVMCallback(void)1617 __weak void HAL_PWREx_UVMCallback(void)
1618 {
1619 /* NOTE : This function should not be modified; when the callback is needed,
1620 HAL_PWREx_UVMCallback() API can be implemented in the user file
1621 */
1622 }
1623
1624 /**
1625 * @brief PWR IO2VM interrupt callback.
1626 * @retval None.
1627 */
HAL_PWREx_IO2VMCallback(void)1628 __weak void HAL_PWREx_IO2VMCallback(void)
1629 {
1630 /* NOTE : This function should not be modified; when the callback is needed,
1631 HAL_PWREx_IO2VMCallback() API can be implemented in the user file
1632 */
1633 }
1634
1635 /**
1636 * @brief PWR AVM1 interrupt callback.
1637 * @retval None.
1638 */
HAL_PWREx_AVM1Callback(void)1639 __weak void HAL_PWREx_AVM1Callback(void)
1640 {
1641 /* NOTE : This function should not be modified; when the callback is needed,
1642 HAL_PWREx_AVM1Callback() API can be implemented in the user file
1643 */
1644 }
1645
1646 /**
1647 * @brief PWR AVM2 interrupt callback.
1648 * @retval None.
1649 */
HAL_PWREx_AVM2Callback(void)1650 __weak void HAL_PWREx_AVM2Callback(void)
1651 {
1652 /* NOTE : This function should not be modified; when the callback is needed,
1653 HAL_PWREx_AVM2Callback() API can be implemented in the user file
1654 */
1655 }
1656 /**
1657 * @}
1658 */
1659
1660 /** @defgroup PWREx_Exported_Functions_Group4 Memories Retention Functions
1661 * @brief Memories retention functions
1662 *
1663 @verbatim
1664 ===============================================================================
1665 ##### Memories Retention Functions #####
1666 ===============================================================================
1667 [..]
1668 Several STM32U5 devices RAMs are configurable to keep / lose RAMs content
1669 during Stop mode (Stop 0/1/2/3).
1670 (+) Retained content RAMs in Stop modes are :
1671 (++) SRAM1
1672 (++) SRAM2
1673 (++) SRAM3 (available only for STM32U575xx, STM32U585xx, STM32U59xxx,
1674 STM32U5Axxx, STM32U5Fxxx and STM32U5Gxxx devices)
1675 (++) SRAM4
1676 (++) ICACHE
1677 (++) DMA2DRAM (available only for STM32U575xx, STM32U585xx, STM32U59xxx,
1678 STM32U5Axxx, STM32U5Fxxx and STM32U5Gxxx devices)
1679 (++) PKA32RAM
1680 (++) DCACHE
1681 (++) FMAC
1682 (++) FDCAN
1683 (++) USB
1684
1685 [..]
1686 Several STM32U5 devices RAMs are configurable to keep / lose RAMs content
1687 during Run mode.
1688 (+) Retained content RAMs in Run modes are :
1689 (++) SRAM1
1690 (++) SRAM2
1691 (++) SRAM3 (available only for STM32U575xx, STM32U585xx, STM32U59xxx,
1692 STM32U5Axxx, STM32U5Fxxx and STM32U5Gxxx devices)
1693 (++) SRAM4
1694
1695 [..]
1696 SRAM2 is configurable to keep / lose its content in Stop 3 and Standby
1697 modes. The SRAM2 retention feature granularity is at pages level.
1698
1699 [..]
1700 BKPRAM is configurable to keep / lose its content in Standby, Shutdown and
1701 VBAT modes.
1702
1703 @endverbatim
1704 * @{
1705 */
1706
1707 /**
1708 * @brief Enable SRAM2 page(s) content retention in Stop 3 and Standby mode.
1709 * @note When RRSx bit is set, SRAM2 is powered by the low-power regulator in
1710 * Stop 3 and Standby mode and its content is kept.
1711 * @param SRAM2Pages : Specifies the SRAM2 pages.
1712 * This parameter can be one of the following values :
1713 * @arg PWR_SRAM2_PAGE1_STANDBY : SRAM2 page 1 retention.
1714 * @arg PWR_SRAM2_PAGE2_STANDBY : SRAM2 page 2 retention.
1715 * @arg PWR_SRAM2_FULL_STANDBY : SRAM2 page 1 and page 2 retention.
1716 * @retval None.
1717 */
HAL_PWREx_EnableSRAM2ContentStandbyRetention(uint32_t SRAM2Pages)1718 void HAL_PWREx_EnableSRAM2ContentStandbyRetention(uint32_t SRAM2Pages)
1719 {
1720 /* Check the parameters */
1721 assert_param(IS_PWR_SRAM2_STANDBY_RETENTION(SRAM2Pages));
1722
1723 /* Set RRSx bit(s) */
1724 SET_BIT(PWR->CR1, SRAM2Pages);
1725 }
1726
1727 /**
1728 * @brief Disable SRAM2 page(s) content retention in Stop 3 and Standby mode.
1729 * @note When RRSx bit is reset, SRAM2 is powered off in Stop 3 and Standby
1730 * mode and its content is lost.
1731 * @param SRAM2Pages : Specifies the SRAM2 pages.
1732 * This parameter can be one of the following values :
1733 * @arg PWR_SRAM2_PAGE1_STANDBY : SRAM2 page 1 retention.
1734 * @arg PWR_SRAM2_PAGE2_STANDBY : SRAM2 page 2 retention.
1735 * @arg PWR_SRAM2_FULL_STANDBY : SRAM2 page 1 and page 2 retention.
1736 * @retval None.
1737 */
HAL_PWREx_DisableSRAM2ContentStandbyRetention(uint32_t SRAM2Pages)1738 void HAL_PWREx_DisableSRAM2ContentStandbyRetention(uint32_t SRAM2Pages)
1739 {
1740 /* Check the parameters */
1741 assert_param(IS_PWR_SRAM2_STANDBY_RETENTION(SRAM2Pages));
1742
1743 /* Clear RRSx bit(s) */
1744 CLEAR_BIT(PWR->CR1, SRAM2Pages);
1745 }
1746
1747 /**
1748 * @brief Enable RAM page(s) content retention in Stop mode (Stop 0, 1, 2, 3).
1749 * @note When enabling content retention for a given RAM, memory kept powered
1750 * in Stop mode. (Not optimized power consumption)
1751 * @param RAMSelection: Specifies RAM page(s) to be retained in Stop mode.
1752 * This parameter can be one or a combination of the same
1753 * memory @ref PWREx_RAM_Contents_Stop_Retention.
1754 * @retval None.
1755 */
HAL_PWREx_EnableRAMsContentStopRetention(uint32_t RAMSelection)1756 void HAL_PWREx_EnableRAMsContentStopRetention(uint32_t RAMSelection)
1757 {
1758 uint32_t dummy;
1759
1760 /* Check RAM ID */
1761 switch (RAMSelection & SRAM_ID_MASK)
1762 {
1763 /* SRAM 1 Stop retention */
1764 case SRAM1_ID:
1765 {
1766 /* Check the parameters */
1767 assert_param(IS_PWR_SRAM1_STOP_RETENTION(RAMSelection));
1768
1769 /* Calculate pages mask */
1770 dummy = (RAMSelection & ~SRAM_ID_MASK) & (PAGE01_ID | PAGE02_ID | PAGE03_ID);
1771 CLEAR_BIT(PWR->CR2, dummy);
1772
1773 #if defined (PWR_CR4_SRAM1PDS4)
1774 /* Calculate pages mask */
1775 dummy = ((RAMSelection & ~SRAM_ID_MASK) & ~(PAGE01_ID | PAGE02_ID | PAGE03_ID)) >> 0x03U;
1776 CLEAR_BIT(PWR->CR4, dummy);
1777 #endif /* defined (PWR_CR4_SRAM1PDS4) */
1778
1779 break;
1780 }
1781
1782 /* SRAM 2 Stop retention */
1783 case SRAM2_ID:
1784 {
1785 /* Check the parameters */
1786 assert_param(IS_PWR_SRAM2_STOP_RETENTION(RAMSelection));
1787
1788 /* Calculate pages mask */
1789 dummy = (RAMSelection & PWR_SRAM2_FULL_STOP) & ~SRAM_ID_MASK;
1790 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_SRAM2PDS1_Pos));
1791
1792 break;
1793 }
1794
1795 #if defined (PWR_CR2_SRAM3PDS1)
1796 /* SRAM 3 Stop retention */
1797 case SRAM3_ID:
1798 {
1799 /* Check the parameters */
1800 assert_param(IS_PWR_SRAM3_STOP_RETENTION(RAMSelection));
1801
1802 /* Calculate pages mask */
1803 dummy = (RAMSelection & ~SRAM_ID_MASK) & (PAGE01_ID | PAGE02_ID | PAGE03_ID | PAGE04_ID |
1804 PAGE05_ID | PAGE06_ID | PAGE07_ID | PAGE08_ID);
1805 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_SRAM3PDS1_Pos));
1806
1807 #if defined (PWR_CR4_SRAM3PDS9)
1808 /* Calculate pages mask */
1809 dummy = ((RAMSelection & ~SRAM_ID_MASK) & ~(PAGE01_ID | PAGE02_ID | PAGE03_ID | PAGE04_ID |
1810 PAGE05_ID | PAGE06_ID | PAGE07_ID | PAGE08_ID)) >> 0x08U;
1811 CLEAR_BIT(PWR->CR4, (dummy << PWR_CR4_SRAM3PDS9_Pos));
1812 #endif /* defined (PWR_CR4_SRAM3PDS9) */
1813
1814 break;
1815 }
1816 #endif /* PWR_CR2_SRAM3PDS1 */
1817
1818 /* SRAM 4 Stop retention */
1819 case SRAM4_ID:
1820 {
1821 /* Check the parameters */
1822 assert_param(IS_PWR_SRAM4_STOP_RETENTION(RAMSelection));
1823
1824 /* Calculate pages mask */
1825 dummy = (RAMSelection & PWR_SRAM4_FULL_STOP) & ~SRAM_ID_MASK;
1826 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_SRAM4PDS_Pos));
1827
1828 break;
1829 }
1830
1831 /* ICACHE RAM Stop retention */
1832 case ICACHERAM_ID:
1833 {
1834 /* Check the parameters */
1835 assert_param(IS_PWR_ICACHE_STOP_RETENTION(RAMSelection));
1836
1837 /* Calculate pages mask */
1838 dummy = (RAMSelection & PWR_ICACHE_FULL_STOP) & ~SRAM_ID_MASK;
1839 CLEAR_BIT(PWR->CR2, dummy << PWR_CR2_ICRAMPDS_Pos);
1840
1841 break;
1842 }
1843
1844 /* DCACHE1 RAM Stop retention */
1845 case DCACHE1RAM_ID:
1846 {
1847 /* Check the parameters */
1848 assert_param(IS_PWR_DCACHE1_STOP_RETENTION(RAMSelection));
1849
1850 /* Calculate pages mask */
1851 dummy = (RAMSelection & PWR_DCACHE1_FULL_STOP) & ~SRAM_ID_MASK;
1852 CLEAR_BIT(PWR->CR2, dummy << PWR_CR2_DC1RAMPDS_Pos);
1853
1854 break;
1855 }
1856
1857 #if defined (PWR_CR2_DMA2DRAMPDS)
1858 /* DMA2D RAM Stop retention */
1859 case DMA2DRAM_ID:
1860 {
1861 /* Check the parameters */
1862 assert_param(IS_PWR_DMA2DRAM_STOP_RETENTION(RAMSelection));
1863
1864 /* Calculate pages mask */
1865 dummy = (RAMSelection & PWR_DMA2DRAM_FULL_STOP) & ~SRAM_ID_MASK;
1866 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_DMA2DRAMPDS_Pos));
1867
1868 break;
1869 }
1870 #endif /* PWR_CR2_DMA2DRAMPDS */
1871
1872 /* FMAC, FDCAN and USB RAM Stop retention */
1873 case PERIPHRAM_ID:
1874 {
1875 /* Check the parameters */
1876 assert_param(IS_PWR_PERIPHRAM_STOP_RETENTION(RAMSelection));
1877
1878 /* Calculate pages mask */
1879 dummy = (RAMSelection & PWR_PERIPHRAM_FULL_STOP) & ~SRAM_ID_MASK;
1880 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_PRAMPDS_Pos));
1881
1882 break;
1883 }
1884
1885 #if defined (PWR_CR2_PKARAMPDS)
1886 /* PKA32 RAM Stop retention */
1887 case PKARAM_ID:
1888 {
1889 /* Check the parameters */
1890 assert_param(IS_PWR_PKA32RAM_STOP_RETENTION(RAMSelection));
1891
1892 /* Calculate pages mask */
1893 dummy = (RAMSelection & PWR_PKA32RAM_FULL_STOP) & ~SRAM_ID_MASK;
1894 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_PKARAMPDS_Pos));
1895
1896 break;
1897 }
1898 #endif /* PWR_CR2_PKARAMPDS */
1899
1900 #if defined (PWR_CR2_DC2RAMPDS)
1901 /* DCACHE2 RAM Stop retention */
1902 case DCACHE2RAM_ID:
1903 {
1904 /* Check the parameters */
1905 assert_param(IS_PWR_DCACHE2_STOP_RETENTION(RAMSelection));
1906
1907 /* Calculate pages mask */
1908 dummy = (RAMSelection & PWR_DCACHE2_FULL_STOP) & ~SRAM_ID_MASK;
1909 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_DC2RAMPDS_Pos));
1910
1911 break;
1912 }
1913 #endif /* defined (PWR_CR2_DC2RAMPDS) */
1914
1915 #if defined (PWR_CR2_GPRAMPDS)
1916 /* LTDC and GFXMMU RAM Stop retention */
1917 case GRAPHIPRAM_ID:
1918 {
1919 /* Check the parameters */
1920 assert_param(IS_PWR_GRAPHICPRAM_STOP_RETENTION(RAMSelection));
1921
1922 /* Calculate pages mask */
1923 dummy = (RAMSelection & PWR_GRAPHICPRAM_FULL_STOP) & ~SRAM_ID_MASK;
1924 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_GPRAMPDS_Pos));
1925
1926 break;
1927 }
1928 #endif /* defined (PWR_CR2_GPRAMPDS) */
1929
1930 #if defined (PWR_CR2_DSIRAMPDS)
1931 /* DSI RAM Stop retention */
1932 case DSIRAM_ID:
1933 {
1934 /* Check the parameters */
1935 assert_param(IS_PWR_DSIRAM_STOP_RETENTION(RAMSelection));
1936
1937 /* Calculate pages mask */
1938 dummy = (RAMSelection & PWR_DSIRAM_FULL_STOP) & ~SRAM_ID_MASK;
1939 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_DSIRAMPDS_Pos));
1940
1941 break;
1942 }
1943 #endif /* defined (PWR_CR2_DSIRAMPDS) */
1944
1945 #if defined (PWR_CR2_JPEGRAMPDS)
1946 /* JPEG RAM Stop retention */
1947 case JPEGRAM_ID:
1948 {
1949 /* Check the parameters */
1950 assert_param(IS_PWR_JPEGRAM_STOP_RETENTION(RAMSelection));
1951
1952 /* Calculate pages mask */
1953 dummy = (RAMSelection & PWR_JPEGRAM_FULL_STOP) & ~SRAM_ID_MASK;
1954 CLEAR_BIT(PWR->CR2, (dummy << PWR_CR2_JPEGRAMPDS_Pos));
1955
1956 break;
1957 }
1958 #endif /* defined (PWR_CR2_JPEGRAMPDS) */
1959
1960 #if defined (PWR_CR4_SRAM5PDS1)
1961 /* SRAM 5 Stop retention */
1962 case SRAM5_ID:
1963 {
1964 /* Check the parameters */
1965 assert_param(IS_PWR_SRAM5_STOP_RETENTION(RAMSelection));
1966
1967 /* Calculate pages mask */
1968 dummy = ((RAMSelection & PWR_SRAM5_FULL_STOP) & ~SRAM_ID_MASK);
1969 CLEAR_BIT(PWR->CR4, (dummy << PWR_CR4_SRAM5PDS1_Pos));
1970
1971 break;
1972 }
1973 #endif /* defined (PWR_CR4_SRAM5PDS1) */
1974
1975 #if defined (PWR_CR5_SRAM6PDS1)
1976 /* SRAM 6 Stop retention */
1977 case SRAM6_ID:
1978 {
1979 /* Check the parameters */
1980 assert_param(IS_PWR_SRAM6_STOP_RETENTION(RAMSelection));
1981
1982 /* Calculate pages mask */
1983 dummy = ((RAMSelection & PWR_SRAM6_FULL_STOP) & ~SRAM_ID_MASK);
1984 CLEAR_BIT(PWR->CR5, (dummy << PWR_CR5_SRAM6PDS1_Pos));
1985
1986 break;
1987 }
1988 #endif /* defined (PWR_CR5_SRAM6PDS1) */
1989
1990 default:
1991 {
1992 return;
1993 break;
1994 }
1995 }
1996 }
1997
1998 /**
1999 * @brief Disable RAM page(s) content lost in Stop mode (Stop 0, 1, 2, 3).
2000 * @note When disabling content lost for a given RAM, memory powered down
2001 * in Stop mode. (Optimized power consumption)
2002 * @param RAMSelection: Specifies RAM page(s) to be lost in Stop mode.
2003 * This parameter can be one or a combination of the same
2004 * memory @ref PWREx_RAM_Contents_Stop_Retention.
2005 * @retval None.
2006 */
HAL_PWREx_DisableRAMsContentStopRetention(uint32_t RAMSelection)2007 void HAL_PWREx_DisableRAMsContentStopRetention(uint32_t RAMSelection)
2008 {
2009 uint32_t dummy;
2010
2011 /* Check RAM ID */
2012 switch (RAMSelection & SRAM_ID_MASK)
2013 {
2014 /* SRAM 1 Stop retention */
2015 case SRAM1_ID:
2016 {
2017 /* Check the parameters */
2018 assert_param(IS_PWR_SRAM1_STOP_RETENTION(RAMSelection));
2019
2020 /* Calculate pages mask */
2021 dummy = (RAMSelection & ~SRAM_ID_MASK) & (PAGE01_ID | PAGE02_ID | PAGE03_ID);
2022 SET_BIT(PWR->CR2, dummy);
2023 #if defined (PWR_CR4_SRAM1PDS4)
2024 /* Calculate pages mask */
2025 dummy = ((RAMSelection & ~SRAM_ID_MASK) & ~(PAGE01_ID | PAGE02_ID | PAGE03_ID)) >> 0x03U;
2026 SET_BIT(PWR->CR4, dummy);
2027 #endif /* defined (PWR_CR4_SRAM1PDS4) */
2028
2029 break;
2030 }
2031
2032 /* SRAM 2 Stop retention */
2033 case SRAM2_ID:
2034 {
2035 /* Check the parameters */
2036 assert_param(IS_PWR_SRAM2_STOP_RETENTION(RAMSelection));
2037
2038 /* Calculate pages mask */
2039 dummy = (RAMSelection & PWR_SRAM2_FULL_STOP) & ~SRAM_ID_MASK;
2040 SET_BIT(PWR->CR2, (dummy << PWR_CR2_SRAM2PDS1_Pos));
2041
2042 break;
2043 }
2044
2045 #if defined (PWR_CR2_SRAM3PDS1)
2046 /* SRAM 3 Stop retention */
2047 case SRAM3_ID:
2048 {
2049 /* Check the parameters */
2050 assert_param(IS_PWR_SRAM3_STOP_RETENTION(RAMSelection));
2051
2052 /* Calculate pages mask */
2053 dummy = (RAMSelection & ~SRAM_ID_MASK) & (PAGE01_ID | PAGE02_ID | PAGE03_ID | PAGE04_ID |
2054 PAGE05_ID | PAGE06_ID | PAGE07_ID | PAGE08_ID);
2055 SET_BIT(PWR->CR2, (dummy << PWR_CR2_SRAM3PDS1_Pos));
2056
2057 #if defined (PWR_CR4_SRAM3PDS9)
2058 /* Calculate pages mask */
2059 dummy = ((RAMSelection & ~SRAM_ID_MASK) & ~(PAGE01_ID | PAGE02_ID | PAGE03_ID | PAGE04_ID |
2060 PAGE05_ID | PAGE06_ID | PAGE07_ID | PAGE08_ID)) >> 0x08U;
2061 SET_BIT(PWR->CR4, (dummy << PWR_CR4_SRAM3PDS9_Pos));
2062 #endif /* defined (PWR_CR4_SRAM3PDS9) */
2063
2064 break;
2065 }
2066 #endif /* PWR_CR2_SRAM3PDS1 */
2067
2068 /* SRAM 4 Stop retention */
2069 case SRAM4_ID:
2070 {
2071 /* Check the parameters */
2072 assert_param(IS_PWR_SRAM4_STOP_RETENTION(RAMSelection));
2073
2074 /* Calculate pages mask */
2075 dummy = (RAMSelection & PWR_SRAM4_FULL_STOP) & ~SRAM_ID_MASK;
2076 SET_BIT(PWR->CR2, (dummy << PWR_CR2_SRAM4PDS_Pos));
2077
2078 break;
2079 }
2080
2081 /* ICACHE RAM Stop retention */
2082 case ICACHERAM_ID:
2083 {
2084 /* Check the parameters */
2085 assert_param(IS_PWR_ICACHE_STOP_RETENTION(RAMSelection));
2086
2087 /* Calculate pages mask */
2088 dummy = (RAMSelection & PWR_ICACHE_FULL_STOP) & ~SRAM_ID_MASK;
2089 SET_BIT(PWR->CR2, (dummy << PWR_CR2_ICRAMPDS_Pos));
2090
2091 break;
2092 }
2093
2094 /* DCACHE1 RAM Stop retention */
2095 case DCACHE1RAM_ID:
2096 {
2097 /* Check the parameters */
2098 assert_param(IS_PWR_DCACHE1_STOP_RETENTION(RAMSelection));
2099
2100 /* Calculate pages mask */
2101 dummy = (RAMSelection & PWR_DCACHE1_FULL_STOP) & ~SRAM_ID_MASK;
2102 SET_BIT(PWR->CR2, (dummy << PWR_CR2_DC1RAMPDS_Pos));
2103
2104 break;
2105 }
2106
2107 #if defined (PWR_CR2_DMA2DRAMPDS)
2108 /* DMA2D RAM Stop retention */
2109 case DMA2DRAM_ID:
2110 {
2111 /* Check the parameters */
2112 assert_param(IS_PWR_DMA2DRAM_STOP_RETENTION(RAMSelection));
2113
2114 /* Calculate pages mask */
2115 dummy = (RAMSelection & PWR_DMA2DRAM_FULL_STOP) & ~SRAM_ID_MASK;
2116 SET_BIT(PWR->CR2, (dummy << PWR_CR2_DMA2DRAMPDS_Pos));
2117
2118 break;
2119 }
2120 #endif /* PWR_CR2_DMA2DRAMPDS */
2121
2122 /* FMAC, FDCAN and USB RAM Stop retention */
2123 case PERIPHRAM_ID:
2124 {
2125 /* Check the parameters */
2126 assert_param(IS_PWR_PERIPHRAM_STOP_RETENTION(RAMSelection));
2127
2128 /* Calculate pages mask */
2129 dummy = (RAMSelection & PWR_PERIPHRAM_FULL_STOP) & ~SRAM_ID_MASK;
2130 SET_BIT(PWR->CR2, (dummy << PWR_CR2_PRAMPDS_Pos));
2131
2132 break;
2133 }
2134
2135 #if defined (PWR_CR2_PKARAMPDS)
2136 /* PKA32 RAM Stop retention */
2137 case PKARAM_ID:
2138 {
2139 /* Check the parameters */
2140 assert_param(IS_PWR_PKA32RAM_STOP_RETENTION(RAMSelection));
2141
2142 /* Calculate pages mask */
2143 dummy = (RAMSelection & PWR_PKA32RAM_FULL_STOP) & ~SRAM_ID_MASK;
2144 SET_BIT(PWR->CR2, (dummy << PWR_CR2_PKARAMPDS_Pos));
2145
2146 break;
2147 }
2148 #endif /* PWR_CR2_PKARAMPDS */
2149
2150 #if defined (PWR_CR2_DC2RAMPDS)
2151 /* DCACHE2 RAM Stop retention */
2152 case DCACHE2RAM_ID:
2153 {
2154 /* Check the parameters */
2155 assert_param(IS_PWR_DCACHE2_STOP_RETENTION(RAMSelection));
2156
2157 /* Calculate pages mask */
2158 dummy = (RAMSelection & PWR_DCACHE2_FULL_STOP) & ~SRAM_ID_MASK;
2159 SET_BIT(PWR->CR2, (dummy << PWR_CR2_DC2RAMPDS_Pos));
2160
2161 break;
2162 }
2163 #endif /* defined (PWR_CR2_DC2RAMPDS) */
2164
2165 #if defined (PWR_CR2_GPRAMPDS)
2166 /* LTDC and GFXMMU RAM Stop retention */
2167 case GRAPHIPRAM_ID:
2168 {
2169 /* Check the parameters */
2170 assert_param(IS_PWR_GRAPHICPRAM_STOP_RETENTION(RAMSelection));
2171
2172 /* Calculate pages mask */
2173 dummy = (RAMSelection & PWR_GRAPHICPRAM_FULL_STOP) & ~SRAM_ID_MASK;
2174 SET_BIT(PWR->CR2, (dummy << PWR_CR2_GPRAMPDS_Pos));
2175
2176 break;
2177 }
2178 #endif /* defined (PWR_CR2_GPRAMPDS) */
2179
2180 #if defined (PWR_CR2_DSIRAMPDS)
2181 /* DSI RAM Stop retention */
2182 case DSIRAM_ID:
2183 {
2184 /* Check the parameters */
2185 assert_param(IS_PWR_DSIRAM_STOP_RETENTION(RAMSelection));
2186
2187 /* Calculate pages mask */
2188 dummy = (RAMSelection & PWR_DSIRAM_FULL_STOP) & ~SRAM_ID_MASK;
2189 SET_BIT(PWR->CR2, (dummy << PWR_CR2_DSIRAMPDS_Pos));
2190
2191 break;
2192 }
2193 #endif /* defined (PWR_CR2_DSIRAMPDS) */
2194
2195 #if defined (PWR_CR2_JPEGRAMPDS)
2196 /* JPEG RAM Stop retention */
2197 case JPEGRAM_ID:
2198 {
2199 /* Check the parameters */
2200 assert_param(IS_PWR_JPEGRAM_STOP_RETENTION(RAMSelection));
2201
2202 /* Calculate pages mask */
2203 dummy = (RAMSelection & PWR_JPEGRAM_FULL_STOP) & ~SRAM_ID_MASK;
2204 SET_BIT(PWR->CR2, (dummy << PWR_CR2_JPEGRAMPDS_Pos));
2205
2206 break;
2207 }
2208 #endif /* defined (PWR_CR2_JPEGRAMPDS) */
2209
2210 #if defined (PWR_CR4_SRAM5PDS1)
2211 /* SRAM 5 Stop retention */
2212 case SRAM5_ID:
2213 {
2214 /* Check the parameters */
2215 assert_param(IS_PWR_SRAM5_STOP_RETENTION(RAMSelection));
2216
2217 /* Calculate pages mask */
2218 dummy = ((RAMSelection & PWR_SRAM5_FULL_STOP) & ~SRAM_ID_MASK);
2219 SET_BIT(PWR->CR4, (dummy << PWR_CR4_SRAM5PDS1_Pos));
2220
2221 break;
2222 }
2223 #endif /* defined (PWR_CR4_SRAM5PDS1) */
2224
2225 #if defined (PWR_CR5_SRAM6PDS1)
2226 /* SRAM 6 Stop retention */
2227 case SRAM6_ID:
2228 {
2229 /* Check the parameters */
2230 assert_param(IS_PWR_SRAM6_STOP_RETENTION(RAMSelection));
2231
2232 /* Calculate pages mask */
2233 dummy = ((RAMSelection & PWR_SRAM6_FULL_STOP) & ~SRAM_ID_MASK);
2234 SET_BIT(PWR->CR5, (dummy << PWR_CR5_SRAM6PDS1_Pos));
2235
2236 break;
2237 }
2238 #endif /* defined (PWR_CR5_SRAM6PDS1) */
2239
2240 default:
2241 {
2242 return;
2243 break;
2244 }
2245 }
2246 }
2247
2248 /**
2249 * @brief Enable RAMs full content retention in Run mode.
2250 * @param RAMSelection : Specifies the SRAM content to be retained in Run mode.
2251 * This parameter can be one or a combination of the following values :
2252 * @arg PWR_SRAM1_FULL_RUN : SRAM1 full content retention.
2253 * @arg PWR_SRAM2_FULL_RUN : SRAM2 full content retention.
2254 * @arg PWR_SRAM3_FULL_RUN : SRAM3 full content retention (available only for STM32U575xx,
2255 * STM32U585xx STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
2256 and STM32U5Gxxx devices).
2257 * @arg PWR_SRAM4_FULL_RUN : SRAM4 full content retention.
2258 * @arg PWR_SRAM5_FULL_RUN : SRAM5 full content retention (available only for
2259 * STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
2260 * and STM32U5Gxxx devices).
2261 * @arg PWR_SRAM6_FULL_RUN : SRAM6 full content retention (available only for
2262 * STM32U5Fxxx and STM32U5Gxxx devices).
2263 * @retval None.
2264 */
HAL_PWREx_EnableRAMsContentRunRetention(uint32_t RAMSelection)2265 void HAL_PWREx_EnableRAMsContentRunRetention(uint32_t RAMSelection)
2266 {
2267 /* Check the parameters */
2268 assert_param(IS_PWR_RAM_RUN_RETENTION(RAMSelection));
2269
2270 /* Enable RAM retention in Run mode */
2271 CLEAR_BIT(PWR->CR1, RAMSelection);
2272 }
2273
2274 /**
2275 * @brief Disable RAMs full content retention in Run mode.
2276 * @param RAMSelection : Specifies the SRAM content to be lost in Run mode.
2277 * This parameter can be one or a combination of the following values :
2278 * @arg PWR_SRAM1_FULL_RUN : SRAM1 full content lost.
2279 * @arg PWR_SRAM2_FULL_RUN : SRAM2 full content lost.
2280 * @arg PWR_SRAM3_FULL_RUN : SRAM3 full content lost (available only for STM32U575xx,
2281 * STM32U585xx STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
2282 and STM32U5Gxxx devices).
2283 * @arg PWR_SRAM4_FULL_RUN : SRAM4 full content lost.
2284 * @arg PWR_SRAM5_FULL_RUN : SRAM5 full content retention (available only for
2285 * STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
2286 * and STM32U5Gxxx devices).
2287 * @arg PWR_SRAM6_FULL_RUN : SRAM6 full content retention (available only for
2288 * STM32U5Fxxx and STM32U5Gxxx devices).
2289 * @retval None.
2290 */
HAL_PWREx_DisableRAMsContentRunRetention(uint32_t RAMSelection)2291 void HAL_PWREx_DisableRAMsContentRunRetention(uint32_t RAMSelection)
2292 {
2293 /* Check the parameters */
2294 assert_param(IS_PWR_RAM_RUN_RETENTION(RAMSelection));
2295
2296 /* Disable RAM retention in Run mode */
2297 SET_BIT(PWR->CR1, RAMSelection);
2298 }
2299
2300 /**
2301 * @brief Enable the Backup RAM retention in Standby, Shutdown and VBAT modes.
2302 * @note If BREN is reset, the backup RAM can still be used in Run, Sleep and
2303 * Stop modes. However, its content is lost in Standby, Shutdown and
2304 * VBAT modes.
2305 * @note This bit can be enabled only when LDO regulator is selected as
2306 * source supply.
2307 * @retval HAL Status.
2308 */
HAL_PWREx_EnableBkupRAMRetention(void)2309 HAL_StatusTypeDef HAL_PWREx_EnableBkupRAMRetention(void)
2310 {
2311 /*
2312 Backup RAM retention in Standby, Shutdown and VBAT should be enabled
2313 when the Vcore is alimented by the LDO regulator
2314 */
2315 if (HAL_PWREx_GetSupplyConfig() == PWR_LDO_SUPPLY)
2316 {
2317 SET_BIT(PWR->BDCR1, PWR_BDCR1_BREN);
2318 }
2319 /* SMPS regulator selected */
2320 else
2321 {
2322 return HAL_ERROR;
2323 }
2324
2325 return HAL_OK;
2326 }
2327
2328 /**
2329 * @brief Disable the Backup RAM retention in Standby, Shutdown and VBAT modes.
2330 * @note If BREN is reset, the backup RAM can still be used in Run, Sleep and
2331 * Stop modes. However, its content is lost in Standby, Shutdown and
2332 * VBAT modes. This bit can be writte
2333 * @retval None.
2334 */
HAL_PWREx_DisableBkupRAMRetention(void)2335 void HAL_PWREx_DisableBkupRAMRetention(void)
2336 {
2337 CLEAR_BIT(PWR->BDCR1, PWR_BDCR1_BREN);
2338 }
2339
2340 /**
2341 * @brief Enable the flash memory fast wakeup from Stop 0 and Stop 1 modes.
2342 * @note This feature is used to obtain the best trade-off between low-power
2343 * consumption and wakeup time when exiting the Stop 0 or Stop 1 modes.
2344 * When this feature is enabled, the Flash memory remains in normal
2345 * mode in Stop 0 and Stop 1 modes, which offers a faster startup time
2346 * with higher consumption.
2347 * @retval None.
2348 */
HAL_PWREx_EnableFlashFastWakeUp(void)2349 void HAL_PWREx_EnableFlashFastWakeUp(void)
2350 {
2351 SET_BIT(PWR->CR2, PWR_CR2_FLASHFWU);
2352 }
2353
2354 /**
2355 * @brief Disable the Flash Power Down in Stop mode.
2356 * @note This feature is used to obtain the best trade-off between low-power
2357 * consumption and wakeup time when exiting the Stop 0 or Stop 1 modes.
2358 * When this feature is disabled, the Flash memory enters low-power
2359 * mode in Stop 0 and Stop 1 modes, which causes a slower startup time
2360 * with lower consumption.
2361 * @retval None.
2362 */
HAL_PWREx_DisableFlashFastWakeUp(void)2363 void HAL_PWREx_DisableFlashFastWakeUp(void)
2364 {
2365 CLEAR_BIT(PWR->CR2, PWR_CR2_FLASHFWU);
2366 }
2367
2368 /**
2369 * @brief Enable the SRAM4 memory fast wakeup from Stop 0, Stop 1 and Stop 2 modes.
2370 * @note This bit is used to obtain the best trade-off between low-power consumption
2371 * and wakeup time. SRAM4 wakeup time increases the wakeup time when exiting
2372 * Stop 0, Stop 1 and Stop 2 modes, and also increases the LPDMA access time
2373 * to SRAM4 during Stop modes.
2374 * @retval None.
2375 */
HAL_PWREx_EnableSRAM4FastWakeUp(void)2376 void HAL_PWREx_EnableSRAM4FastWakeUp(void)
2377 {
2378 SET_BIT(PWR->CR2, PWR_CR2_SRAM4FWU);
2379 }
2380
2381 /**
2382 * @brief Disable the SRAM4 memory fast wakeup from Stop 0, Stop 1 and Stop 2 modes.
2383 * @note This bit is used to obtain the best trade-off between low-power consumption
2384 * and wakeup time. SRAM4 wakeup time increases the wakeup time when exiting
2385 * Stop 0, Stop 1 and Stop 2 modes, and also increases the LPDMA access time
2386 * to SRAM4 during Stop modes.
2387 * @retval None.
2388 */
HAL_PWREx_DisableSRAM4FastWakeUp(void)2389 void HAL_PWREx_DisableSRAM4FastWakeUp(void)
2390 {
2391 CLEAR_BIT(PWR->CR2, PWR_CR2_SRAM4FWU);
2392 }
2393 /**
2394 * @}
2395 */
2396
2397 /** @defgroup PWREx_Exported_Functions_Group5 I/O Pull-Up Pull-Down Configuration Functions
2398 * @brief I/O pull-up / pull-down configuration functions
2399 *
2400 @verbatim
2401 ===============================================================================
2402 ##### I/O Pull-Up Pull-Down Configuration Functions #####
2403 ===============================================================================
2404 [..]
2405 In Standby and Shutdown mode, pull up and pull down can be configured to
2406 maintain an I/O in the selected state. If the APC bit in the PWR_APCR
2407 register is set, the I/Os can be configured either with a pull-up through
2408 PWR_PUCRx registers (x=A,B,C,D,E,F,G,H,I,J), or with a pull-down through
2409 PWR_PDCRx registers (x=A,B,C,D,E,F,G,H,I,J)), or can be kept in analog state
2410 if none of the PWR_PUCRx or PWR_PDCRx register is set.
2411 (+) Port J is available only for STM32U59xxx, STM32U5Axxx, STM32U5Fxxx
2412 and STM32U5Gxxx devices.
2413
2414 [..]
2415 The pull-down configuration has highest priority over pull-up
2416 configuration in case both PWR_PUCRx and PWR_PDCRx are set for the same
2417 I/O.
2418 This configuration is lost when exiting the Shutdown but not from Standby
2419 mode.
2420
2421 @endverbatim
2422 * @{
2423 */
2424
2425 /**
2426 * @brief Enable pull-up and pull-down configuration.
2427 * @note When APC bit is set, the I/O pull-up and pull-down configurations
2428 * defined in PWR_PUCRx and PWR_PDCRx registers are applied in Standby
2429 * and Shutdown modes.
2430 * @note Pull-up set by PUy bit of PWR_PUCRx register is not activated if the
2431 * corresponding PDy bit of PWR_PDCRx register is also set (pull-down
2432 * configuration priority is higher). HAL_PWREx_EnableGPIOPullUp() and
2433 * HAL_PWREx_EnableGPIOPullDown() API's ensure there is no conflict
2434 * when setting PUy or PDy bit.
2435 * @retval None.
2436 */
HAL_PWREx_EnablePullUpPullDownConfig(void)2437 void HAL_PWREx_EnablePullUpPullDownConfig(void)
2438 {
2439 SET_BIT(PWR->APCR, PWR_APCR_APC);
2440 }
2441
2442 /**
2443 * @brief Disable pull-up and pull-down configuration.
2444 * @note When APC bit is cleared, the I/O pull-up and pull-down configurations
2445 * defined in PWR_PUCRx and PWR_PDCRx registers are not applied in
2446 * Standby and Shutdown modes.
2447 * @retval None.
2448 */
HAL_PWREx_DisablePullUpPullDownConfig(void)2449 void HAL_PWREx_DisablePullUpPullDownConfig(void)
2450 {
2451 CLEAR_BIT(PWR->APCR, PWR_APCR_APC);
2452 }
2453
2454 /**
2455 * @brief Enable GPIO pull-up state in Standby and Shutdown modes.
2456 * @note Set the relevant PUy bits of PWR_PUCRx register to configure the I/O
2457 * in pull-up state in Standby and Shutdown modes.
2458 * @note This state is effective in Standby and Shutdown modes only if APC
2459 * bit is set through HAL_PWREx_EnablePullUpPullDownConfig() API.
2460 * @note The configuration is lost when exiting the Shutdown mode due to the
2461 * power-on reset, maintained when exiting the Standby mode.
2462 * @note To avoid any conflict at Standby and Shutdown modes exits, the
2463 * corresponding PDy bit of PWR_PDCRx register is cleared unless it is
2464 * reserved.
2465 * @note Even if a PUy bit to set is reserved, the other PUy bits entered as
2466 * input parameter at the same time are set.
2467 * @param GPIO_Port : Specify the IO port.
2468 * This parameter can be a value of
2469 * @ref PWREx_GPIO_Port.
2470 * @param GPIO_Pin : Specify the I/O pins numbers.
2471 * This parameter can be a value of
2472 * @ref PWREx_GPIO_Pin_Mask.
2473 * @retval HAL Status.
2474 */
HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO_Port,uint32_t GPIO_Pin)2475 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO_Port, uint32_t GPIO_Pin)
2476 {
2477 /* Check the parameters */
2478 assert_param(IS_PWR_GPIO_PORT(GPIO_Port));
2479 assert_param(IS_PWR_GPIO_PIN_MASK(GPIO_Pin));
2480
2481 /* Check GPIO port */
2482 switch (GPIO_Port)
2483 {
2484 case PWR_GPIO_A: /* Apply Pull Up to GPIO port A */
2485 SET_BIT(PWR->PUCRA, (GPIO_Pin & (~(PWR_GPIO_BIT_14))));
2486 CLEAR_BIT(PWR->PDCRA, (GPIO_Pin & (~(PWR_GPIO_BIT_13 | PWR_GPIO_BIT_15))));
2487 break;
2488
2489 case PWR_GPIO_B: /* Apply Pull Up to GPIO port B */
2490 SET_BIT(PWR->PUCRB, GPIO_Pin);
2491 CLEAR_BIT(PWR->PDCRB, (GPIO_Pin & (~(PWR_GPIO_BIT_4))));
2492 break;
2493
2494 case PWR_GPIO_C: /* Apply Pull Up to GPIO port C */
2495 SET_BIT(PWR->PUCRC, GPIO_Pin);
2496 CLEAR_BIT(PWR->PDCRC, GPIO_Pin);
2497 break;
2498
2499 case PWR_GPIO_D: /* Apply Pull Up to GPIO port D */
2500 SET_BIT(PWR->PUCRD, GPIO_Pin);
2501 CLEAR_BIT(PWR->PDCRD, GPIO_Pin);
2502 break;
2503
2504 case PWR_GPIO_E: /* Apply Pull Up to GPIO port E */
2505 SET_BIT(PWR->PUCRE, GPIO_Pin);
2506 CLEAR_BIT(PWR->PDCRE, GPIO_Pin);
2507 break;
2508
2509 #ifdef PWR_PUCRF_PU0
2510 case PWR_GPIO_F: /* Apply Pull Up to GPIO port F */
2511 SET_BIT(PWR->PUCRF, GPIO_Pin);
2512 CLEAR_BIT(PWR->PDCRF, GPIO_Pin);
2513 break;
2514 #endif /* PWR_PUCRF_PU0 */
2515
2516 case PWR_GPIO_G: /* Apply Pull Up to GPIO port G */
2517 SET_BIT(PWR->PUCRG, GPIO_Pin);
2518 CLEAR_BIT(PWR->PDCRG, GPIO_Pin);
2519 break;
2520
2521 case PWR_GPIO_H: /* Apply Pull Up to GPIO port H */
2522 SET_BIT(PWR->PUCRH, GPIO_Pin);
2523 CLEAR_BIT(PWR->PDCRH, GPIO_Pin);
2524 break;
2525
2526 #ifdef PWR_PUCRI_PU0
2527 case PWR_GPIO_I: /* Apply Pull Up to GPIO port I */
2528 SET_BIT(PWR->PUCRI, (GPIO_Pin & PWR_PORTI_AVAILABLE_PINS));
2529 CLEAR_BIT(PWR->PDCRI, (GPIO_Pin & PWR_PORTI_AVAILABLE_PINS));
2530 break;
2531 #endif /* PWR_PUCRI_PU0 */
2532
2533 #if defined (PWR_PUCRJ_PU0)
2534 case PWR_GPIO_J: /* Apply Pull Up to GPIO port J */
2535 SET_BIT(PWR->PUCRJ, (GPIO_Pin & PWR_PORTJ_AVAILABLE_PINS));
2536 CLEAR_BIT(PWR->PDCRJ, (GPIO_Pin & PWR_PORTJ_AVAILABLE_PINS));
2537 break;
2538 #endif /* defined (PWR_PUCRJ_PU0) */
2539
2540 default:
2541 return HAL_ERROR;
2542 break;
2543 }
2544
2545 return HAL_OK;
2546 }
2547
2548 /**
2549 * @brief Disable GPIO pull-up state in Standby mode and Shutdown modes.
2550 * @note Reset the relevant PUy bits of PWR_PUCRx register used to configure
2551 * the I/O in pull-up state in Standby and Shutdown modes.
2552 * @note Even if a PUy bit to reset is reserved, the other PUy bits entered as
2553 * input parameter at the same time are reset.
2554 * @param GPIO_Port : Specify the IO port.
2555 * This parameter can be a value of
2556 * @ref PWREx_GPIO_Port.
2557 * @param GPIO_Pin : Specify the I/O pins numbers.
2558 * This parameter can be a value of
2559 * @ref PWREx_GPIO_Pin_Mask.
2560 * @retval HAL Status.
2561 */
HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO_Port,uint32_t GPIO_Pin)2562 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO_Port, uint32_t GPIO_Pin)
2563 {
2564 /* Check the parameters */
2565 assert_param(IS_PWR_GPIO_PORT(GPIO_Port));
2566 assert_param(IS_PWR_GPIO_PIN_MASK(GPIO_Pin));
2567
2568 /* Check GPIO port */
2569 switch (GPIO_Port)
2570 {
2571 case PWR_GPIO_A: /* Disable Pull Up for GPIO port A */
2572 CLEAR_BIT(PWR->PUCRA, (GPIO_Pin & (~(PWR_GPIO_BIT_14))));
2573 break;
2574
2575 case PWR_GPIO_B: /* Disable Pull Up for GPIO port B */
2576 CLEAR_BIT(PWR->PUCRB, GPIO_Pin);
2577 break;
2578
2579 case PWR_GPIO_C: /* Disable Pull Up for GPIO port C */
2580 CLEAR_BIT(PWR->PUCRC, GPIO_Pin);
2581 break;
2582
2583 case PWR_GPIO_D: /* Disable Pull Up for GPIO port D */
2584 CLEAR_BIT(PWR->PUCRD, GPIO_Pin);
2585 break;
2586
2587 case PWR_GPIO_E: /* Disable Pull Up for GPIO port E */
2588 CLEAR_BIT(PWR->PUCRE, GPIO_Pin);
2589 break;
2590
2591 #ifdef PWR_PUCRF_PU0
2592 case PWR_GPIO_F: /* Disable Pull Up for GPIO port F */
2593 CLEAR_BIT(PWR->PUCRF, GPIO_Pin);
2594 break;
2595 #endif /* PWR_PUCRF_PU0 */
2596
2597 case PWR_GPIO_G: /* Disable Pull Up for GPIO port G */
2598 CLEAR_BIT(PWR->PUCRG, GPIO_Pin);
2599 break;
2600
2601 case PWR_GPIO_H: /* Disable Pull Up for GPIO port H */
2602 CLEAR_BIT(PWR->PUCRH, GPIO_Pin);
2603 break;
2604
2605 #ifdef PWR_PUCRI_PU0
2606 case PWR_GPIO_I: /* Disable Pull Up for GPIO port I */
2607 CLEAR_BIT(PWR->PUCRI, (GPIO_Pin & PWR_PORTI_AVAILABLE_PINS));
2608 break;
2609 #endif /* PWR_PUCRI_PU0 */
2610
2611 #if defined (PWR_PUCRJ_PU0)
2612 case PWR_GPIO_J: /* Disable Pull Up for GPIO port J */
2613 CLEAR_BIT(PWR->PUCRJ, (GPIO_Pin & PWR_PORTJ_AVAILABLE_PINS));
2614 break;
2615 #endif /* defined (PWR_PUCRJ_PU0) */
2616
2617 default:
2618 return HAL_ERROR;
2619 break;
2620 }
2621
2622 return HAL_OK;
2623 }
2624
2625 /**
2626 * @brief Enable GPIO pull-down state in Standby and Shutdown modes.
2627 * @note Set the relevant PDy bits of PWR_PDCRx register to configure the I/O
2628 * in pull-down state in Standby and Shutdown modes.
2629 * @note This state is effective in Standby and Shutdown modes only if APC bit
2630 * is set through HAL_PWREx_EnablePullUpPullDownConfig() API.
2631 * @note The configuration is lost when exiting the Shutdown mode due to the
2632 * power-on reset, maintained when exiting the Standby mode.
2633 * @note To avoid any conflict at Standby and Shutdown modes exits, the
2634 * corresponding PUy bit of PWR_PUCRx register is cleared unless it is
2635 * reserved.
2636 * @note Even if a PDy bit to set is reserved, the other PDy bits entered as
2637 * input parameter at the same time are set.
2638 * @param GPIO_Port : Specify the IO port.
2639 * This parameter can be a value of
2640 * @ref PWREx_GPIO_Port.
2641 * @param GPIO_Pin : Specify the I/O pins numbers.
2642 * This parameter can be a value of
2643 * @ref PWREx_GPIO_Pin_Mask.
2644 * @retval HAL Status.
2645 */
HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO_Port,uint32_t GPIO_Pin)2646 HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO_Port, uint32_t GPIO_Pin)
2647 {
2648 /* Check the parameters */
2649 assert_param(IS_PWR_GPIO_PORT(GPIO_Port));
2650 assert_param(IS_PWR_GPIO_PIN_MASK(GPIO_Pin));
2651
2652 /* Check GPIO port */
2653 switch (GPIO_Port)
2654 {
2655 case PWR_GPIO_A: /* Apply Pull Down to GPIO port A */
2656 SET_BIT(PWR->PDCRA, (GPIO_Pin & (~(PWR_GPIO_BIT_13 | PWR_GPIO_BIT_15))));
2657 CLEAR_BIT(PWR->PUCRA, (GPIO_Pin & (~(PWR_GPIO_BIT_14))));
2658 break;
2659
2660 case PWR_GPIO_B: /* Apply Pull Down to GPIO port B */
2661 SET_BIT(PWR->PDCRB, (GPIO_Pin & (~(PWR_GPIO_BIT_4))));
2662 CLEAR_BIT(PWR->PUCRB, GPIO_Pin);
2663 break;
2664
2665 case PWR_GPIO_C: /* Apply Pull Down to GPIO port C */
2666 SET_BIT(PWR->PDCRC, GPIO_Pin);
2667 CLEAR_BIT(PWR->PUCRC, GPIO_Pin);
2668 break;
2669
2670 case PWR_GPIO_D: /* Apply Pull Down to GPIO port D */
2671 SET_BIT(PWR->PDCRD, GPIO_Pin);
2672 CLEAR_BIT(PWR->PUCRD, GPIO_Pin);
2673 break;
2674
2675 case PWR_GPIO_E: /* Apply Pull Down to GPIO port E */
2676 SET_BIT(PWR->PDCRE, GPIO_Pin);
2677 CLEAR_BIT(PWR->PUCRE, GPIO_Pin);
2678 break;
2679
2680 #ifdef PWR_PUCRF_PU0
2681 case PWR_GPIO_F: /* Apply Pull Down to GPIO port F */
2682 SET_BIT(PWR->PDCRF, GPIO_Pin);
2683 CLEAR_BIT(PWR->PUCRF, GPIO_Pin);
2684 break;
2685 #endif /* PWR_PUCRF_PU0 */
2686
2687 case PWR_GPIO_G: /* Apply Pull Down to GPIO port G */
2688 SET_BIT(PWR->PDCRG, GPIO_Pin);
2689 CLEAR_BIT(PWR->PUCRG, GPIO_Pin);
2690 break;
2691
2692 case PWR_GPIO_H: /* Apply Pull Down to GPIO port H */
2693 SET_BIT(PWR->PDCRH, GPIO_Pin);
2694 CLEAR_BIT(PWR->PUCRH, GPIO_Pin);
2695 break;
2696
2697 #ifdef PWR_PUCRI_PU0
2698 case PWR_GPIO_I: /* Apply Pull Down to GPIO port I */
2699 SET_BIT(PWR->PDCRI, (GPIO_Pin & PWR_PORTI_AVAILABLE_PINS));
2700 CLEAR_BIT(PWR->PUCRI, (GPIO_Pin & PWR_PORTI_AVAILABLE_PINS));
2701 break;
2702 #endif /* PWR_PUCRI_PU0 */
2703
2704 #if defined (PWR_PUCRJ_PU0)
2705 case PWR_GPIO_J: /* Apply Pull Down to GPIO port J */
2706 SET_BIT(PWR->PDCRJ, (GPIO_Pin & PWR_PORTJ_AVAILABLE_PINS));
2707 CLEAR_BIT(PWR->PUCRJ, (GPIO_Pin & PWR_PORTJ_AVAILABLE_PINS));
2708 break;
2709 #endif /* defined (PWR_PUCRJ_PU0) */
2710
2711 default:
2712 return HAL_ERROR;
2713 break;
2714 }
2715
2716 return HAL_OK;
2717 }
2718
2719 /**
2720 * @brief Disable GPIO pull-down state in Standby and Shutdown modes.
2721 * @note Reset the relevant PDy bits of PWR_PDCRx register used to configure the I/O
2722 * in pull-down state in Standby and Shutdown modes.
2723 * @note Even if a PDy bit to reset is reserved, the other PDy bits entered as input
2724 * parameter at the same time are reset.
2725 * @param GPIO_Port : Specify the IO port.
2726 * This parameter can be a value of
2727 * @ref PWREx_GPIO_Port.
2728 * @param GPIO_Pin : Specify the I/O pins numbers.
2729 * This parameter can be a value of
2730 * @ref PWREx_GPIO_Pin_Mask.
2731 * @retval HAL Status.
2732 */
HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO_Port,uint32_t GPIO_Pin)2733 HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO_Port, uint32_t GPIO_Pin)
2734 {
2735 /* Check the parameters */
2736 assert_param(IS_PWR_GPIO_PORT(GPIO_Port));
2737 assert_param(IS_PWR_GPIO_PIN_MASK(GPIO_Pin));
2738
2739 /* Check GPIO port */
2740 switch (GPIO_Port)
2741 {
2742 case PWR_GPIO_A: /* Disable Pull Down for GPIO port A */
2743 CLEAR_BIT(PWR->PDCRA, (GPIO_Pin & (~(PWR_GPIO_BIT_13 | PWR_GPIO_BIT_15))));
2744 break;
2745
2746 case PWR_GPIO_B: /* Disable Pull Down for GPIO port B */
2747 CLEAR_BIT(PWR->PDCRB, (GPIO_Pin & (~(PWR_GPIO_BIT_4))));
2748 break;
2749
2750 case PWR_GPIO_C: /* Disable Pull Down for GPIO port C */
2751 CLEAR_BIT(PWR->PDCRC, GPIO_Pin);
2752 break;
2753
2754 case PWR_GPIO_D: /* Disable Pull Down for GPIO port D */
2755 CLEAR_BIT(PWR->PDCRD, GPIO_Pin);
2756 break;
2757
2758 case PWR_GPIO_E: /* Disable Pull Down for GPIO port E */
2759 CLEAR_BIT(PWR->PDCRE, GPIO_Pin);
2760 break;
2761
2762 #ifdef PWR_PUCRF_PU0
2763 case PWR_GPIO_F: /* Disable Pull Down for GPIO port F */
2764 CLEAR_BIT(PWR->PDCRF, GPIO_Pin);
2765 break;
2766 #endif /* PWR_PUCRF_PU0 */
2767
2768 case PWR_GPIO_G: /* Disable Pull Down for GPIO port G */
2769 CLEAR_BIT(PWR->PDCRG, GPIO_Pin);
2770 break;
2771
2772 case PWR_GPIO_H: /* Disable Pull Down for GPIO port H */
2773 CLEAR_BIT(PWR->PDCRH, GPIO_Pin);
2774 break;
2775
2776 #ifdef PWR_PUCRI_PU0
2777 case PWR_GPIO_I: /* Disable Pull Down for GPIO port I */
2778 CLEAR_BIT(PWR->PDCRI, (GPIO_Pin & PWR_PORTI_AVAILABLE_PINS));
2779 break;
2780 #endif /* PWR_PUCRI_PU0 */
2781
2782 #if defined (PWR_PUCRJ_PU0)
2783 case PWR_GPIO_J: /* Disable Pull Down for GPIO port J */
2784 CLEAR_BIT(PWR->PDCRJ, (GPIO_Pin & PWR_PORTJ_AVAILABLE_PINS));
2785 break;
2786 #endif /* defined (PWR_PUCRJ_PU0) */
2787
2788 default:
2789 return HAL_ERROR;
2790 break;
2791 }
2792
2793 return HAL_OK;
2794 }
2795 /**
2796 * @}
2797 */
2798
2799 #endif /* defined (HAL_PWR_MODULE_ENABLED) */
2800
2801 /**
2802 * @}
2803 */
2804
2805 /**
2806 * @}
2807 */
2808
2809 /**
2810 * @}
2811 */
2812