2
\$\begingroup\$

I'm currently designing a PCB based on a STM32 micro-controller (more precisely a STM32F722ZE).

The question is : do I need a high speed clock (or is the internal good enough)? If so, what crystal and what capacitors should I use?

In terms of timing accuracy, the manual gives 1% accuracy for the internal 16MHz RC-clock. Regarding absolute time, I don't care. But will it matter for communication protocols? I'm planning of the STM32 to be a I2C slave, and to control by UART 2 1D lidars; I might in addition use later on the STM32 as I2C or SPI master. No ethernet planed. No direct USB planned (only programming through the ST-Link V2 of a Nucleo board). So do you think I need an external clock (crystal + capacitors).

If I need some, which crystal and capacitors should I use? (Ideally, If you have a reference available for assembly at JLCPCB (through EasyEda), it would be perfect).

So far, what I tried:

  • the datasheet of the microcontroller: I got from there the information about the 1% accuracy (3.12). There is a bit more info about it at 6.3.9, but it isn't precise enough to enable me to find the right components

  • the application note about hardware development for the STM32F7 series: a quite useful document for most of the design, but still not precise enough to enable me to find the right crystal + capacitors (they discuss the clock in sections 3, 7.1 and 7.2, but the concrete example (7.1/7.2) only proposes a 25MHz crystal but without specifying which one, nor how to pick the right capacitors for it

  • there is a whole application note of 36 pages about choosing crystals: I suppose if one manage to understand all of it, one can pick the right crystal + capacitors. But I must admit I didn't understood much of it.

  • I tried to look at the schematics of the Nucleo development board I use with the same micro-controller, but the clock is provided from another micro-controller instead of using a crystal. I tried with other boards, so far without success (clock provided by other µC, or crystal not available for assembly at JLCPCB)

PS: can you confirm that I don't need the low speed external clock if I don't care about the RTC (real time clock)?

EDIT : so I got the impression from your answers that even if it might work without crystall, I should use on to be sure. So the question is how to choose it. Do you think that one will do (that one comes nearlly for free because it's a "standard" part at manufacturer, for other models they add a labor fee to load the components): https://www.lcsc.com/product-detail/Crystals_Yangxing-Tech-X322525MOB4SI_C9006.html and https://datasheet.lcsc.com/lcsc/2103291203_Yangxing-Tech-X322525MOB4SI_C9006.pdf The datasheets don't give load capacitor, but on the LCSC link, they give 12pF : you think it's safe to go for that number even if it is missing from the datasheet itself?

Then for calculating the value of the load capacitors C1 and C2 (usually C1=C2 from what I understand):

  • I need a total load capacitance CL=12pf
  • the oscillator choosing guide (section 3.3) gives CL=C1*C2/(C1+C2) + Cs where Cs is the stray capacitor
  • hardware development for the STM32F7 series application note (section 3.1.2) gives, if I understand well, Cs=10pF as a rough estimate
  • so I get 12pF=C1/2 + 10pF -> C1=4pF Does that seem OK for you? Do you think I can just go allong with the Cs=10pF estimation? (C1 is quite sensitive to it : if Cs is 20% bigger, C1 becomes 0, if Cs is 20% smaller, it doubles C1) Or should I try to find another crystal with bigger load capacitance to be safer?

Once this calculation done, is there anything else to take into account?

For the capacitors, can I take whatever capacitor around 2pF, or should I be carefull about some other factors (tight tolerance? temperature stability? ...)

\$\endgroup\$

4 Answers 4

2
\$\begingroup\$

If this is for a hobby project, I've found a cheap canned oscillator (less than 1€) is a worthy option compared to spending an hour or two pondering about what crystal to use and what load capacitor values it needs...

\$\endgroup\$
5
  • \$\begingroup\$ yes, it's a hobby project, so ne problem in increasing the price of 1€. However, I'm not sure what you mean by "canned oscillator"? Is it an oscillator with everything included in it? Or a clock genrator? \$\endgroup\$
    – Sandro
    Dec 11, 2021 at 12:25
  • 1
    \$\begingroup\$ These mouser.fr/c/passive-components/frequency-control-timing-devices/… \$\endgroup\$
    – bobflux
    Dec 11, 2021 at 12:36
  • \$\begingroup\$ Thanks a lot! I seems a far simpler solution! So if I go for example for this one : datasheet.lcsc.com/lcsc/… They mention 30pF output load : does that mean that I should add a 20pF capacitor? (in adition to the estimated 10pF stray capacitor). As the 10pF is a rough estimation, should I better aim for a bit more or a bit less, or to be as near as possible? Or that it should be bellow 30pF (in that case, I add nothing)? \$\endgroup\$
    – Sandro
    Dec 11, 2021 at 13:39
  • 1
    \$\begingroup\$ "30pF load" refers to the maximum capacitance that the output can drive, so that's the trace capacitance plus input capacitance the micro's clock input pin. That'll be much lower than 30pF so no worry. Don't add a capacitor on the output! You can add the usual 100nF decoupling cap on the power pin, or stick it next to one of the micro's decoupling caps. Note these clocks use more power than a crystal on the micro, so not recommended for battery use, but if you're not using a battery, it saves headaches lol. \$\endgroup\$
    – bobflux
    Dec 11, 2021 at 15:31
  • \$\begingroup\$ Thanks a lot! My robot is baterry powered, but it's a big battery (3S 4800mAh lipo), and the motors will consume a few amps, so I don't care about a 20mA more or less \$\endgroup\$
    – Sandro
    Dec 11, 2021 at 15:41
3
\$\begingroup\$

Only if you intend to run the MCU at stable 25 degrees C and stable 3.3V supply, the HSI oscillator is guaranteed to be within 1%. So if there is any changes in the temperature or voltage, the 1% does not hold any more.

The SPI or I2C do not care about absolute clock rate as long as they are within minimum and maximum limits so they won't be an issue, but UART comms could be a problem.

You also don't know how accurate the other chips are and what are their UART baud rate error or tolerance.

Typically, recommended maximum error for a device is around 2%, but it assumes data frames with 8 bits and that the error is shared with both devices. Under certain circumstances such as longer data frames the tolerance requirement could go near 1%.

So in general, simply the fact that UART comms is used will generally be enough of a reason that a better clock than an internal oscillator is required.

This means that an external resonator, an external crystal, or an external clock source such as a crystal oscillator module should be designed in to the circuit.

You don't need a high speed crystal, a low speed crystal is fine as the MCU has an internal PLL. The capacitor values depend on which exact capacitance the crystal you will buy requires to operate at the rated frequency.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks a lot The temperature rage will be a bit wider (the robot I'm building is for cave exploration, so 0-14°C in caves, 15-30°C at home when programming/testing). And UART frames will probably be longer (I was considering using the TF-mini Plus, in which case the frames are up to 8 bytes). So I would say that I need a crystal \$\endgroup\$
    – Sandro
    Dec 11, 2021 at 0:09
  • \$\begingroup\$ @Sandro The error at 0°C can exceed 2% so yes internal oscillator is not a good choise. But you have some misunderstanding, 8 bytes are 8 UART frames. Eact UART frame has a start bit, some amount of data bits from 5 to 10 and then a stop bit or two. \$\endgroup\$
    – Justme
    Dec 11, 2021 at 8:27
  • \$\begingroup\$ OK, so its 10 bits per frame (8 bits payload + start + 1 stop) \$\endgroup\$
    – Sandro
    Dec 11, 2021 at 9:34
2
\$\begingroup\$
  • The low-speed external clock is optional; the peripherals can be connected to it, or to a clock derived from the high-speed clock. So no, you don't need it.
  • A 1% accurate clock is OK for asynchronous serial, and just fine for IIC and SPI.
  • A 1% accurate clock isn't good enough for USB, but I know (without knowing how) that USB peripherals can derive a clock from the master. I don't know if that chip will work with USB without a crystal, though. I'd have to dredge through the datasheet to find out. Close reading of the USB section of the data sheet might tell you.
\$\endgroup\$
2
  • \$\begingroup\$ I have used a timer to generate a USB clock before, now I just use a separate external clock. \$\endgroup\$
    – Voltage Spike
    Dec 10, 2021 at 23:15
  • \$\begingroup\$ Thanks! I will not be using any USB directly. I will only use the ST-LINK V2 part from a nucleo board to programm/debug the STM32 : the ST-LINK has USB, but has also it's one crystall, so the USB itself should be fine \$\endgroup\$
    – Sandro
    Dec 11, 2021 at 0:28
1
\$\begingroup\$

do I need a high speed clock (or is the internal good enough)? If so, what crystal and what capacitors should I use?

Short answer, no you don't necessarily need a high speed clock, the STM32 has a PLL with multipliers to generate clocks of many different speeds. The Cube MX tool will allow you to explore different options as well as generate code to setup the complex clock system of an STM32.

If I need some, which crystal and capacitors should I use?

A crystal oscillator will typically uses two pins, OSC_IN and OSC_OUT. Typically two capacitors are needed to compensate a crystal oscillator. The value will be determined by the oscillator, usually the values of the capacitors are listed in the microprocessor family datasheet:

enter image description here

Source: https://www.st.com/resource/en/technical_note/tn1205-tape-and-reel-shipping-media-for-stm8-and-stm32-microcontrollers-in-fpn-packages-stmicroelectronics.pdf

A

\$\endgroup\$
1
  • \$\begingroup\$ Thanks. I'm not sure, to understand : should I look for the values of the capacitors in the documentation of the STM32 or of the crystal? PS : I think you put the wrong link : the one you put is about tape-and-reel packaging \$\endgroup\$
    – Sandro
    Dec 11, 2021 at 0:16

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.