Yahoo Groups archive

Lpc2000

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

Message

IAP problem

2005-09-05 by Michal Krestan

Hi,

I still have problem with IAP on LPC2106. I've upgraded my bootloader to verion 1.52 as desribed on philips website and it still doesn't work.
It will hang very often somewhere in following procedure and will not make any modification in FLASH memory, but sometimes it's successfull
and new firmware is uploaded correctly. Following procedure is mappend into 15th sector of FLASH memory. (Only first 48Kb of FLASH onchip
memory is used by my application). My code is compiled in ARM mode.

In linker script I've following modification for reserved RAM by IAP calls:

/* Memory Definitions */
MEMORY
{
  ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000
  RAM (rw) : ORIGIN = 0x40000000, LENGTH = 0x0000FF7F
  bootloader (rx) : ORIGIN = 0x00010000, LENGTH = 0x00001000
}



static void __attribute__((section(".bootloader"))) callIAP(void) __attribute((naked));
static void __attribute__((section(".bootloader"))) callIAP(void)
{
  // fast way to get the address of flashParams[] directly into r0
  register void *pFP asm("r0") = command;

  asm volatile(" mov r1, r0\n"          // copy &flashParams[] into r1
               " bx  %[iapLocation]"    // 'bx' because IAP is Thumb mode
               :
               : "r" (pFP), [iapLocation] "r" (IAP_LOCATION)
               : "r1" );
}

void __attribute__((section(".bootloader"))) startflash(void) 
{
unsigned char y, x, fbuf[512], trr;
unsigned long startadr, destadr;
unsigned char *ptr;
disableIRQ();
VICVectCntl0 = 0;
VICVectCntl1 = 0;
VICVectCntl2 = 0;
VICIntEnable = 0;    

SCB_PLLCON = 0;//turn off PLL
SCB_PLLFEED = PLL_FEED1;
SCB_PLLFEED = PLL_FEED2;

MAM_MAMCR = 0; 
startadr=262144;
destadr=0;
for (x=0;x<7;x++) { 
   trr=30;
   tryprepareagain:
   trr--;
   if (trr==0) goto flasherror;
   command[0]=50;//prepare sector
   command[1]=x;
   command[2]=x;
   callIAP();
   if (command[0]!=0) goto tryprepareagain;


   command[0]=52;//erase sector
   command[1]=x;
   command[2]=x;
   command[3]=7328;
   callIAP();
   
   command[0]=53;//blank check
   command[1]=x;
   command[2]=x;
   callIAP();
   if (command[0]!=0) goto tryprepareagain;
   

   for (y=0;y<16;y++) {
      flash_readbuf(&fbuf[0], startadr, 255);startadr+=256; //read code from external SPI flash memory
      flash_readbuf(&fbuf[256], startadr, 255);startadr+=256;
      prep2:
      command[0]=50;
      command[1]=0;
      command[2]=13;
      callIAP();
      if (command[0]!=0) goto prep2;
      command[0]=51;
      command[1]=destadr;
      command[2]=&fbuf[0];
      command[3]=512;
      command[4]=7328;
      callIAP();


      command[0]=56;
      command[1]=destadr;
      command[2]=&fbuf[0];
      command[3]=512;
      callIAP();
      destadr+=512;
      }
   }
flasherror:
dorestart();   
while (1) ;   
}

      

[Non-text portions of this message have been removed]

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.