ZHCACU3 july 2023 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138128A , UCD3138A , UCD3138A64
zero_out_integrity_word 函数用于清除校验和的指定位置。当 zero_out_integrity_word 函数未在 32 位模式下进行编译时,可能会发生锁定。此函数通常位于名为 zero_out_integrity_word.c 的独立文件中不同工程的函数名或文件名可能略有不同,但通常如下所示。
#define program_flash_integrity_word (*((volatile unsigned long *) 0x7ffc))
//last word in flash, when executing from Flash. used to store integrity code
void zero_out_integrity_word(void)
{
DecRegs.FLASHILOCK.all = 0x42DC157E;// Write key to Program Flash Interlock Register
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K; //enable program flash write program_flash_integrity_word = 0;
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K + MFBALRX_BYTE0_RONLY;
while(DecRegs.PFLASHCTRL.bit.BUSY != 0)
{
; //do nothing while it programs
}
return;
}
要检查此函数/文件是否在 32 位模式下编译:
请注意,此选项通过 CCS 中的配置完成,所以当变更 CCS 版本或编译器版本时,zero_out_integrity_word 函数可能会失败。
另一种选择是使用预处理器指令 #pragma 告知编译器在 32 位模式下编译指定函数。下面是一个示例:
#define program_flash_integrity_word (*((volatile unsigned long *) 0x7ffc))
//last word in flash, when executing from Flash. used to store integrity code
#pragma CODE_STATE(zero_out_integrity_word, 32) // 16 = thumb mode, 32 = ARM mode
void zero_out_integrity_word(void)
{
DecRegs.FLASHILOCK.all = 0x42DC157E;// Write key to Program Flash Interlock Register
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K; //enable program flash write
program_flash_integrity_word = 0;
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K + MFBALRX_BYTE0_RONLY;
while(DecRegs.PFLASHCTRL.bit.BUSY != 0)
{
; //do nothing while it programs
}
return;
}