6 years, 6 months ago.

How to increase clock frequency on STM32F103 Nucleo

I have made settings on STM32F103 Nucleo, as per Nucleo datasheet, for HSE oscillator on-board from X3 crystal (not provided) and added a crystal at the place of X3, crystal is of 24MHz

after that I tested following sample codes from EMBED with results noted

1. Nucleo_printf, it ran as it was working with 8MHz (it sent string identical as with 8MHz) 2. Nucleo_blink_led, the LED blinks with the same rate as it was with 8MHz, I was expecting 3 times faster blink

please suggest how to make controller run with crystal frequency noted on external crystal body

Best Regards & Thanks in advance

1 Answer

6 years, 6 months ago.

First of all make sure you use the latest mbed libs with the Nucleo blink code (right click on mbed.bld in your program and select update). The default Blinky example download may have a very old version of the lib. Recent versions of the lib will automatically detect an external xtal and switch between either the external xtal, clocksource or the internal oscillator.

The external xtal should be 8 MHz and not 24 MHz. Different xtals will require modifications in the mbed lib source for the Nucleo. The ST32F103 and other ARM cores use PLLs to control their clockspeed. Dont mess with the xtals unless you read and understand the device usermanual. The values for external clock and internal PLL, busspeeds etc must be within certain ranges or the processor will not work correctly.

The standard Blinky code should obviously not run 3x faster when you use the wait() methods. The wait() method is supposed to provide a constant delay independent from the controller clockspeed. It uses timers that are always corrected for the clockspeed assuming the external clock value matches the defined values in the mbed lib (ie 8 MHz). Similar corrections are performed in the mbed libs to make sure that UART baudrates, I2C and SPI clockspeeds match with settings that you provide as parameter.

#include "mbed.h"
DigitalOut myled(LED1);
int main() {
    while(1) {
        myled = 1; // LED is ON
        wait(0.2); // 200 ms
        myled = 0; // LED is OFF
        wait(1.0); // 1 sec

If you want to check the current processor clockspeed use

 pc.printf("SystemCoreClock = %d", SystemCoreClock);

Accepted Answer