I use a timer to trigger ADC sampling on STM32F401, and the interrupt service routine of ADC will toggle a GPIO pin so that I can measure the ADC sampling frequency using an oscilloscope (which should equal the timer frequency). However the results I get from two scenarios, one being on a Discovery board and the other on my own board, are different. I am wondering if it has something to do with the crystal connection.

In both cases, the CPU frequency is set to be 84 MHz, and the timer frequency is scaled down to 16 kHz. A 8MHz external crystal is also used.

I first test on STM32F401 discovery board which uses STM32F401VCT6. The GPIO pin toggles with 16 kHz frequency. So I think the code is working.

After that I make my own board with the MCU being STM32F401RBT6. I can program and debug the code via SWD without problem, but the GPIO pin toggles with ~5.1kHz frequency. The code is largely same -- the only difference is I use a different ADC pin (thus the corresponding change in the firmware) which should not matter.

The STM32F401 part of schematic of my own design is shown below:


The part of layout related to crystal connection on my board is here:

my xtal layout

The 8MHz crystal on my board is ABLS-8.000MHz-B2-T which needs 18pF loading capacitor. I use two 5% 18pF capacitors. I have probed the oscillator pin with an oscilloscope (despite the probe capacitance may play a role). I can see 8MHz sine-wave like voltage signals, but the amplitude is not from rail to rail.

The crystal part of schematic of STM32F401 discovery board is:

stm32401 discovery board xtal

You can see it has a 220 Ohm series resistor on the PH1-OSC_OUT pin, which I don't have on my board.

Could anyone please advise what I may have done wrong?

  • \$\begingroup\$ I don't think this is your root cause, but one thing that stands out to me is that you used 18pF capacitors to support the required load capacitance. Remember though, that the PCB traces and the pins of the micro itself add stray capacitance that should be factored in. You may actually need less -- maybe 14-16pF capacitors instead after factoring in the parasitics. \$\endgroup\$ Dec 23, 2015 at 23:26
  • \$\begingroup\$ How different is your expected sampling frequency from what's actually happening, as well? \$\endgroup\$ Dec 23, 2015 at 23:27
  • \$\begingroup\$ I can see 8MHz signal on the osc_out pin after probing it with an oscilloscope (although the probe capacitance may also play a role). But at least the crystal oscillator is working to some extent. The measured ADC sampling frequency is 5.12 kHz, but it is supposed to be 16 kHz -- 3.125x slower. \$\endgroup\$
    – shva
    Dec 24, 2015 at 0:13
  • \$\begingroup\$ I can confirm now the slowing down of ADC sampling frequency is related to the slower system clock. The system clock should be 84 MHz, but it is actually 26.88 MHz read from RCC_GetClocksFreq(). The ratio is also 3.125, which is consistent of the ratio of ADC sampling frequency mentioned above. \$\endgroup\$
    – shva
    Dec 24, 2015 at 0:16
  • \$\begingroup\$ Sounds like a mis-configured PLL -- is it locking? \$\endgroup\$ Dec 24, 2015 at 0:17

1 Answer 1


The cause was PLL misconfiguration as suggested by Krunal after reviewing SystemInit() function. Now the clock is working correctly.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.