jie841010 发表于 2008-7-15 20:09:44

IAP编程问题

LPC2104
在进行FLASH擦写时,总是会出现异常,不知道为什么,中断我已经关了,ARM/THUMB Interwork也选了!有个奇怪的现像,我把simple中的Layout项清空,中断向量表自会自动跑到程序的最后,但程序擦写就可以成功处理,但是中断不会响应了,串口也配置不了,程序变得很乱。
2104盘上的IAP事例也跑不起来,常出现取指令异常,FIQ中断,现在用新的模版就出现了数据异常!
我把程序都COPY上来,希望周公帮忙分析了,也希望哪个朋友能多多提点方案
#include "config.h"
#define IAP_ENTER_ADR 0x7FFFFFF1 /* IAP入口地址定义 */

/* 定义IAP命令字 */
#define IAP_SELSECTOR 50
#define IAP_RAMTOFLASH 51
#define IAP_ERASESECTOR 52
#define IAP_BLANKCHK 53
#define IAP_READPARTID 54
#define IAP_BOOTCODEID 55
#define IAP_COMPARE 56

/* 定义IAP返回状态字 */
#define CMD_SUCCESS 0
#define INVALID_COMMAND 1
#define SRC_ADDR_ERROR 2
#define DST_ADDR_ERROR 3
#define SRC_ADDR_NOT_MAPPED 4
#define DST_ADDR_NOT_MAPPED 5
#define COUNT_ERROR 6
#define INVALID_SECTOR 7
#define SECTOR_NOT_BLANK 8
#define SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION 9
#define COMPARE_ERROR 10
#define BUSY 11
#define PARAM_ERROR 12 /* Insufficient number of parameters */
#define ADDR_ERROR 13 /* Address not on word boundary */
#define ADDR_NOT_MAPPED 14
#define CMD_LOCKED 15 /* Command is locked */
#define INVALID_CODE 16 /* Unlock code is invalid */
#define INVALID_BAUD_RATE 17
#define INVALID_STOP_BIT 18

/* 定义CCLK值大小,单位为KHz */
#define IAP_FCCLK 11059


/* 定义函数指针 */
void (*IAP_Entry)(uint32 param_tab[], uint32 result_tab[]);
extern void UserSevice(void);
uint32 paramin; // IAP入口参数缓冲区
uint32 paramout; // IAP出口参数缓冲区
#define BlockSize 512
#define UART0BAUT 9600

#define ST_OK 1
#define ST_NO 0

#define ACK 0x80//信息确认
#define NAK 0x81//信息重发

uint8 BufData;//缓冲区
uint32 FlashAdd; //应用程序地址入口
uint32 BufAdd;
uint8 State; //下载程序,0正在下载,1下载结束
uint8 Status;//校验 1成功,0失败
uint32 time;//校验时间
uint8 CurSector;//16个扇区,0:bootloader
uint8 CurBlock;//
/****************************************************************************
* 名称:SelSector()
* 功能:IAP操作扇区选择,命令代码50。
* 入口参数:sec1 起始扇区
* sec2 终止扇区
* 出口参数:IAP返回值(paramout缓冲区)
****************************************************************************/
void SelSector(uint8 sec1, uint8 sec2)
{ paramin = IAP_SELSECTOR; // 设置命令字
paramin = sec1; // 设置参数
paramin = sec2;
(*IAP_Entry)(paramin, paramout); // 调用IAP服务程序
}


/****************************************************************************
* 名称:RamToFlash()
* 功能:复制RAM的数据到FLASH,命令代码51。
* 入口参数:dst 目标地址,即FLASH起始地址。以512字节为分界
* src 源地址,即RAM地址。地址必须字对齐
* no 复制字节个数,为512/1024/4096/8192
* 出口参数:IAP返回值(paramout缓冲区)
****************************************************************************/
void RamToFlash(uint32 dst, uint32 src, uint32 no)
{ paramin = IAP_RAMTOFLASH; // 设置命令字
paramin = dst; // 设置参数
paramin = src;
paramin = no;
paramin = IAP_FCCLK;
(*IAP_Entry)(paramin, paramout); // 调用IAP服务程序
}


/****************************************************************************
* 名称:EraseSector()
* 功能:扇区擦除,命令代码52。
* 入口参数:sec1 起始扇区
* sec2 终止扇区
* 出口参数:IAP返回值(paramout缓冲区)
****************************************************************************/
void EraseSector(uint8 sec1, uint8 sec2)
{ paramin = IAP_ERASESECTOR; // 设置命令字
paramin = sec1; // 设置参数
paramin = sec2;
paramin = IAP_FCCLK;
(*IAP_Entry)(paramin, paramout); // 调用IAP服务程序
}
void UartInit()
{
uint32 temp;
PCONP |= (1 << 3);
PINSEL0 &= 0xfffffff0;
PINSEL0 |= 0x00000005;
temp = (Fpclk >> 4) / UART0BAUT;
U0LCR = 0x80;
U0DLM = (temp >> 8);
U0DLL = (temp & 0xff);
U0LCR = 0x03;
U0FCR = 0x87;
}
unsigned char RecData()
{
unsigned char tmp;
while((U0LSR & 0x01) == 0)
{
/*if(State == 1) //等待一段时间,无数据则运行程序
{
time--;
if(time == 0)
{
Status = ST_OK;
return 0xff;
}
}*/
}
tmp = U0RBR;
return tmp;
}
void SendData(unsigned char data)
{
U0THR = data;
}
void InitVar()
{
CurSector = 0;
CurBlock = 0;
FlashAdd = 0x0000;
BufAdd = 0x40000504;
State = 1;
Status = 0;
time = 10000;

}


int main()
{
uint8 c,Check,flag;
uint16 i;
flag = 0;
InitVar();
UartInit();
VICProtection = 1;
IAP_Entry = (void(*)())IAP_ENTER_ADR;
/*while(Status != ST_OK)
{
c = RecData();
if(c != 0x00)
{
Status = ST_OK;
break;
}
Check = c;
FlashAdd += (unsigned long) c << 24;
c = RecData();
Check += c;
FlashAdd += (unsigned long) c << 16;
c = RecData();
Check += c;
FlashAdd += (unsigned long) c << 8;
c = RecData();
Check += c;
FlashAdd += (unsigned long) c;
for(i = 0;i < BlockSize ;i++)
{
c = RecData();
BufData = c;
}
c = RecData();
Check +=c;
if(Check == 0)
{*/
__asm{MSR CPSR_c,#0xdf}
if(CurBlock == 0)
{
SelSector(CurSector,CurSector);
EraseSector(CurSector,CurSector);
}
SelSector(CurSector,CurSector);
RamToFlash(FlashAdd,BufAdd,512);
__asm{MSR CPSR_c,#0x5f}
FlashAdd += 512;
if(CurBlock == 15)
{
CurBlock = 0;
CurSector++;
}
else
CurBlock++;

SendData(ACK);
// State = 1;
//}
//else
//{
// SendData(NAK);
// State = 0;
//}
//}
//UserSevice();
return 0;
}
    RO地址:0x00,RW:0x40000000向量表(... 250 字节 hduhfl 2008-7-15 18:58:00

jie841010 发表于 2008-7-15 21:44:21

急求解答,期待你的回应,这事情太急了,谁能帮忙分析下,谁遇到过这个问题,你们LPC2104上的IAP事例程序运行的了吗?

期待你们的留言

mendoulou 发表于 2011-5-11 22:58:57

楼主解决了吗,我现在问题跟你很像,用jtag跟了一下,发现在擦FLASH时,总是进入数据访问异常。

ymm1030 发表于 2011-5-12 12:23:47

标记一下,如果解决,值得参考
页: [1]
查看完整版本: IAP编程问题