2014-07-18 06:46 AM
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-scaling2014-08-25 02:44 AM
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);