STM32 – Overclocking
Have you ever wondered if it was possible to overclock the STM32? It is, with a simple change in code line!
We only have to change the PLL setting, which is able to go up to 16 – so that means that we can overclock the STM32 up to 8MHz x 16 = 128 MHz
Here is the RCC Initialization code for 128MHz – remember, you also have to comment the “SYSCLK_FREQ_72MHz”, uncomment the “SYSCLK_FREQ_HSE” and set it to 128MHz in the system_stm32f10x.c
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
//RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* PLLCLK = 8MHz * 16 = 128 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_16);
// The frequency has also been changed in system_stm32f10x
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{;}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{;}
}
/* Enable peripheral clocks --------------------------------------------------*/
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG
| RCC_APB2Periph_AFIO, ENABLE);
}
How do you get the USB clock to 48MHz or will this only work for non-usb applications?
About the USB clock I’m not sure, as I haven’t done any projects with USB yet!
But I think if you chose to go with 128MHz, you just have to change the USB PLL to a higher value.
Thomas
How is reliability? Does it work sometimes, or will this work reliably? Will the cortex heat up (overheat)? Can the peripherals, namely the ADC work faster (maybe losing a bit or two in reliable resolution)?
regards,
Mox
Dear Mox.
I haven’t had any problems when running at 128MHz, but I don’t know about the ADC, but that would definitely also run faster, but I don’t know if any problems would occour then!
You have to try it out – also the STM32 won’t be damaged or heat up when overclocking.
Best Regards
Thomas Jespersen
128Mhz is just the beginnigng . About two months ago i plugged 25Mhz crystal on board for Ethernet STM32F107 family when i was changing developmnet platform from STM32F103 at 8MHz clock. PLL was set to 72Mhz when 8MHz crystal was mounted. I did’nt change PLL’s configuration for STM32F107, and guess what? It was working ! at 225 MHz with FreeRTOS onboard. Led was blinking faster, PWM was goin faster, UART to !
Amazing that it works, but it won’t work reliably.
The problem is that the chip and the things inside it isn’t made for speeds that fast, so I think you would see that the chip will go into the Hard Fault routine most of the time!