summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2022-04-07 16:46:52 +0200
committerDamien George <damien@micropython.org>2022-04-11 16:12:53 +1000
commitbdbc9b395fb19ae7b31e9f4c6116a0bba24addd1 (patch)
treed88b3a554777be4322ff5dbdb8000cec8490f0a7
parent7b3adb5ce583614acd72c14ee343b395190aba76 (diff)
stm32/system_stm32: Add H7 switched-mode-power-supply support.
- Add board-level configuration option to set the SMPS supply mode. - Wait for valid voltage levels after configuring the SMPS mode. - Wait for external supply ready flag if SMPS supplies external circuitry.
-rw-r--r--ports/stm32/boards/STM32H7B3I_DK/mpconfigboard.h3
-rw-r--r--ports/stm32/system_stm32.c25
2 files changed, 24 insertions, 4 deletions
diff --git a/ports/stm32/boards/STM32H7B3I_DK/mpconfigboard.h b/ports/stm32/boards/STM32H7B3I_DK/mpconfigboard.h
index 02f5fcac2..29d00e29e 100644
--- a/ports/stm32/boards/STM32H7B3I_DK/mpconfigboard.h
+++ b/ports/stm32/boards/STM32H7B3I_DK/mpconfigboard.h
@@ -29,6 +29,9 @@
// 6 wait states when running at 280MHz (VOS0 range)
#define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_6
+// SMPS configuration
+#define MICROPY_HW_PWR_SMPS_CONFIG (PWR_DIRECT_SMPS_SUPPLY)
+
#if 0
// 512MBit external OSPI flash, used for either the filesystem or XIP memory mapped
#define MICROPY_HW_OSPIFLASH_SIZE_BITS_LOG2 (29)
diff --git a/ports/stm32/system_stm32.c b/ports/stm32/system_stm32.c
index 2ee745a49..cdbfe925f 100644
--- a/ports/stm32/system_stm32.c
+++ b/ports/stm32/system_stm32.c
@@ -179,15 +179,32 @@ MP_WEAK void SystemClock_Config(void) {
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
- /* Enable Power Control clock */
- #if defined(STM32H7A3xxQ) || defined(STM32H7B3xxQ)
- MODIFY_REG(PWR->CR3, PWR_SUPPLY_CONFIG_MASK, PWR_CR3_SMPSEN);
+ #if defined(STM32H7) && defined(SMPS)
+ // H7 MCUs with SMPS must provide a power supply configuration.
+ MODIFY_REG(PWR->CR3, PWR_SUPPLY_CONFIG_MASK, MICROPY_HW_PWR_SMPS_CONFIG);
#elif defined(STM32H7)
+ // H7 MCUs without SMPS, lock the power supply configuration update.
MODIFY_REG(PWR->CR3, PWR_CR3_SCUEN, 0);
#else
+ // other MCUs, enable power control clock.
__PWR_CLK_ENABLE();
#endif
+ #if defined(STM32H7)
+ // Wait untill the voltage levels are valid.
+ while (!__HAL_PWR_GET_FLAG(PWR_FLAG_ACTVOSRDY)) {
+ }
+
+ #if defined(MICROPY_HW_PWR_SMPS_CONFIG)
+ // If the SMPS supplies external circuitry, wait for the external supply ready flag.
+ if (MICROPY_HW_PWR_SMPS_CONFIG & PWR_CR3_SMPSEXTHP) {
+ while (!__HAL_PWR_GET_FLAG(PWR_FLAG_SMPSEXTRDY)) {
+ }
+ }
+ #endif // defined(MICROPY_HW_PWR_SMPS_CONFIG)
+
+ #endif // defined(STM32H7)
+
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
@@ -202,7 +219,7 @@ MP_WEAK void SystemClock_Config(void) {
#endif
#if defined(STM32H7)
- // Wait for PWR_FLAG_VOSRDY
+ // Wait until core supply reaches the required voltage level.
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {
}
#endif