MM32 备份域学习(兼容STM32)

内容提要

  • 备份域工作原理
  • 备份域特性
  • 备份域的保护:侵入检测
  • 备份域侵入检测

备份域电源与主要内容

备份域特性


侵入检测理解


备份域侵入检测测试

void TamperEventTest()
{
//设置时钟PWR和BKP
RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
PWR_BackupAccessCmd(ENABLE); //使能访问备份域和RTC //侵入引脚时钟设置
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //初始化备份域
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE); //设置备份域时钟
RCC_LSEConfig(RCC_LSE_ON); //Configures the External Low Speed oscillator (LSE).
RCC_RTCCLKCmd(ENABLE); //Enables or disables the RTC clock.
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); //Configures the RTC clock (RTCCLK). while(!(RCC->BDCR & 0x1<<1)); //External low-speed clock ready flag. BKP_ClearFlag(); //Set CTE bit to clear Tamper Pin Event flag //配置信号控制(PA1)侵入检测的信号(PC13)
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure); //write backup registers
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
BKP_WriteBackupRegister(BKP_DR2, 0x8888);
BKP_WriteBackupRegister(BKP_DR3, 0x6666);
BKP_WriteBackupRegister(BKP_DR4, 0x9999);
BKP_WriteBackupRegister(BKP_DR5, 0x9999);
BKP_WriteBackupRegister(BKP_DR6, 0x9999);
BKP_WriteBackupRegister(BKP_DR7, 0x9999);
BKP_WriteBackupRegister(BKP_DR8, 0x9999);
BKP_WriteBackupRegister(BKP_DR9, 0x9999);
BKP_WriteBackupRegister(BKP_DR10, 0x9999); BKP->CR=0x01;
GPIOA->ODR=1;//set PA[0]=1 >> set PC[13]
while(1)
{
if((BKP->CSR &0x100)==0x100)//tef tamper event flag
{
//A write to the BKP->DRx register is performed while tef is set the value will not be stored
BKP->DR1=0x6666;
BKP->DR2=0x6666;
delay(100);
BKP->CSR=0x1;//clear tamper event flag;侵入检测,将使备份域复位
break;
}
}

实验注意事项

  • 设置了两个GPIO引脚,PA1和PC13,PA1用于控制等待配置完成,然后请自行添加PC13的信号(等到PA1高电平来)即侵入信号。
  • 实验结果应该是备份域被复位,读出数据为0x0。

总结


参考资料

[1]. MM32 miniboard资料

05-02 06:50