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!
And how about flash latency? Normally flash runs at maximum speed of 24MHz, therefore the processor has to wait for instructions for longer than 2 cycles. So is the flash also read faster? I can’t believe that.
@Medved
I don’t know if flash is running faster, as I haven’t tried reading/writing to flash when overclocked. Though I think you will experience problems when trying to access the flash!
Best Regards
Thomas Jespersen
Hi!
Nice piece of code. Sharing is caring 🙂
I have tried it with STM32 Discovery running STM32F100RBT6B (Medium Density Value Line). It works OK up to 64 MHz. 72 MHz and over gives me HardFault interrupt. Maybe I am doing something wrong… But with different configurations and trying out to set up default configuration to 72 MHz (changing system_stm32f10x.c) didn’t help.
So far I am happy. I need higher frequency to set more precise timer clock. Do you have a clue how will power demands after changing the clock (higher, lower, depends on the code)?
@Radzick
Dear Radzick.
Wow, I’m really amazed that you could overclock it that far.
It doesn’t surprise me that it doesn’t work at 72MHz, which is 3 times the specified maximum clock.
About the power consumption it is definitely going to rise when overclocking – the same happens with the heat.
Thomas
Hello guys
I tested the STM32F103VET6 in 128MHz and it worked good without any failure.without overheating problem at 3.3v power supply.But i think USB can not work in this situation because it requires 48MHz.”If the USB interface is used in the application, the PLL must be programmed to output 48 or
72 MHz. This is needed to provide a 48 MHz USBCLK.”
Best Regards
Farhad Rouzdar
From Azerbaijan
I had tried to use 8MHz crystal, PLL 16 to 128Mhz, the system, LCD, Flash read write, all works good.