Application note

Introduction to using the hardware real-time clock (RTC) and the tamper management unit (TAMP) for STM32 MCUs

Rev 11 - March 2026

Introduction

A real-time clock (RTC) is a computer clock that tracks 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.

The dedicated software is 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
TypeProducts
Expansion PackageX-CUBE-RTC
MicrocontrollersSTM32C0 series, STM32F0 series, STM32F2 series, STM32F3 series, STM32F4 series, STM32F7 series, STM32G0 series, STM32G4 series, STM32H5 series, STM32H7 series, STM32L0 series, STM32L1 series, STM32L4 series, STM32L4+ series, STM32L5 series, STM32N6 series, STM32U0 series, STM32U3 series, STM32U5 series, STM32WB series, STM32WB0 series, STM32WBA series, STM32WL series

Overview of the STM32 MCUs advanced RTC

The RTC is embedded in STM32 Arm® Cortex®-based MCUs.

Note:

Arm and Cortex are registered trademarks of Arm Limited (or its subsidiaries or affiliates) in the US and/or elsewhere.

Arm and TrustZone are registered trademarks of Arm Limited (or its subsidiaries or affiliates) in the US and/or elsewhere.

The Arm word and logo are trademarks of Arm Limited (or its subsidiaries) in the US and/or elsewhere. All rights reserved.

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
FeaturesRTC2RTC3
RTC clock source (LSE, LSI, HSE with prescaler)XX
Binary mode-X
Mixed mode (BCD and binary)-X
PrescalersAsynchronousXX
SynchronousXX
CalendarTime12 h/24 h formatXX
Hour, minute, secondXX
SubsecondX X
DateXX
Daylight operationXX
Bypass the shadow registersXX
Power optimization mode-X
AlarmAlarms availableAlarm AXX
Alarm BXX
Time12 h/24 h formatXX
Hour, minutes, secondsXX
SubsecondsXX
Date or week dayXX
Binary mode alarm-X
Tamper detectionTamper effectsBackup registers erase1XX
InterruptionXX
Trigger for low-power timerXX
Configurable edge detectionXX
Configurable level detection (filtering, sampling and precharge configuration, internal pull-up)XX
Internal tamper events-X
External tamper inputsXX
VBAT mode pinsXX
NOERASE mode XX
Independent watchdog linked to an internal tamper for potential detection timeout-X
Active tamper-X
Monotonic counter-X
SAES key storage-X
Secure protection modes-X
Privileged protection mode-X
TimestampConfigurable input mappingXX
TimeHour, minute, secondXX
SubsecondXX
Date (day, month)XX
Timestamp on tamper detection eventXX
Timestamp on switch to VBAT modeXX
Wakeup unitClock source availableXX
Hardware automatic flag clearanceXX
RTC outputsTAMPALRMAlarm eventXX
Wakeup eventXX
Tamper event-X
CALIB512 HzXX
1 HzXX
Smooth digital calibrationSmooth calibrationXX
Power optimization mode-X
RTC synchronizationXX
Reference clock detectionXX
Backup registersReset on a tamper detectionXX
Reset when Flash memory readout protection is disabledXX
RTC secure protection mode-X
RTC privileged protection mode-X

The RTC acts as an independent binary-coded decimal (BCD) timer/counter. For the RTC3 type, a binary and a mixed (both binary and BCD) modes are available.

A given feature can be available for a RTC type but not implemented on all products (see Table 4 Advanced features for RTC2 type and AN4759_Adv-RTC-features.html#id_33173__table_hqc_shf_rpb for more details).

The table below specifies which RTC type is implemented on which product.
Table 3. RTC type on STM32 MCUs
RTC typeSTM32 MCUs
RTC2STM32F0 series, STM32F2 series, STM32F3 series, STM32F4 series, STM32F7 series, STM32H72/H73/H74/H75xxx, STM32L0 series, STM32L1 series, STM32L43/L44/L45/46/47/48xxx, STM32L4R5/Q5 line, STM32L4R7/S7 line, STM32L4R9/S9 line, STM32WB series, STM32WB0 series
RTC3STM32C0 series, STM32G0 series, STM32G4 series, STM32H5 series, STM32H7A3/7B3 line, STM32H7Rx/7Sx line, STM32L41/L42xxx, STM32L4P5/Q5 line, STM32L5 series, STM32N6 series, STM32U0 series, STM32U3 series, STM32U5 series, STM32WL series, STM32WBA series
1 Depending on devices, other resources can also be erased.