IAP problem

Started by Michal Krestan August 24, 2005
Hi,

I'm using IAP programming in my application with LPC2106. It works fine, but in one of about 5 tries my procedure for firmware update will hang somewhere (probably in callIAP) and after hardware reset, in MCU still remains the same code without any modification. Does anyone have recommended flowchart for using IAP? Do I have to check result of IAP prepare command and result of other IAP calls? For example, I don't know what to do if I'll get busy result after IAP call. Do I have to make infinite loop with call of the same command until it's sucessfull? My code for fw update is following:

It will copy new firmware sotred in external SPI flash memory. This procedure is compiled in ARM mode, located in 8th sector of flash memory.

void __attribute__((section(".bootloader"))) startflash(void)
{
disableIRQ();
VICVectCntl0 = 0;
VICVectCntl1 = 0;
VICVectCntl2 = 0;

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

MAM_MAMCR = 0;
startadr&2144;
destadr=0;
for (x=0;x<7;x++) {
command[0]P;
command[1]=x;
command[2]=x;
callIAP();
command[0]R;
command[1]=x;
command[2]=x;
command[3]s28;
callIAP();
for (y=0;y<16;y++) {
flash_readbuf(&fbuf[0], startadr, 255);startadr+%6;
flash_readbuf(&fbuf[256], startadr, 255);startadr+%6;
command[0]P;
command[1]=0;
command[2];
callIAP();
command[0]Q;
command[1]tadr;
command[2]=&fbuf[0];
command[3]Q2;
command[4]s28;
callIAP();
command[0]V;
command[1]tadr;
command[2]=&fbuf[0];
command[3]Q2;
callIAP();
destadr+Q2;
}
}
dorestart();
while (1) ;
} Regards,
Michal


An Engineer's Guide to the LPC2100 Series

older version of philips boot loader had some issue and it would
lock up sometimes.

On philips website, you will find a hex file and the steps to update
the boot loader.

I think (not sure) I had problem with version 1.61 and updated to
1.63 to fix --- In lpc2000@lpc2..., "Michal Krestan" <krestan@h...>
wrote:
> Hi,
>
> I'm using IAP programming in my application with LPC2106. It works
fine, but in one of about 5 tries my procedure for firmware update
will hang somewhere (probably in callIAP) and after hardware reset,
in MCU still remains the same code without any modification. Does
anyone have recommended flowchart for using IAP? Do I have to check
result of IAP prepare command and result of other IAP calls? For
example, I don't know what to do if I'll get busy result after IAP
call. Do I have to make infinite loop with call of the same command
until it's sucessfull? My code for fw update is following:
>
> It will copy new firmware sotred in external SPI flash memory.
This procedure is compiled in ARM mode, located in 8th sector of
flash memory.
>
> void __attribute__((section(".bootloader"))) startflash(void)
> {
> disableIRQ();
> VICVectCntl0 = 0;
> VICVectCntl1 = 0;
> VICVectCntl2 = 0;
>
> SCB_PLLCON = 0;//turn off PLL
> SCB_PLLFEED = PLL_FEED1;
> SCB_PLLFEED = PLL_FEED2;
>
> MAM_MAMCR = 0;
> startadr&2144;
> destadr=0;
> for (x=0;x<7;x++) {
> command[0]P;
> command[1]=x;
> command[2]=x;
> callIAP();
> command[0]R;
> command[1]=x;
> command[2]=x;
> command[3]s28;
> callIAP();
> for (y=0;y<16;y++) {
> flash_readbuf(&fbuf[0], startadr, 255);startadr+%6;
> flash_readbuf(&fbuf[256], startadr, 255);startadr+%6;
> command[0]P;
> command[1]=0;
> command[2];
> callIAP();
> command[0]Q;
> command[1]tadr;
> command[2]=&fbuf[0];
> command[3]Q2;
> command[4]s28;
> callIAP();
> command[0]V;
> command[1]tadr;
> command[2]=&fbuf[0];
> command[3]Q2;
> callIAP();
> destadr+Q2;
> }
> }
> dorestart();
> while (1) ;
> } > Regards,
> Michal >



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&2144;
destadr=0;
for (x=0;x<7;x++) {
trr0;
tryprepareagain:
trr--;
if (trr==0) goto flasherror;
command[0]P;//prepare sector
command[1]=x;
command[2]=x;
callIAP();
if (command[0]!=0) goto tryprepareagain; command[0]R;//erase sector
command[1]=x;
command[2]=x;
command[3]s28;
callIAP();

command[0]S;//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+%6; //read code from external SPI flash memory
flash_readbuf(&fbuf[256], startadr, 255);startadr+%6;
prep2:
command[0]P;
command[1]=0;
command[2];
callIAP();
if (command[0]!=0) goto prep2;
command[0]Q;
command[1]tadr;
command[2]=&fbuf[0];
command[3]Q2;
command[4]s28;
callIAP(); command[0]V;
command[1]tadr;
command[2]=&fbuf[0];
command[3]Q2;
callIAP();
destadr+Q2;
}
}
flasherror:
dorestart();
while (1) ;
}


Michal

How are you handling interrupts which may occur during programming?
Your interrupt routines must either be completely in RAM or interrupts
must be disabled when the IAP is operating. The second is the easiest
and quickest to do to test whether it improves the situation.

Regards

Mark Butcher
www.mjbc.ch

--- In lpc2000@lpc2..., "Michal Krestan" <krestan@h...> wrote:
>
> 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
...




----- Original Message -----
From: Mark Butcher
To: lpc2000@lpc2...
Sent: Monday, September 05, 2005 5:42 PM
Subject: [lpc2000] Re: IAP problem
Hi,

I've got disabled all interrupts before entering my flash update procedure and it still doesn't work well.

Regards,
Michal Krestan

Michal

How are you handling interrupts which may occur during programming?
Your interrupt routines must either be completely in RAM or interrupts
must be disabled when the IAP is operating. The second is the easiest
and quickest to do to test whether it improves the situation.

Regards

Mark Butcher
www.mjbc.ch

--- In lpc2000@lpc2..., "Michal Krestan" <krestan@h...> wrote:
>
> 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
... SPONSORED LINKS Microprocessor Microcontrollers Pic microcontrollers
8051 microprocessor ------
YAHOO! GROUPS LINKS

a.. ------