Solved
CubeMX creates broken SystemClock_Config()
Posted on November 04, 2016 at 13:42
In STM32Cube MX 4.17 I have set up an empty STM32L476 Nucleo project with and created code for the Low-Layer API. The parameters were:
- LL_PWR_REGU_VOLTAGE_SCALE2
- LL_RCC_MSIRANGE_8
SystemClock_Config() of the generated code starts with
void SystemClock_Config(void)
{
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE2);
LL_RCC_MSI_Enable();
/* Wait till MSI is ready */
while(LL_RCC_MSI_IsReady() != 1)
{
}
LL_RCC_MSI_EnableRangeSelection();
LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_8);
LL_RCC_MSI_SetCalibTrimming(0);
LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_2)
{
Error_Handler();
}
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
⋮
The documentation (DocID024597 Rev 4, section 5.1.7 Dynamic voltage scaling management)
reasonably states that the FLASH latency must be set up
before the core voltage is changed.
However the function SystemClock_Config() does it the other way around. This may work under limited conditions…
#cubemx-flash-latency