在为LPC1768做一个CAN总线在线升级功能的时候,使用IAP功能,将KEIL转换生成的bin文件写入lpc1768内部flash的起始地址,然后跳转到这个位置启动。自动跳转时能够正常启动,但是一复位或者断电重启就不能启动了,查找原因并求助论坛网友得到了问题原因和解决办法。
程序写入内部flash时需要计算bin文件前28个字节的校验和(32位),然后将这个校验和替换bin文件第28到31字节的值,bin文件其他部分不变。
计算方法:
/******************************************************************
* 名称 :LpcCodeChecksum()
* 功能 :The reserved Cortex-M3 exception vector location 7 (offset 0x 001C in the vector table)
should contain the 2’s complement of the check-sum of table entries 0 through 6. This
causes the checksum of the first 8 table entries to be 0. The boot loader code checksums
the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is