Lpc2148 using IAP (IDE:IAR EW)

Started by jiaomj December 16, 2009
Hi, everyone~

I just want to use IAP functions to load the data from RAM to Flash.
I followed the LPC214x_User_Manual. In the manual I got every steps to accomplish this IAP task.

-----------------
// I define the osc like this as the frequency of the system:

#define OSCILLATOR_CLOCK_FREQUENCY 12000000

// and when i use the fosc i make it divide 1000 as the parameter in the IAP function
----------------
// my programe invoke IAP here:

#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
#define IAP_REINVOKEISP 57
#define IAP_LOCATION 0x7ffffff1
typedef void (*IAP)(unsigned long[],unsigned long[]);
IAP iap_entry = (IAP) IAP_LOCATION;

unit32 paramin[5]; //IAP entry parameter buffer
unit32 paramout[2];
unit8 count;

void SelSector(unit8 sec1, unit8 sec2){
paramin[0] = IAP_SELSECTOR;
paramin[1] = sec1;
paramin[2] = sec2;
iap_entry(paramin,paramout);
for(count=0;count<=2;count++){
printf("%lu\n",paramout[count]);
}
printf("____________________\n");
}
void RamToFlash(unit32 dst, unit32 src, unit32 no){
paramin[0] = IAP_RAMTOFLASH;
paramin[1] = dst;
paramin[2] = src;
paramin[3] = no;
paramin[4] = Fosc/1000;
iap_entry(paramin,paramout);
for(count=0;count<=2;count++){
printf("%lu\n",paramout[count]);
}
printf("____________________\n");
}

void EraseSector(unit8 sec1, unit8 sec2){
paramin[0] = IAP_ERASESECTOR;
paramin[1] = sec1;
paramin[2] = sec2;
paramin[3] = Fosc/1000;
iap_entry(paramin,paramout);
for(count=0;count<=2;count++){
printf("%lu\n",paramout[count]);
}
printf("____________________\n");
}

void BlankCHK(unit8 sec1, unit8 sec2){
paramin[0] = IAP_BLANKCHK;
paramin[1] = sec1;
paramin[2] = sec2;
iap_entry(paramin,paramout);
for(count=0;count<=2;count++){
printf("%lu\n",paramout[count]);
}
printf("____________________\n");
}

void ReadParID(void){
paramin[0] = IAP_READPARTID;
iap_entry(paramin,paramout);
for(count=0;count<=2;count++){
printf("%lu\n",paramout[count]);
}
printf("____________________\n");
}

void BootCodeID(void){
paramin[0] = IAP_BOOTCODEID;
iap_entry(paramin,paramout);
for(count=0;count<=2;count++){
printf("%lu\n",paramout[count]);
}
printf("____________________\n");
}

void Compare(unit32 dst, unit32 src, unit32 no){
paramin[0] = IAP_COMPARE;
paramin[1] = dst;
paramin[2] = src;
paramin[3] = no;
iap_entry(paramin,paramout);
for(count=0;count<=2;count++){
printf("%lu\n",paramout[count]);
}
printf("____________________\n");
}

************************* main.c *********************************

int main(void){
MAMCR = 0; //close MAN
PLLCON = 0; //colse PLL
PLLFEED = 0xaa; // set this to make sure that the PLLCON setting works
PLLFEED = 0x55;

ReadParID();
BootCodeID();

SelSector(1,1);
EraseSector(1,1);
BlankCHK(1,1);

SelSector(1,1);
RamToFlash(0x00001000,0x400017A0,1024);
BlankCHK(1,1);
Compare(0x00001000,0x400017A0,1024);

while(1);
return(0);
}

**********************************************************
I got the result in terminal I/O here:

0
67305253
2
____________________
0
524
2
____________________
0
524
2
____________________
0
524
2
____________________
8 // SECTOR_NOT_BLANK Sector is not blank
0
2
____________________
0
0
2
____________________
0
0
2
____________________
8
0
2
____________________
10 // this means COMPARE_ERROR Source
// and destination data is not same.
0
2
____________________

It seems it doesn't work at all when i invoke the IAP function to copy the data from RAM to flash.

I use the typical lpc2xxx_cstartup.s79 in the Program Files\IAR Systems\Embedded Workbench 4.0 Kickstart\arm\src\examples\Philips\LPC214x

My macro file used is just like the examples "LPC2148_RAM.mac".
Thank you in advance!

John

An Engineer's Guide to the LPC2100 Series