Forums

How to write flash from application?

Started by rattencremesuppe December 9, 2004

Hi,

I'm writing an application for LPC2124 using ARM ADS 1.2

I want to save a few user-defined configuration bytes in the internal
flash.

I've tried to use the IAP (in application programming) as suggested by
philips' user manual, but the LPC freezes when entering the "iap
entry".
Scatter def reserves upper 32 bytes of RAM exclusively for IAP code.
ASM listing shows that args are passed in r0 and r1 as required.

Are there any code examples or app notes around, on how to program the
flash memory from an application that's itself running in flash
memory?

struct iap_t {
unsigned long cmd;
unsigned long arg0;
unsigned long arg1;
unsigned long arg2;
unsigned long arg3;
};
typedef void (*IAP)(struct iap_t *, unsigned long *);

#define IAP_LOCATION 0x7ffffff1
IAP iap_entry =(IAP) IAP_LOCATION;

#define FLASH_PARAM_ADDR 0x0001C000

void WriteEEPROM(void)
{
struct iap_t
prepare_flash = { 50, 0, 0, 0, 0 },
erase_sector = { 52, 0, 0, 0, 0 },
copy_to_flash = { 51, 0, 0, 0, 0 };
unsigned long result[2];

disableIRQ();

prepare_flash.arg0 =
prepare_flash.arg1 = FLASH_PARAM_ADDR / 0x2000;
iap_entry(&prepare_flash, result);

erase_sector.arg0 =
erase_sector.arg1 = FLASH_PARAM_ADDR / 0x2000;
erase_sector.arg2 = 18432; /* 18.432 MHz clk */
iap_entry(&erase_sector, result);

iap_entry(&prepare_flash, result);

copy_to_flash.arg0 = FLASH_PARAM_ADDR;
copy_to_flash.arg1 =
(unsigned long)eeprom_settings.EEPROMCC1020Config;
copy_to_flash.arg2 = 512;
copy_to_flash.arg3 = 18432;
iap_entry(&copy_to_flash, result);

enableIRQ();
}




An Engineer's Guide to the LPC2100 Series