Yahoo Groups archive

Lpc2000

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

Thread

How to write flash from application?

How to write flash from application?

2004-12-09 by rattencremesuppe

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(©_to_flash, result);

  enableIRQ();
}

still can't write flash with IAP

2004-12-09 by rattencremesuppe

> 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".

now IAP doesn't freeze, as I enabled "thumb interworking" in the ADS
compiler.

But now the "copy RAM to flash" fails with error code 9
(CMD_SUCCESS | DST_ADDR_ERROR)

DST_ADDR_ERROR means that destination address is not on a correct
boundary. But I am pretty sure that 0x0001c000 is in fact on a correct
boundary.

Cmd  = 51
arg0 = 0001c000
arg1 = 400002a4
arg2 = 00000200
arg3 = 00004800
Status  = 00000009

Any ideas?

Thanks
Patrick

solved (Re: still can't write flash with IAP)

2004-12-09 by rattencremesuppe

> But now the "copy RAM to flash" fails with error code 9
> (CMD_SUCCESS | DST_ADDR_ERROR)
> 
> DST_ADDR_ERROR means that destination address is not on a correct
> boundary. But I am pretty sure that 0x0001c000 is in fact on a
correct
> boundary.

oops, 0x0001c000 is no boundary address on the 2124. That sucker is a
256k part...

*bangs his head against the wall*

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.