×
单片机 > 单片机程序设计 > 详情

LPC1768 IAP写入bin格式程序不能启动的解决办法

发布时间:2020-06-04 发布时间:
|

在为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
               transferred to the user code.


* 入口参数   :bin文件开头28个字节数据
                  


* 返回值    :32位校验和


* 说明    :如果写入FLASH时,bin文件不修改这4个字节,复位或断电后,软件不能执行
******************************************************************/
int LpcCodeChecksum(unsigned char *pBuf)
{
int i = 0;
int checksum = 0;
int * p;
p = (int *)pBuf;
for(i = 0; i < 7; i++)
{
checksum += *p;
p++;

checksum = 0 - checksum;
return checksum;
}


pbData存bin文件所有内容,checkSumBuf为前28个字节(0--27)。

checkSumVal = LpcCodeChecksum(checkSumBuf);
pbData[28] = checkSumVal & 0xff;
pbData[29] = (checkSumVal >>  8) & 0xff;
pbData[30] = (checkSumVal >> 16) & 0xff;
pbData[31] = (checkSumVal >> 24) & 0xff;

然后写入flash,启动正常。



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
基于arm的指纹识别门禁系统是如何设计的