Skip to main content
EThom.3
Senior II
April 15, 2026
Question

STM32G4: Using PC13 for calibrating RTC – how bad can it be, really?

  • April 15, 2026
  • 1 reply
  • 139 views

Hello fellow STM32 users.

Only after making a prototype where I use PC13 for calibrating the RTC, I stumbled upon the PC13 issue. Or maybe I had seen it before, and forgotten about it.

For those unfamiliar with this issue, using PC13 for anything I/O related may affect the RTC clock frequency, in case you use an external RTC crystal (LSE oscillator). This is copied from the STM32G4 errata sheet:

EThom3_0-1776244222256.png

But how bad can it be, really? After (re)discovering this, I decided to put it to the test. I made a firmware version where I could select which I/O port to use for calibration. I use the 1 Hz calibration output, and have a frequency counter measure the average pulse period over 32 consecutive pulses. The frequency counter uses an external GPSDO as frequency reference, so the result should be pretty accurate.

Using PC13 for the 1 Hz calibration signal, I measured a 243.7 ppm deviation. Pretty big, actually, but still possible to compensate for in the RTC_CALR register.

However, when I used PB2 for the exact same purpose, I measured a 182.9 ppm deviation. Still significant, and I probably need to adjust the crystal capacitors a bit. But also a big difference from the PC13 measurement.

Then I entered -256 into RTC_CALR, to calibrate the RTC based on the PC13 measurement. Measured once more to verify (using PC13) and got -0.5 ppm. That's fine.

After this, I again turned on the 1 Hz output on the PB2 port, and made a measurement. Not surprisingly, the result was -61.4 ppm, which is very close to the difference between the first two measurements. (243.7 - 182.9 = 60.8. (-0.5) - (-61.4) = 60.9. Very close indeed.)

I imagine that using the 512 Hz output for calibrating, would make the difference even bigger. I haven't made any experiments with this, though, so it is pure guesswork.

My conclusion

On this particular board, with this microcontroller (an STM32G474), the difference between calibrating with PC13 and PB2 (at 1 Hz) is about 61 ppm. Over a year, this amounts to about 32 minutes. In some applications, this discrepancy is unacceptable.

So when using the LSE, it would indeed be wise to not use PC13 at all, or to use it for something that rarely changes level, such as a DIP switch input. And never ever for RTC calibration.

1 reply

waclawek.jan
Super User
April 15, 2026

Thanks for your report.

I've experimented with a 'F411 Nucleo; my finding with that particular setup was, that the effect is barely noticeable.

While the oscillator circuit within the chip is very different between 'F4 and 'G4 (and other families)  - see AN2867 - I am convinced that even there the particular layout and LSE drive setting will have significant effect on gravity of the problem.

Can you please at least try changing LSE drive and observe the effect? Also it would be nice to see if this disturbance changes with changing the capacitors to achieve precise 32.768kHz oscillations. And if you have a 'G4 Nucleo at hand, could you please try that one as well?

JW

EThom.3
EThom.3Author
Senior II
April 15, 2026

@waclawek.jan wrote:

While the oscillator circuit within the chip is very different between 'F4 and 'G4 (and other families)  - see AN2867 - I am convinced that even there the particular layout and LSE drive setting will have significant effect on gravity of the problem.

Can you please at least try changing LSE drive and observe the effect? Also it would be nice to see if this disturbance changes with changing the capacitors to achieve precise 32.768kHz oscillations. And if you have a 'G4 Nucleo at hand, could you please try that one as well?

JW


I may revisit this, and try different drive levels. My experiment was made at medium high drive level.

The capacitors will not be changed on the existing prototype boards, but I'll have other capacitor values on the next version. (I had made a *** math error, and put too small capacitors on the first batch.)

I don't have a G4 Nucleo board, so I can't test with such a board.

By the way: Not that I expect others to have any interest in this, but I've made a small program that communicates with a TF930 frequency counter from TTI. The program sets up the counter for measuring the 1 Hz calibration signal. When activated, the program will capture 32 consecutive measurements, calculate the deviation, and suggest a calibration value. Willing to share if anyone should want it.