AIR环境下MCU单片机Flash完整性校验

AIR环境下MCU单片机Flash完整性校验_第1张图片

AIR环境下MCU单片机Flash完整性校验_第2张图片

/* 粘贴在 xx.icf 文件末尾*/
/*IROM1_region需要改成实际的ROM名称*/

place at end of IROM1_region { ro section .checksum }; 
#define BOOT_START_ADDR 0x08000000
#define APP_START_ADDR  0x08003000
#define BOOT_CRC_ADDR   (APP_START_ADDR - 4)

static void BootFlashIntegrityCheck(void)
{
    uint32_t CRCCalcResult = 0;
    uint32_t CRCCValue = 0;
    
    //CRC复位uint32_t
    CRC_DeInit();
    
    //配置硬件CRC参数
    CRC_ConfigType CRCConfig;
    CRCConfig.crcProtocolType = CRC_PROTOCOL_32BIT;
    CRCConfig.writeTransposeType = CRC_WRITE_TRANSPOSE_BYTES;
    CRCConfig.readTransposeType = CRC_READ_TRANSPOSE_NONE;
    CRCConfig.finalXOR = DISABLE;
    CRCConfig.writeBytesNumOnce = CRC_WRITE_4_BYTE_ONCE;
    CRCConfig.poly = 0x4C11DB7;
    CRC_Init(&CRCConfig);
    
    //计算Flash CRC值
    CRCCalcResult = CRC_Check(0xFFFFFFFF, (uint8_t *)BOOT_START_ADDR, BOOT_CRC_ADDR - BOOT_START_ADDR);
    //获得Flash末尾的CRC值
    CRCCValue = *(uint32_t *)BOOT_CRC_ADDR;
    
    //如果FlashCRC检查有异常,停止运行
    if(CRCCalcResult != CRCCValue)
    {
        while(1);
    }
}

你可能感兴趣的:(单片机,嵌入式硬件)