Skip to main content
adam23
Associate II
July 18, 2014
Question

Voltage scaling: way to set 1.5V/16MHz

  • July 18, 2014
  • 1 reply
  • 810 views
Posted on July 18, 2014 at 15:46

I would like to set a Vcore voltage range to 1.5V and then back to default 1.8V on STM32L1xx for some code execution. I did not found anywhere the correct procedure, what everything has to be change, but generally it only seems the FLASH WS needs to be changed too.

Here is what I came to:

      FLASH_SetLatency(FLASH_Latency_1);

      /* Set internal voltage regulator to 1.5V */

      PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);

      /* Wait Until the Voltage Regulator is ready */

      while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

      /* Some code here */

      /* Set internal voltage regulator to 1.8V */

      PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);

      /* Wait Until the Voltage Regulator is ready */

      while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

      FLASH_SetLatency(FLASH_Latency_0);

But after this it ends up in a HardFault. What else needs to be done to dynamically scale the voltage like this?

#stm32l1-voltage-scaling
This topic has been closed for replies.

1 reply

adam23
adam23Author
Associate II
August 25, 2014
Posted on August 25, 2014 at 11:44

OK the problem is that you have to also enable 64b access together with 1WS - this is not obvious from the doc. Otherwise the flash reads are incorrect resulting in HardFault.

E.g.:

/* Enable 64-bit access */

FLASH_ReadAccess64Cmd(ENABLE);

/* Change flash WS */

FLASH_SetLatency(FLASH_Latency_1);

/* Set internal voltage regulator to 1.5V */

PWR_VoltageScalingConfig(PWR_VoltageScaling_Range2);

/* Wait Until the Voltage Regulator is ready */

while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

/* Some code here */

/* Set internal voltage regulator to 1.8V */

PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);

/* Wait Until the Voltage Regulator is ready */

while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;

/* Set flash latency to 0WS */

FLASH_SetLatency(FLASH_Latency_0);

/* Disable 64-bit access */

FLASH_ReadAccess64Cmd(DISABLE);