Configuring SysClk on STM32L152 to 32MHz using SPL
Hey guys and gals! I am facing a persistent problems when configuring system clock on the STM32L152 to 32MHz using SPL. It smoothly runs at 24MHz but always freezes when making it to run at its maximum freq.
The MCU's max clock frequnecy is 32MHz and it runs just fine when configuring the clock using STM32CUBE IDE and HAL. The intention is to run it from HSI (16MHz) via the PLL in this way:
It refuses to work in my SPL-based code, although the procedure seems to be the exact analogy to the HAL code:
void init32MHzClock() {
RCC_DeInit();
FLASH_SetLatency(FLASH_Latency_1);
PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK
RCC_PCLK1Config(RCC_HCLK_Div1); // PCLK1 = HCLK
RCC_AdjustHSICalibrationValue(0x10U); // default HSI calibration trimming value
RCC_HSICmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) != SET);
// PLL clock from 16 MHz HSI:
RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_4, RCC_PLLDiv_2); // 16*4/2 = 32MHz
// RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_6, RCC_PLLDiv_4); // 16*6/4 = 24MHz
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) != SET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // select the PLL as clock source.
while(RCC_GetSYSCLKSource() != 0x0C); // wait till PLL is used as system clock
SystemCoreClock = 32000000;
}It never goes beyond the last while on line 23. All the code I had googled is mostly related to other MCUs (mostly F103), and there seems not to be anything that different in the architecture. Could any of you, please spot a difference or a missing piece and advise? Cheers!
