From a8052d343c133202590b3f6712a9267abee1f5c1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 24 Aug 2017 12:20:26 +1000 Subject: [PATCH] stmhal/modmachine: For F7 MCU, save power by reducing internal volt reg. --- stmhal/modmachine.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c index df75d393c9..81f82e1913 100644 --- a/stmhal/modmachine.c +++ b/stmhal/modmachine.c @@ -363,6 +363,21 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) { // set PLL as system clock source if wanted if (sysclk_source == RCC_SYSCLKSOURCE_PLLCLK) { + #if defined(MCU_SERIES_F7) + // if possible, scale down the internal voltage regulator to save power + uint32_t volt_scale; + if (wanted_sysclk <= 151000000) { + volt_scale = PWR_REGULATOR_VOLTAGE_SCALE3; + } else if (wanted_sysclk <= 180000000) { + volt_scale = PWR_REGULATOR_VOLTAGE_SCALE2; + } else { + volt_scale = PWR_REGULATOR_VOLTAGE_SCALE1; + } + if (HAL_PWREx_ControlVoltageScaling(volt_scale) != HAL_OK) { + goto fail; + } + #endif + #if !defined(MICROPY_HW_FLASH_LATENCY) #define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_5 #endif