6. Backup registers (BKP)

Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.

Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.

High-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes.

XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 768 Kbytes and 1 Mbyte.

Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.

This section applies to the whole STM32F101xx family, unless otherwise specified.

6.1 BKP introduction

The backup registers are forty two 16-bit registers for storing 84 bytes of user application data.

They are implemented in the backup domain that remains powered on by \( V_{BAT} \) when the \( V_{DD} \) power is switched off. They are not reset when the device wakes up from Standby mode or by a system reset or power reset.

In addition, the BKP control registers are used to manage the Tamper detection feature and RTC calibration.

After reset, access to the Backup registers and RTC is disabled and the Backup domain (BKP) is protected against possible parasitic write access. To enable access to the Backup registers and the RTC, proceed as follows:

6.2 BKP main features

6.3 BKP functional description

6.3.1 Tamper detection

The TAMPER pin generates a Tamper detection event when the pin changes from 0 to 1 or from 1 to 0 depending on the TPAL bit in the Backup control register (BKP_CR) . A tamper detection event resets all data backup registers.

However to avoid losing Tamper events, the signal used for edge detection is logically ANDed with the Tamper enable in order to detect a Tamper event in case it occurs before the TAMPER pin is enabled.

By setting the TPIE bit in the BKP_CSR register, an interrupt is generated when a Tamper detection event occurs.

After a Tamper event has been detected and cleared, the TAMPER pin should be disabled and then re-enabled with TPE before writing to the backup data registers (BKP_DRx) again. This prevents software from writing to the backup data registers (BKP_DRx), while the TAMPER pin value still indicates a Tamper detection. This is equivalent to a level detection on the TAMPER pin.

Note: Tamper detection is still active when V DD power is switched off. To avoid unwanted resetting of the data backup registers, the TAMPER pin should be externally tied to the correct level.

6.3.2 RTC calibration

For measurement purposes, the RTC clock with a frequency divided by 64 can be output on the TAMPER pin. This is enabled by setting the CCO bit in the RTC clock calibration register (BKP_RTCCR) .

The clock can be slowed down by up to 121 ppm by configuring CAL[6:0] bits.

For more details about RTC calibration and how to use it to improve timekeeping accuracy, refer to AN2604 "STM32F101xx and STM32F103xx RTC calibration".

6.4 BKP registers

Refer to Section 2.2 on page 45 for a list of abbreviations used in register descriptions.

The peripheral registers can be accessed by half-words (16-bit) or words (32-bit).

6.4.1 Backup data register x (BKP_DRx) (x = 1 ..42)

Address offset: 0x04 to 0x28, 0x40 to 0xBC

Reset value: 0x0000 0000

1514131211109876543210
D[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 15:0 D[15:0] Backup data

These bits can be written with user data.

Note: The BKP_DRx registers are not reset by a System reset or Power reset or when the device wakes up from Standby mode.

They are reset by a Backup Domain reset or by a TAMPER pin event (if the TAMPER pin function is activated).

6.4.2 RTC clock calibration register (BKP_RTCCR)

Address offset: 0x2C

Reset value: 0x0000 0000

1514131211109876543210
ReservedASOSASOECCOCAL[6:0]
rwrwrwrwrwrwrwrwrwrw

Bits 15:10 Reserved, must be kept at reset value.

Bit 9 ASOS : Alarm or second output selection

When the ASOE bit is set, the ASOS bit can be used to select whether the signal output on the TAMPER pin is the RTC Second pulse signal or the Alarm pulse signal:

0: RTC Alarm pulse output selected

1: RTC Second pulse output selected

Note: This bit is reset only by a Backup domain reset.

Bit 8 ASOE : Alarm or second output enable

Setting this bit outputs either the RTC Alarm pulse signal or the Second pulse signal on the TAMPER pin depending on the ASOS bit.

The output pulse duration is one RTC clock period. The TAMPER pin must not be enabled while the ASOE bit is set.

Note: This bit is reset only by a Backup domain reset.

Bit 7 CCO : Calibration clock output

0: No effect

1: Setting this bit outputs the RTC clock with a frequency divided by 64 on the TAMPER pin. The TAMPER pin must not be enabled while the CCO bit is set in order to avoid unwanted Tamper detection.

Note: This bit is reset when the \( V_{DD} \) supply is powered off.

Bits 6:0 CAL[6:0] : Calibration value

This value indicates the number of clock pulses that will be ignored every \( 2^{20} \) clock pulses. This allows the calibration of the RTC, slowing down the clock by steps of \( 1000000/2^{20} \) PPM.

The clock of the RTC can be slowed down from 0 to 121PPM.

6.4.3 Backup control register (BKP_CR)

Address offset: 0x30

Reset value: 0x0000 0000

1514131211109876543210
ReservedTPALTPE
rwrw

Bits 15:2 Reserved, must be kept at reset value.

Bit 1 TPAL : TAMPER pin active level

0: A high level on the TAMPER pin resets all data backup registers (if TPE bit is set).

1: A low level on the TAMPER pin resets all data backup registers (if TPE bit is set).

Bit 0 TPE : TAMPER pin enable

0: The TAMPER pin is free for general purpose I/O

1: Tamper alternate I/O function is activated.

Note: Setting the TPAL and TPE bits at the same time is always safe, however resetting both at the same time can generate a spurious Tamper event. For this reason it is recommended to change the TPAL bit only when the TPE bit is reset.

6.4.4 Backup control/status register (BKP_CSR)

Address offset: 0x34

Reset value: 0x0000 0000

1514131211109876543210
ReservedTIFTEFReservedTPIECTICTE
rrrwww

Bits 15:10 Reserved, must be kept at reset value.

Bit 9 TIF : Tamper interrupt flag

This bit is set by hardware when a Tamper event is detected and the TPIE bit is set. It is cleared by writing 1 to the CTI bit (also clears the interrupt). It is also cleared if the TPIE bit is reset.
0: No Tamper interrupt
1: A Tamper interrupt occurred

Note: This bit is reset only by a system reset and wakeup from Standby mode.

Bit 8 TEF : Tamper event flag

This bit is set by hardware when a Tamper event is detected. It is cleared by writing 1 to the CTE bit.
0: No Tamper event
1: A Tamper event occurred

Note: A Tamper event resets all the BKP_DRx registers. They are held in reset as long as the TEF bit is set. If a write to the BKP_DRx registers is performed while this bit is set, the value will not be stored.

Bits 7:3 Reserved, must be kept at reset value.

Bit 2 TPIE : TAMPER pin interrupt enable

0: Tamper interrupt disabled
1: Tamper interrupt enabled (the TPE bit must also be set in the BKP_CR register)

Note: A Tamper interrupt does not wake up the core from low-power modes.

This bit is reset only by a system reset and wakeup from Standby mode.

Bit 1 CTI : Clear tamper interrupt

This bit is write only, and is always read as 0.
0: No effect
1: Clear the Tamper interrupt and the TIF Tamper interrupt flag.

Bit 0 CTE : Clear tamper event

This bit is write only, and is always read as 0.
0: No effect
1: Reset the TEF Tamper event flag (and the Tamper detector)

6.4.5 BKP register map

BKP registers are mapped as 16-bit addressable registers as described in the table below:

Table 17. BKP register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00Reserved
0x04BKP_DR1ReservedD[15:0]
Reset value0000000000000000

Table 17. BKP register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x08BKP_DR2ReservedD[15:0]
Reset value0000000000000000
0x0CBKP_DR3ReservedD[15:0]
Reset value0000000000000000
0x10BKP_DR4ReservedD[15:0]
Reset value0000000000000000
0x14BKP_DR5ReservedD[15:0]
Reset value0000000000000000
0x18BKP_DR6ReservedD[15:0]
Reset value0000000000000000
0x1CBKP_DR7ReservedD[15:0]
Reset value0000000000000000
0x20BKP_DR8ReservedD[15:0]
Reset value0000000000000000
0x24BKP_DR9ReservedD[15:0]
Reset value0000000000000000
0x28BKP_DR10ReservedD[15:0]
Reset value0000000000000000
0x2CBKP_RTCCRReservedASOSASOECCOCAL[6:0]
Reset value0000000000
0x30BKP_CRReservedTPALTPE
Reset value00
0x34BKP_CSRReservedTIFTEFReservedTPIECTICTE
Reset value00000
0x38Reserved
0x3CReserved
0x40BKP_DR11ReservedD[15:0]
Reset value0000000000000000

Table 17. BKP register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x44BKP_DR12ReservedD[15:0]
Reset value00000000000000000000000000000000
0x48BKP_DR13ReservedD[15:0]
Reset value00000000000000000000000000000000
0x4CBKP_DR14ReservedD[15:0]
Reset value00000000000000000000000000000000
0x50BKP_DR15ReservedD[15:0]
Reset value00000000000000000000000000000000
0x54BKP_DR16ReservedD[15:0]
Reset value00000000000000000000000000000000
0x58BKP_DR17ReservedD[15:0]
Reset value00000000000000000000000000000000
0x5CBKP_DR18ReservedD[15:0]
Reset value00000000000000000000000000000000
0x60BKP_DR19ReservedD[15:0]
Reset value00000000000000000000000000000000
0x64BKP_DR20ReservedD[15:0]
Reset value00000000000000000000000000000000
0x68BKP_DR21ReservedD[15:0]
Reset value00000000000000000000000000000000
0x6CBKP_DR22ReservedD[15:0]
Reset value00000000000000000000000000000000
0x70BKP_DR23ReservedD[15:0]
Reset value00000000000000000000000000000000
0x74BKP_DR24ReservedD[15:0]
Reset value00000000000000000000000000000000
0x78BKP_DR25ReservedD[15:0]
Reset value00000000000000000000000000000000

Table 17. BKP register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x7CBKP_DR26ReservedD[15:0]
Reset value0000000000000000
0x80BKP_DR27ReservedD[15:0]
Reset value0000000000000000
0x84BKP_DR28ReservedD[15:0]
Reset value0000000000000000
0x88BKP_DR29ReservedD[15:0]
Reset value0000000000000000
0x8CBKP_DR30ReservedD[15:0]
Reset value0000000000000000
0x90BKP_DR31ReservedD[15:0]
Reset value0000000000000000
0x94BKP_DR32ReservedD[15:0]
Reset value0000000000000000
0x98BKP_DR33ReservedD[15:0]
Reset value0000000000000000
0x9CBKP_DR34ReservedD[15:0]
Reset value0000000000000000
0xA0BKP_DR35ReservedD[15:0]
Reset value0000000000000000
0xA4BKP_DR36ReservedD[15:0]
Reset value0000000000000000
0xA8BKP_DR37ReservedD[15:0]
Reset value0000000000000000
0xACBKP_DR38ReservedD[15:0]
Reset value0000000000000000
0xB0BKP_DR39ReservedD[15:0]
Reset value0000000000000000

Table 17. BKP register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0xB4BKP_DR40ReservedD[15:0]
Reset value0000000000000000
0xB8BKP_DR41ReservedD[15:0]
Reset value0000000000000000
0xBCBKP_DR42ReservedD[15:0]
Reset value0000000000000000

Refer to Table 3 on page 50 for the register boundary addresses.