Skip to content

Commit b49766f

Browse files
belolapcfriedt
authored andcommitted
drivers: clock_control: More power supply modes for STM32H7
STM32H7 has different power supply modes but now Zephyr supports just LDO and direct SMPS. This commit introduses POWER_SUPPLY_CHOICE configuration parameter and add support for missed power supply modes. Signed-off-by: Gennady Kovalev <[email protected]> Fixes #40730.
1 parent 868c002 commit b49766f

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

drivers/clock_control/clock_stm32_ll_h7.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,28 @@ static uint32_t get_hclk_frequency(void)
259259

260260
static int32_t prepare_regulator_voltage_scale(void)
261261
{
262-
/* Make sure to put the CPU in highest Voltage scale during clock configuration */
263-
#if defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS)
262+
/* Apply system power supply configuration */
263+
#if defined(SMPS) && defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS)
264264
LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY);
265+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO)
266+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_LDO);
267+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO)
268+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_LDO);
269+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO)
270+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO);
271+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO)
272+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO);
273+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT)
274+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT);
275+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT)
276+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT);
277+
#elif defined(CONFIG_POWER_SUPPLY_EXTERNAL_SOURCE)
278+
LL_PWR_ConfigSupply(LL_PWR_EXTERNAL_SOURCE_SUPPLY);
265279
#else
266280
LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY);
267281
#endif
282+
283+
/* Make sure to put the CPU in highest Voltage scale during clock configuration */
268284
/* Highest voltage is SCALE0 */
269285
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE0);
270286
return 0;
@@ -280,8 +296,22 @@ static int32_t optimize_regulator_voltage_scale(uint32_t sysclk_freq)
280296
/* LL_PWR_REGULATOR_SCALE3 is lowest power consumption */
281297
/* Must be done in accordance to the Maximum allowed frequency vs VOS*/
282298
/* See RM0433 page 352 for more details */
283-
#if defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS)
299+
#if defined(SMPS) && defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS)
284300
LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY);
301+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO)
302+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_LDO);
303+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO)
304+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_LDO);
305+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO)
306+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO);
307+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO)
308+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO);
309+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT)
310+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT);
311+
#elif defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT)
312+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT);
313+
#elif defined(CONFIG_POWER_SUPPLY_EXTERNAL_SOURCE)
314+
LL_PWR_ConfigSupply(LL_PWR_EXTERNAL_SOURCE_SUPPLY);
285315
#else
286316
LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY);
287317
#endif

soc/arm/st_stm32/common/Kconfig.soc

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,36 @@ config USE_STM32_ASSERT
2222
help
2323
Enable asserts in STM32Cube HAL and LL drivers.
2424

25-
config POWER_SUPPLY_SMPS
26-
bool "Enable STM32 internal SMPS"
25+
choice POWER_SUPPLY_CHOICE
26+
prompt "STM32 power supply configuration"
27+
default POWER_SUPPLY_LDO
2728
depends on SOC_SERIES_STM32H7X
28-
help
29-
Enable SMPS Power Supply.
29+
30+
config POWER_SUPPLY_LDO
31+
bool "LDO supply"
32+
33+
config POWER_SUPPLY_DIRECT_SMPS
34+
bool "Direct SMPS supply"
35+
36+
config POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO
37+
bool "SMPS 1.8V supplies LDO (no external supply)"
38+
39+
config POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO
40+
bool "SMPS 2.5V supplies LDO (no external supply)"
41+
42+
config POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO
43+
bool "External SMPS 1.8V supply, supplies LDO"
44+
45+
config POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO
46+
bool "External SMPS 2.5V supply, supplies LDO"
47+
48+
config POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT
49+
bool "External SMPS 1.8V supply and bypass"
50+
51+
config POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT
52+
bool "External SMPS 2.5V supply and bypass"
53+
54+
config POWER_SUPPLY_EXTERNAL_SOURCE
55+
bool "Bypass"
56+
57+
endchoice

soc/arm/st_stm32/stm32h7/soc_m7.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,32 @@ static int stm32h7_init(const struct device *arg)
8080
SystemCoreClock = 64000000;
8181

8282
/* Power Configuration */
83-
#if defined(SMPS) && defined(CONFIG_POWER_SUPPLY_SMPS)
84-
LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY);
85-
#elif defined(CONFIG_POWER_SUPPLY_SMPS)
83+
#if !defined(SMPS) && \
84+
(defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS) || \
85+
defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO) || \
86+
defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO) || \
87+
defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO) || \
88+
defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO) || \
89+
defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT) || \
90+
defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT))
8691
#error Unsupported configuration: Selected SoC do not support SMPS
92+
#endif
93+
#if defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS)
94+
LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY);
95+
#elif defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO)
96+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_LDO);
97+
#elif defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO)
98+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_LDO);
99+
#elif defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO)
100+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO);
101+
#elif defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO)
102+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO);
103+
#elif defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT)
104+
LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT);
105+
#elif defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT)
106+
LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT);
107+
#elif defined(CONFIG_POWER_SUPPLY_EXTERNAL_SOURCE)
108+
LL_PWR_ConfigSupply(LL_PWR_EXTERNAL_SOURCE_SUPPLY);
87109
#else
88110
LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY);
89111
#endif

0 commit comments

Comments
 (0)