libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
h7/pwr.h
Go to the documentation of this file.
1/** @defgroup pwr_defines PWR Defines
2
3@brief <b>Defined Constants and Types for the STM32H7xx Power Control</b>
4
5@ingroup STM32H7xx_defines
6
7@version 1.0.0
8
9LGPL License Terms @ref lgpl_license
10 */
11/*
12 * This file is part of the libopencm3 project.
13 *
14 * Copyright (C) 2019 Brian Viele <vielster@allocor.tech>
15 *
16 * This library is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Lesser General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 */
29
30#pragma once
31/**@{*/
32
33/** @defgroup pwr_registers PWR Registers
34@{*/
35/** Power control register. */
36#define PWR_CR1 MMIO32(POWER_CONTROL_BASE + 0x00)
37
38/** Power control/status register. */
39#define PWR_CSR1 MMIO32(POWER_CONTROL_BASE + 0x04)
40
41/** Power control register 2. */
42#define PWR_CR2 MMIO32(POWER_CONTROL_BASE + 0x08)
43
44/** Power control register 3. */
45#define PWR_CR3 MMIO32(POWER_CONTROL_BASE + 0x0C)
46
47/** CPU Power control register 3. */
48#define PWR_CPUCR MMIO32(POWER_CONTROL_BASE + 0x10)
49
50/** D3 Domain Power Control register.
51 * Note: Referred to as PWR_SRDCR (SmartRun Domain Control) on LP devices.
52 * The VOS bitfield differs between the two implementations (unfortunately).
53 */
54#define PWR_D3CR MMIO32(POWER_CONTROL_BASE + 0x18)
55#define PWR_SRDCR MMIO32(POWER_CONTROL_BASE + 0x18)
56
57/** Wakeup Domain Power Control register. */
58#define PWR_WKUPCR MMIO32(POWER_CONTROL_BASE + 0x20)
59
60/**@}*/
61
62/** VOS[15:14]: Regulator voltage scaling output selection */
63#define PWR_CR1_SVOS_SHIFT 14
64#define PWR_CR1_SVOS_MASK (0x3)
65#define PWR_CR1_SVOS_SCALE_3 (0x3)
66#define PWR_CR1_SVOS_SCALE_4 (0x2)
67#define PWR_CR1_SVOS_SCALE_5 (0x1)
68
69/** SmartRun domain AHB memory shut-off in DStop/DStop2 low-power mode */
70#define PWR_CR1_SRDRAMSO BIT27
71/** high-speed interfaces USB and FDCAN memory shut-off in DStop/DStop2 mode */
72#define PWR_CR1_HSITFSO BIT26
73/** GFXMMU and JPEG memory shut-off in DStop/DStop2 mode */
74#define PWR_CR1_GFXSO BIT25
75/** instruction TCM and ETM memory shut-off in DStop/DStop2 mode */
76#define PWR_CR1_ITCMSO BIT24
77/** AHB SRAM2 shut-off in DStop/DStop2 mode */
78#define PWR_CR1_AHBRAM2SO BIT23
79/** AHB SRAM1 shut-off in DStop/DStop2 mode */
80#define PWR_CR1_AHBRAM1SO BIT22
81/** AXI SRAM3 shut-off in DStop/DStop2 mode */
82#define PWR_CR1_AXIRAM3SO BIT21
83/** AXI SRAM2 shut-off in DStop/DStop2 mode */
84#define PWR_CR1_AXIRAM2SO BIT20
85/** AXI SRAM1 shut-off in DStop/DStop2 mode */
86#define PWR_CR1_AXIRAM1SO BIT19
87/** voltage threshold detected by the AVD. */
88#define PWR_CR1_ALS_SHIFT 17
89#define PWR_CR1_ALS_MASK 0x3
90#define PWR_CR1_ALS_1P7V 0x0
91#define PWR_CR1_ALS_2P1V 0x1
92#define PWR_CR1_ALS_2P5V 0x2
93#define PWR_CR1_ALS_2P8V 0x3
94/** peripheral voltage monitor on V DDA enable */
95#define PWR_CR1_AVDEN BIT16
96/** analog voltage ready
97 * This bit is only used when the analog switch boost needs to be enabled (see BOOSTE bit).
98 * It must be set by software when the expected V DDA analog supply level is available.
99 * The correct analog supply level is indicated by the AVDO bit (PWR_CSR1 register) after
100 * setting the AVDEN bit and selecting the supply level to be monitored (ALS bits).
101 */
102#define PWR_CR1_AVD_READY BIT13
103/** analog switch VBoost control
104 * This bit enables the booster to guarantee the analog switch AC performance when the V DD
105 * supply voltage is below 2.7 V (reduction of the total harmonic distortion to have the same
106 * switch performance over the full supply voltage range)
107 * The V DD supply voltage can be monitored through the PVD and the PLS bits.
108 */
109#define PWR_CR1_BOOSTE BIT12
110/** DBP[8]: Disable backup domain write protection. */
111#define PWR_CR1_DBP BIT8
112
113/** CSR1 Register Bits */
114#define PWR_CSR1_MMCVDO BIT17
115#define PWR_CSR1_AVDO BIT16
116#define PWR_CSR1_ACTVOS_SHIFT 14
117#define PWR_CSR1_ACTVOSRDY BIT13
118#define PWR_CSR1_PVDO BIT4
119
120/** CR2 Register Bits */
121/** temperature level monitoring versus high threshold */
122#define PWR_CR2_TEMPH BIT23
123/** temperature level monitoring versus low threshold */
124#define PWR_CR2_TEMPL BIT22
125/** backup regulator ready */
126#define PWR_CR2_BRRDY BIT16
127/** V BAT and temperature monitoring enable */
128#define PWR_CR2_MONEN BIT4
129/** backup regulator enable */
130#define PWR_CR2_BREN BIT0
131
132/** CR3 Register Bits */
133#define PWR_CR3_USB33RDY BIT26
134#define PWR_CR3_USBREGEN BIT25
135#define PWR_CR3_USB33DEN BIT24
136/** SMPS step-down converter external supply ready */
137#define PWR_CR3_SMPSEXTRDY BIT16
138/** V BAT charging resistor selection */
139#define PWR_CR3_VBRS BIT9
140/** V BAT charging enable */
141#define PWR_CR3_VBE BIT8
142
143/** @defgroup pwr_cr3_smpslevel SMPS step-down converter voltage output level selection
144 * This setting is used when both the LDO and SMPS step-down converter are enabled with SMPSEN and
145 * LDOEN enabled or when SMPSEXTHP is enabled. In this case SMPSLEVEL must be written with
146 * a value different than 00 to reach the appropriate voltage, based on VOS or external supply.
147 * @{
148 */
149#define PWR_CR3_SMPSLEVEL_VOS 0x0
150#define PWR_CR3_SMPSLEVEL_1P8V 0x1
151#define PWR_CR3_SMPSLEVEL_2P5V 0x2
152/**@}*/
153#define PWR_CR3_SMPSLEVEL_SHIFT 4
154#define PWR_CR3_SMPSLEVEL_MASK 0x3
155
156/** SMPS step-down converter external power delivery selection */
157#define PWR_CR3_SMPSEXTHP BIT3
158#define PWR_CR3_SCUEN BIT2
159/* BIT2 Is overloaded on devices with SMPS as the SMPSEN bit. */
160#define PWR_CR3_SMPSEN BIT2
161#define PWR_CR3_LDOEN BIT1
162#define PWR_CR3_BYPASS BIT0
163
164/** D3CR Register Bits */
165#define PWR_D3CR_VOSRDY BIT13
166#define PWR_D3CR_VOS_SHIFT 14
167#define PWR_D3CR_VOS_MASK (0x03)
168/** VOS0 is implemented on STM32H72x/3x with simple VOS setting.
169 * STM32H742/43/45/47/50/53/55/57 SCALE0 this as SCALE1 + SYSCFG.ODEN */
170#define PWR_D3CR_VOS_SCALE_0 (0x0)
171#define PWR_D3CR_VOS_SCALE_3 (0x1)
172#define PWR_D3CR_VOS_SCALE_2 (0x2)
173#define PWR_D3CR_VOS_SCALE_1 (0x3)
174/** SRDCR Register Bits */
175#define PWR_SRDCR_VOSRDY BIT13
176#define PWR_SRDCR_VOS_SHIFT 14
177#define PWR_SRDCR_VOS_MASK (0x03)
178#define PWR_SRDCR_VOS_SCALE_3 (0x0)
179#define PWR_SRDCR_VOS_SCALE_2 (0x1)
180#define PWR_SRDCR_VOS_SCALE_1 (0x2)
181#define PWR_SRDCR_VOS_SCALE_0 (0x3)
182
184 PWR_SYS_SCU_LDO = 0, /**< STM32H742/43/50/53 has special SCUEN handling, use for LDO. */
185 PWR_SYS_SCU_BYPASS, /**< STM32H742/43/50/53 has special SCUEN handling, use for bypass. */
186 PWR_SYS_LDO, /**< Devices with SMPS use this to run from LDO only. */
187 PWR_SYS_SMPS_DIRECT, /**< Disable LDO, apply SMPS direct to CPU using VOS. */
188 PWR_SYS_SMPS_LDO, /**< SMPS supplies internal LDO. */
189 PWR_SYS_EXT_SMPS_LDO, /**< SMPS supplies external power, and CPU through LDO. */
190 PWR_SYS_EXT_SMPS_LDO_BYP, /**< SMPS supplies external power, bypasses LDO (e.g. external LDO) */
191 PWR_SYS_BYPASS /**< Disable all internal power supplies. */
193
198};
199
206};
207
209
210/** @defgroup pwr_peripheral_api PWR Peripheral API
211 * @ingroup peripheral_apis
212@{*/
213/** Set power subsystem to utilize the LDO for CPU. */
214void pwr_set_mode_ldo(void);
215
216/** Specific STM32H742/43/50/53 LDO mode setting.. */
217void pwr_set_mode_scu_ldo(void);
218
219/** Set power subsystem to utilize the SMPS run through the LDO for CPU.
220 * @param[in] supply_external Supply is powering external circuits, enable high power mode.
221 * @param[in] smps_level Voltage level from @ref pwr_cr3_smpslevel (1.8V/2.5V)
222 * @param[in] use_ldo Set this value to true if the internal LDO should be enabled.
223 */
224void pwr_set_mode_smps_ldo(bool supply_external, uint32_t smps_level, bool use_ldo);
225
226/** Set power system based on "System Supply Configurations" table in reference manual.
227 * @param[in] mode Mode mapping to a mode in the system configuration. Note special SCU modes.
228 * @param[in] smps_level Optional, only needed if using an EXT_SMPS or SMPS_LDO mode.
229 * Provide zero if unused, otherwise @ref pwr_cr3_smpslevel.
230 */
231void pwr_set_mode(enum pwr_sys_mode mode, uint8_t smps_level);
232
233/** Set power subsystem to bypass all internal supplies. */
234void pwr_set_mode_bypass(void);
235
236/** Specific STM32H742/43/50/53 Bypsass mode setting.. */
237void pwr_set_mode_scu_bypass(void);
238
239/** Set the voltage scaling/strength for the internal SMPS/LDO when in Stop mode.
240 * @param[in] scale Voltage scale value to set.
241 */
242void pwr_set_svos_scale(enum pwr_svos_scale scale);
243
244/** Set the voltage scaling/strength for the internal SMPS/LDO while running.
245 * @param[in] scale Voltage scale value to set.
246 */
247void pwr_set_vos_scale(enum pwr_vos_scale scale);
248/**@}*/
249
250
252
253/**@}*/
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
#define PWR_CR1_SVOS_SHIFT
VOS[15:14]: Regulator voltage scaling output selection.
Definition: h7/pwr.h:63
pwr_svos_scale
Definition: h7/pwr.h:194
#define PWR_CR1_SVOS_SCALE_4
Definition: h7/pwr.h:66
pwr_vos_scale
Definition: h7/pwr.h:200
#define PWR_CR1_SVOS_SCALE_5
Definition: h7/pwr.h:67
#define PWR_CR1_SVOS_SCALE_3
Definition: h7/pwr.h:65
pwr_sys_mode
Definition: h7/pwr.h:183
@ PWR_SVOS_SCALE4
Definition: h7/pwr.h:196
@ PWR_SVOS_SCALE5
Definition: h7/pwr.h:197
@ PWR_SVOS_SCALE3
Definition: h7/pwr.h:195
@ PWR_VOS_SCALE_2
Definition: h7/pwr.h:204
@ PWR_VOS_SCALE_1
Definition: h7/pwr.h:203
@ PWR_VOS_SCALE_0
Definition: h7/pwr.h:202
@ PWR_VOS_SCALE_3
Definition: h7/pwr.h:205
@ PWR_VOS_SCALE_UNDEFINED
Definition: h7/pwr.h:201
@ PWR_SYS_SMPS_DIRECT
Disable LDO, apply SMPS direct to CPU using VOS.
Definition: h7/pwr.h:187
@ PWR_SYS_EXT_SMPS_LDO
SMPS supplies external power, and CPU through LDO.
Definition: h7/pwr.h:189
@ PWR_SYS_SMPS_LDO
SMPS supplies internal LDO.
Definition: h7/pwr.h:188
@ PWR_SYS_SCU_LDO
STM32H742/43/50/53 has special SCUEN handling, use for LDO.
Definition: h7/pwr.h:184
@ PWR_SYS_LDO
Devices with SMPS use this to run from LDO only.
Definition: h7/pwr.h:186
@ PWR_SYS_EXT_SMPS_LDO_BYP
SMPS supplies external power, bypasses LDO (e.g.
Definition: h7/pwr.h:190
@ PWR_SYS_BYPASS
Disable all internal power supplies.
Definition: h7/pwr.h:191
@ PWR_SYS_SCU_BYPASS
STM32H742/43/50/53 has special SCUEN handling, use for bypass.
Definition: h7/pwr.h:185
void pwr_set_svos_scale(enum pwr_svos_scale scale)
Set the voltage scaling/strength for the internal SMPS/LDO when in Stop mode.
Definition: pwr.c:110
void pwr_set_mode_ldo(void)
Set power subsystem to utilize the LDO for CPU.
Definition: pwr.c:43
void pwr_set_vos_scale(enum pwr_vos_scale scale)
Set the voltage scaling/strength for the internal SMPS/LDO while running.
Definition: pwr.c:117
void pwr_set_mode_bypass(void)
Set power subsystem to bypass all internal supplies.
Definition: pwr.c:72
void pwr_set_mode_scu_bypass(void)
Specific STM32H742/43/50/53 Bypsass mode setting.
Definition: pwr.c:77
void pwr_set_mode_smps_ldo(bool supply_external, uint32_t smps_level, bool use_ldo)
Set power subsystem to utilize the SMPS run through the LDO for CPU.
Definition: pwr.c:54
void pwr_set_mode_scu_ldo(void)
Specific STM32H742/43/50/53 LDO mode setting.
Definition: pwr.c:49
void pwr_set_mode(enum pwr_sys_mode mode, uint8_t smps_level)
Set power system based on "System Supply Configurations" table in reference manual.
Definition: pwr.c:83