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.
This commit is contained in:
iabdalkader 2022-04-07 16:46:52 +02:00 committed by Damien George
parent 7b3adb5ce5
commit bdbc9b395f
2 changed files with 24 additions and 4 deletions

View File

@ -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)

View File

@ -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