Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

sample IAP code

2004-08-27 by Owen Mooney

>Hi all, I'm just starting to work with the In Application 
>Programming and I was wondering if anyone has some simple c code 
>that stores some calibration variables into flash.  Thanks,
>

Here it is:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Setup strucure defined in RAM

struct SETUP {
    ... // fill in the gaps with your data
};

One copy of the structure in RAM

struct SETUP setup;

Pointer to the non volatile copy

struct SETUP * nonvolatile;

nonvolatile= (struct SETUP*) 0x1C000; // Points to page 14 in Flash 
(LPC2106)

copy to RAM (if you need)

setup=*nonvolatile;

now modify it as you need

Then save it - this is for a 14.745 MHz Xtal

#define IAP_LOCATION 0x7ffffff1

void savesetup(struct SETUP *setup){
   typedef void (*IAP)(unsigned int [],unsigned int[]);
   unsigned int command[5];
   unsigned int result[2];
   IAP iap_entry;
   __ARMLIB_disableIRQ();
   iap_entry=(IAP) IAP_LOCATION;
   // get part ID
   command[0]=54;
   result[0]=0;
   iap_entry(command, result); // I do this just for a laugh
   // result in result[1]
   // prepare to erase
   command[0]=50;
   command[1]=14;
   command[2]=14;
   iap_entry(command, result);      
   if (result[0] != 0) goto error;
   // erase
   command[0]=52;
   command[1]=14;
   command[2]=14;
   command[3]=14745;
   iap_entry(command, result);     // erase the block - else you get old 
+ new data mixed !!!
   if (result[0] != 0) goto error;
   // prepare to program
   iap_entry=(IAP) IAP_LOCATION;
   command[0]=50;
   command[1]=14;
   command[2]=14;
   iap_entry(command, result);
   if (result[0] != 0) goto error;
   //  program
   command[0]=51;
   command[1]=0x1C000;
   command[2]=(int)setup;
   command[3]=512;
   command[4]=14745;
   iap_entry(command, result);
   if (result[0] != 0) goto error;
   __ARMLIB_enableIRQ();
   return;
   error:
   __ARMLIB_enableIRQ();
   printf("bum");
}


It works well be me. make your your program doesn't get up to page 14 of 
Flash !!!!


Owen Mooney

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.