AnsweredAssumed Answered

CubeMX creates broken SystemClock_Config()

Question asked by kleier.hermann on Nov 4, 2016
Latest reply on Apr 1, 2017 by Oller.Sebastian.002
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
The function 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…

Outcomes