summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-08-24 12:20:26 +1000
committerDamien George <damien.p.george@gmail.com>2017-08-24 12:20:26 +1000
commita8052d343c133202590b3f6712a9267abee1f5c1 (patch)
tree31663f0a6cc5f0808139d9ed608db6319041a939
parent41b4686dd75fde815cf9c12593f223b4305e54f9 (diff)
stmhal/modmachine: For F7 MCU, save power by reducing internal volt reg.
-rw-r--r--stmhal/modmachine.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c
index df75d393c..81f82e191 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