Skip to content

Instantly share code, notes, and snippets.

@DamianSuess
Last active July 2, 2026 12:42
Show Gist options
  • Select an option

  • Save DamianSuess/19a9b10e5c80e4cd995c50cab762c3ec to your computer and use it in GitHub Desktop.

Select an option

Save DamianSuess/19a9b10e5c80e4cd995c50cab762c3ec to your computer and use it in GitHub Desktop.
STM32 TAMP Register for Tamper And Backup Registers - a hardware security and data-retention block

STM32 (STM32H5) TAMP Register

The STM32H5 TAMP (Tamper and Backup Registers) peripheral is a hardware security and data-retention block. It is designed to detect physical or electronic intrusions and automatically erase sensitive device secrets to prevent attacks, while also managing backup registers that survive power loss.

Key TAMP Features

  • Tamper Detection: Supports multiple internal and external tamper sources (like active/passive detection) to catch intrusions.
  • Backup Registers: 32 32-bit registers (TAMP_BKP0R to TAMP_BKP31R) designed to retain critical data when the main $V_{DD}$ supply is off.
  • Boot Hardware Keys: The first 8 backup registers (TAMP_BKP0R – TAMP_BKP7R) can store secure AES boot hardware keys.
  • Secrets Erasure: Capable of triggering immediate hardware erasure of device secrets, backup SRAM, and backup registers.

Core TAMP Registers

The TAMP peripheral is highly configurable. The primary registers controlling this behavior include:

Register Name / Description Function
TAMP_CR1 Control Register 1 Enables/disables individual external and internal tamper detection circuits.
TAMP_CR2 Control Register 2 Configures tamper edge/level triggers, filtering options, and "No Erase" rules for external pins.
TAMP_CR3 Control Register 3 Configures "No Erase" options and blocking mechanisms for internal tamper events.
TAMP_FLTCR Filter Control Register Sets tamper sampling frequencies and internal pull-up/precharge configurations for pins.
TAMP_SR Status Register Indicates whether an active tamper event has been detected on a specific pin/source.
TAMP_IER Interrupt Enable Register Masks or enables specific tamper event interrupts.
TAMP_MISR Masked Interrupt Status Register Displays flags identifying which unmasked tamper event triggered the interrupt.
TAMP_SMCR Secure Mode Configuration Sets protection, secure/non-secure read-write zones, and privilege levels for the backup registers.
TAMP_BKPxR Backup Data Registers (i.e. TAMP_BKP0R) 32 registers used to preserve data across power cycles or during standby.

Reference and Documentation

For detailed register bit mappings, memory offsets, and instructions on how to use secure zones, consult the STM32H5 Reference Manual (RM0481). To implement secure anti-tamper functionality in your C code, you can use the Hardware Abstraction Layer API documented in the STM32CubeH5 TAMP HAL Documentation.

#include "stm32h5xx_hal_flash.h"
#define EDATA_PROVISION_COOKIE (0xDE4DB33FUL)
bool CustomInit();
static void EDataBackupCookieInit(void);
static bool EDataIsProvisionCookieSet(void);
static void EDataSetProvisionCookie(void);
static void EDataClearProvisionCookie(void);
bool CustomInit()
{
if (!IsConfigurationValidated()) // Your custom function
{
EDataSetProvisionCookie();
// ... Do custom data provisioning here ...
// return false; // Return early if failure during process
EDataClearProvisionCookie();
return false
}
// 2nd-pass provisioning
if (EDataIsProvisionCookieSet())
{
status = CustomDataProvisioning(); // S
if (status == HAL_OK)
EDataClearProvisionCookie();
}
// Load data as normal
// ...
}
static void EDataBackupCookieInit(void)
{
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_RTC_CLK_ENABLE();
}
static bool EDataIsProvisionCookieSet(void)
{
EDataBackupCookieInit();
return (TAMP->BKP0R == EDATA_PROVISION_COOKIE);
}
static void EDataSetProvisionCookie(void)
{
EDataBackupCookieInit();
TAMP->BKP0R = EDATA_PROVISION_COOKIE;
}
static void EDataClearProvisionCookie(void)
{
EDataBackupCookieInit();
TAMP->BKP0R = 0U;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment