Dear TI guys:
I saw a different way to erase checksum posted by a TI staff as shows below. I don't understand why there is no need to consider the instruction set switch from ARM to Thumb by using these code.
A way of grantee to avoid this problem is that just copy the size of zero_out_integrity_word from flash to ram.
Here is the steps of implementing this solution:
1. In cyclone.cmd file, add a group section like this:
SECTIONS
{
… …
UNION : run = RAM, RUN_START(_ram_run_start)
{
.zero_out_integrity_word_0 : load = PFLASH,
LOAD_START(_zero_out_integrity_word_start),
LOAD_END(_zero_out_integrity_word_end),
LOAD_SIZE(_zero_out_integrity_word_size)
}
… …
}
2. Clarify those symbols in header file or at the beginning of the source file referenced
extern Uint8 zero_out_integrity_word_start, zero_out_integrity_word_end, zero_out_integrity_word_size;
extern Uint8 ram_run_start;
3. Use a program to allocate the function into the section defined in above.
#pragma CODE_SECTION(zero_out_integrity_word, ".zero_out_integrity_word_0")
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 + //expand program flash out to 4x real size
MFBALRX_BYTE0_RONLY;
while(DecRegs.PFLASHCTRL.bit.BUSY != 0)
{
; //do nothing while it programs
}
// interrupt_time = TimerRegs.T24CNTDAT.bit.CNT_DAT - interrupt_time;
SysRegs.SYSECR.bit.RESET = 2; //now reset processor.
return;
}
4. Use memcpy function to copy the code from flash into ram, and then call the function directlly.
case 12: // clear integrity word.
{
memcpy((void *)&ram_run_start, (void *)&zero_out_integrity_word_start, (int32)&zero_out_integrity_word_size);
zero_out_integrity_word();
return;
}
There are several advantages of using this way,
- No need to consider the instruction set switch from ARM to Thumb.
- No worries about don’t have copied the whole code or more than the code itself into ram
Looking forward to your reply
Best regard
Dana Huang