Introduction
A real-time clock (RTC) is a computer clock that keeps track of the current time. Although the RTCs are often used in personal
computers, servers and embedded systems, they are also present in almost any electronic device that requires an accurate
time keeping. The microcontrollers supporting the RTC can be used for chronometers, alarm clocks, watches, small electronic
agendas, and many other devices.
This application note describes the RTC features and how to configure it to implement several use cases such as calendar,
alarm, wakeup, timestamp, tamper detection, or calibration.
Depending on the RTC type, the product documentation may refer to an independent TAMP that is also detailed in this
application note.
Software examples are then detailed in this document to show how to use the RTC in the low-power modes and how to ensure
the tamper detection and timestamp while the main supply is switched off and the MCU is supplied by an alternate battery.
Other examples are also presented to illustrate the following features: smooth calibration, synchronization, reference clock
detection and internal tamper.
These dedicated softwares are provided through the X-CUBE-RTC Expansion Package delivered with this application note. This
software contains the source code of these examples and all the embedded software modules required to run the examples.
In this document, the STM32 microcontroller terminology applies to the products listed in the table below.
Table 1. Applicable products
Type Products
Expansion Package X-CUBE-RTC
Microcontrollers
STM32F0 Series, STM32F2 Series, STM32F3 Series, STM32F4 Series, STM32F7 Series, STM32H7 Series,
STM32G0 Series, STM32G4 Series, STM32L0 Series, STM32L1 Series, STM32L4 Series, STM32L4+ Series,
STM32L5 Series, STM32U5 Series, STM32WB Series, STM32WL Series
Using the hardware real-time clock (RTC) and the tamper management unit
(TAMP) with STM32 microcontrollers
AN4759
Application note
AN4759 - Rev 7 - September 2021
For further information contact your local STMicroelectronics sales office.
www.st.com
1 Overview of the STM32 MCUs advanced RTC
The RTC is embedded in STM32 Arm
®
Cortex
®
-based MCUs.
Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
The RTC provides a full-featured calendar, alarm, periodic wakeup unit, digital calibration, synchronization,
timestamp, and advanced tamper detection.
The RTC features and their implementation can be significantly different (regarding the registers map for
example) depending on the product. Two RTC types, RTC2 and RTC3, are distinguished and characterized
in the table below. These types affect the information presented in the rest of this application note.
Table 2. RTC/TAMP types
Features RTC2 RTC3
RTC clock source (LSE, LSI, HSE with prescaler) X X
Binary mode - X
Mixed mode (BCD and binary) - X
Prescalers
Asynchronous X X
Synchronous X X
Calendar
Time
12 h/24 h format X X
Hour, minute, second X X
Subsecond X X
Date X X
Daylight operation X X
Bypass the shadow registers X X
Power optimization mode - X
Alarm
Alarms
available
Alarm A X X
Alarm B X X
Time
12 h/24 h format X X
Hour, minutes, seconds X X
Subseconds X X
Date or week day X X
Binary mode alarm - X
Tamper detection
Tamper
effects
Backup registers erase
(1)
X X
Interruption X X
Trigger for low-power timer X X
Configurable edge detection X X
Configurable level detection (filtering, sampling and precharge
configuration, internal pull-up)
X X
Internal tamper events - X
External tamper inputs X X
V
BAT
mode pins
X X
NOERASE mode X X
AN4759
Overview of the STM32 MCUs advanced RTC
AN4759 - Rev 7
page 2/61