Frequency multiplier on GPIO with STM32

I want to input an external clock signal to the STM32 and output a clock signal with the same phase and 4 times the frequency of the original clock. For example, I have a 6MHz input clock on pin PA1 and output a 24MHz clock on pin PA2.

How could this be done?

So far I tried to use timers, but the problem is that on a STM32H723 the APB1 has 275MHz and this would result in 11.45833 counts for a 24Mhz clock. Since counting is done in integer, the closest rounded value would be 11 and therefore a frequency error of about 4.2% would occur. I would then have a 25Mhz clock, which is not what I am looking for.


  • What you're looking for is a PLL, which is essentially a mixed-signal circuit i.e. one which has digital part (for the divider) and analog part (phase comparator and voltage-controlled oscillator). There's at least one in every STM32, but it's usually dedicated to its basic clocking functionality.

    However, you can use it for your purpose - your input signal would be used as an external HSE oscillator (check if its range fits you in the given STM32's datasheet), PLL set to multiply by 4, and output of PLL output on the MCO pin. You then can clock the rest of the chip either from this signal or e.g. from HSI.

    The lower-end STM32 may be more suitable for this purpose than the overcomplicated 'H7, as they are way easier to set up. OTOH, in some of the newest 'U5/'H5 families there may be multiple PLLs in RCC one of which maybe could be pressed into such use; these are complicated chips and I am not going to study them in enough detail now to find out if this is the case.

    If this is not a viable option for you, you have to resort to external circuitry, as @Ben Voigt said above.