# Ways to observe clock signal of an STM32 MCU

Is there a nice way to be able to observe the clock signal in an oscilloscope to validate my settings for clock speed? After setting it to 168 MHz with PLL for an STM32F407VGT6 MCU let's say.

• Most MCUs feature some sort of "clock out" feature for this purpose. Though you could just implement something like a simple periodic timer based on ARM CMSIS "SysTick", then have that one toggle a GPIO periodically, and measure the GPIO with your scope. Jun 2, 2020 at 8:07
• @Lundin in such case, I won't divide frequency for timer right? I mean Prescaler will be 0 for example Jun 2, 2020 at 8:18

Directly from the reference manual, pay attention to the last line.

Without oscilloscope you can use TIM5 to perform a comparison between two clocks.
Since TIM5 can input capture from LSI or LSE, you can compare the SYSCLK (the one TIM5 is running on) with any of those. TIM11 can do HSE.
Which is described in detail in chapter: 6.2.11 Internal/external clock measurement using TIM5/TIM11

I'd recommend to do this before using a crystal to check whether it is the expected freqeuncy.

• Ok, so if I configure my clock speed to 84 MHz by PLL instead of 168 MHz, then I should be able to observe 84 MHz clock signal directly from MCO1 pin, if I configure it to output PLL clock, of course. Right? Jun 2, 2020 at 8:53
• @muyustan each clockout pin has a configurable prescaler. This means you can look at internal clocks up to 500 MHz. Jun 2, 2020 at 9:26

Some ideas

1. Configure SysTick timer to tick after 1680000 clocks (10ms) and toggle a LED/GPIO each 100 interrupts to get 1s update rate (the signal will have frequency of 0.5Hz). The interrupt and SW processing will introduce some jitter to the signal, so it is not good for clock calibration, but it is still good to recognize wrong PLL settings.
2. Configure one of the timers as PWM output. This will have less jitter, but some timers are not running at AHB speed or even APB1/2 speeds, so it's not very reliable to detect doubled/halved speed etc. However if you're after reading the exact oscillator speed, you may use this with combination with the previous step.
3. Reading the value with RCC_GetClocksFreq, but it is NOT always reliable, as the library will usually tell you the value you asked for, especially if it thinks your crystal frequency is of a different value than in thinks.
• why did you do "frequency of 0.5 Hz" edit? Isn't it 1 Hz ? Jun 2, 2020 at 8:28
• If the led toggles each second, the signal will not be really 1Hz but half the speed. In other words, the toggle changes the phase of the signal by 180° so it takes two interrupts to complete the cycle. The scope would show 0.5Hz. I've made this error before, so I think it is good to mention on this topic. I've accidentally overclocked my STM32F103 to 144Mhz :-) Jun 2, 2020 at 8:34
• ok, so the toggle you are talking about is as follows: LED ON for 1 second and OFF for 1 second and keeps going, right? Jun 2, 2020 at 8:50
• Yes, that was what I meant. I've edited the response to be more clear. Jun 2, 2020 at 9:12