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.
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.
- 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.
- 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.
- 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.