STM32F4-Discovery RTC Hack
STM32F4-Discovery RTC Hack
STM32F4xx have a build in RTC (Real Time Clock) module. It is easy to use and can be driven by an internal or external 32,768 kHz reference clock. External 32.768 kHz clock reference is (by default) not fitted on the STM32F4-Discovery boards, but footprint of the crystal oscillator and load capacitors is provided on the PCB. The only issue is an additional VBAT voltage that is used as a backup supply for the RTC (as well as for additional backup registers and a small amout of backup SRAM memory).
Internal 32kHz reference has a wide tolerance and changes with temperature (as presented in the STM32F405xx / STM32F407xx Datasheet):
So if a stable and accurate time measurements (especially in longer periods) are needed - it is definitelly worth using an external cristall oscillator as a reference clock for the RTC.
Only thing that remains unclear is how to connect the VBAT backup power supply for the RTC (otherwise time and date must be configured each time the board is disconnected from the power supply). While there is a dedicated VBAT pin on the Morpho expansion header on the STM Nucleo boards series it was not routed on any of the STM32F4-Discovery headers. VBAT supply current is small enough that a coin cell battery (for e.g. CR2032) will provide enough power.
By default VBAT is shorten (with R26, 0 Ohm, 0603 size resistor) to the VBAT and can also be found on the C28 decoupling capacitor (schematic of the board can be found in the UM1472 STM32F407 Discovery Kit User Manual):
The R26 can be desoldered (otherwise, when power is removed VBAT would provide VDD voltage for the board, but what is worse: when the board is repowered the VDD would recharge the lithium coin cell battery an it will not end well). In our case a typical, cheap, through hole button cell holder was a perfect match and is soldered directly to the positive pin on the C26 decoupling capacitor and P2-2 GND pin:
It must be remembered, that the cell holder must be operated carefully or the C26 or the board itself (C26 pad torn of the PCB laminate) can be destroyed.