Library 40- Output clocks from STM32F4

STM32F4 has capability to output different clocks on specific 2 pins. You are able to output clocks in original frequency (no prescaler) and also with prescaler values 2, 3, 4 and 5.

2 pins are used to output different frequencies. They are not able to output the same clocks. You can output:

  • MCO1
    • HSI: High Speed Internal oscillator, 16MHz RC
    • HSE: High Speed External oscillator, or External User clock
    • LSE: Low speed, 32768Hz oscillator or ceramic resonator
    • PLLCLK: Output clock from PLL
      • Differ between settings for PLL
  • MCO2
    • SYSCLK: System core clock output
    • PLLI2SCLK: Accurate clock for high-quality audio performance in I2S and SAI interfaces
    • HSE: High Speed External oscillator, or External User clock
    • PLLCLK: Output clock from PLL
      • Differ between settings for PLL

Each clock can be output with no prescaler, or value between 2 – 5.



  • Output different system clocks from STM32F4
  • 2 output pins supported


    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
  • TM
    • TM GPIO
    • defines.h
STM32F4xx MCOx Description
PA8 MCO1 MCO1 output pin
PC9 MCO2 MCO2 output pin

Functions and enumerations


Example below outputs:

  • HSI clock on pin MCO1 (PA8) with prescaler 2 = 16MHz / 2 = 8MHz
  • SYSCLK clock on pin MCO2 (PC9) with prescaler 4
    • On STM32F4-Discovery = 168MHz / 4 = 42MHz
    • On STM32F429-Discovery = 180MHz / 4 = 45MHz
    • On Nucleo F401RE = 84MHz / 4 = 21MHz

Project is available on Github, download library below.

TM STM32F4 MCO Output Library

Output different clocks from STM32F4


Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Pingback: All STM32F4 libraries - STM32F4 Discovery()

  • Petr Machala


    what do you think about the 32F429IDISCOVERY wiring? I mean that both MCO outputs are used for touchscreen. I find this very unfortunate…

    • Cant do anything gere :))

      • Petr Machala

        yeah I know but I need both 🙂 … now I need to use some kind of timer…I would like to know why they made it like that…

        • Which clock is the one you need?

          • Petr Machala

            What do you mean? I dont care…now I use MCO1 but I’ll have to swap it for something else…

          • MCO can output more than just one clock.
            So which one you need? HSE, HSI, SYSCLK, etc?

          • Petr Machala

            yeah but the pin will be used by a touch screen…forget it…I have bugger problems right now 🙂

          • mukhe

            I saw what you did with your code for the ov7670 control, have the same problem now. I used your way of assigning a GPIO for providing the output but somehow it just shows a clock speed of 1.7Mhz using the PA9

            I checked if i could get something out from PA8 but even if i have
            RCC_MCO1Config(RCC_MCO1Source_HSI, RCC_MCO1Div_1);// 16MHZ
            it still only gives me 4Mhz max. weird