Forums

LPC2146 IAP Erase & Write not working.

Started by mark_dell555 December 8, 2005
Hi, I'm having a problem erasing the flash with IAP calls on my
lpc2146. I'm making calls to the IAP, and get the chip id fine from
the IAP. Next I make a call to Prepare the flash for writing (50d),
and I get CMD_SUCCESS (0d) as the response. Then I make a call to
Erase to wipe some sectors where I know I have data (min sector=5 max
sector), and again i get CMD_SUCCESS (0d), but the IAP hasnt erased
anything, and has only spent 300us completing both those calls.

I'm running in User mode, I have interrupts enabled, and all the
handlers for the interrupts are in RAM. Is there something I am
missing? Is there anything else I can try?

Any help is always greatly appriciated.

Cheers,
Mark


An Engineer's Guide to the LPC2100 Series

The only thing I can think of is that the IAP routines may not work in
user mode. Try switching to system mode before calling an IAP routine.

Richard. mark_dell555 wrote:

> Hi, I'm having a problem erasing the flash with IAP calls on my
> lpc2146. I'm making calls to the IAP, and get the chip id fine from
> the IAP. Next I make a call to Prepare the flash for writing (50d),
> and I get CMD_SUCCESS (0d) as the response. Then I make a call to
> Erase to wipe some sectors where I know I have data (min sector=5 max
> sector), and again i get CMD_SUCCESS (0d), but the IAP hasnt erased
> anything, and has only spent 300us completing both those calls.
>
> I'm running in User mode, I have interrupts enabled, and all the
> handlers for the interrupts are in RAM. Is there something I am
> missing? Is there anything else I can try?
>
> Any help is always greatly appriciated.
>
> Cheers,
> Mark


Tried SVC mode, with interrupts both enable and disabled. The result
is still the same.

--- In lpc2000@lpc2..., Richard Duits <yahoo@r...> wrote:
>
> The only thing I can think of is that the IAP routines may not work in
> user mode. Try switching to system mode before calling an IAP routine.
>
> Richard. > mark_dell555 wrote:
>
> > Hi, I'm having a problem erasing the flash with IAP calls on my
> > lpc2146. I'm making calls to the IAP, and get the chip id fine from
> > the IAP. Next I make a call to Prepare the flash for writing (50d),
> > and I get CMD_SUCCESS (0d) as the response. Then I make a call to
> > Erase to wipe some sectors where I know I have data (min sector=5 max
> > sector), and again i get CMD_SUCCESS (0d), but the IAP hasnt erased
> > anything, and has only spent 300us completing both those calls.
> >
> > I'm running in User mode, I have interrupts enabled, and all the
> > handlers for the interrupts are in RAM. Is there something I am
> > missing? Is there anything else I can try?
> >
> > Any help is always greatly appriciated.
> >
> > Cheers,
> > Mark
>




This code works:
http://groups.yahoo.com/group/lpc2000/files/EE_demo.zip
(code here modified from original)

unsigned int command_iap[5];
unsigned int result_iap[3];
unsigned char memmap;

__disable_interrupt();
memmap = MEMMAP; // get current memory map
MEMMAP = MEMMAP_FLASH; // map User Flash into low 64 bytes

command_iap[0]P; //prepare sectors for erase
command_iap[1]SEC_L;
command_iap[2]SEC_H;
iap_entry=(IAP) IAP_LOCATION;
iap_entry(command_iap,result_iap);

command_iap[0]R; //erase sectors
command_iap[1]SEC_L;
command_iap[2]SEC_H;
command_iap[3]CCLK;
iap_entry=(IAP) IAP_LOCATION;
iap_entry(command_iap,result_iap);

command_iap[0]S; //blankcheck sectors
command_iap[1]SEC_L;
command_iap[2]SEC_H;
iap_entry=(IAP) IAP_LOCATION;
iap_entry(command_iap,result_iap);

MEMMAP = memmap & 0x03; // restore the memory map
__enable_interrupt(); Joel


Thanks for the snippet, I tried everything in this code and almost
gave up, then just by accident I noticed that erase has a 3rd
parameter (CCLK). Cant believe I wasted 2 days trying to fix
something so simple. Mark
--- In lpc2000@lpc2..., "Joel Winarske" <joelw@i...> wrote:
>
> This code works:
> http://groups.yahoo.com/group/lpc2000/files/EE_demo.zip
> (code here modified from original)
>
> unsigned int command_iap[5];
> unsigned int result_iap[3];
> unsigned char memmap;
>
> __disable_interrupt();
> memmap = MEMMAP; // get current memory map
> MEMMAP = MEMMAP_FLASH; // map User Flash into low 64 bytes
>
> command_iap[0]P; //prepare sectors for erase
> command_iap[1]SEC_L;
> command_iap[2]SEC_H;
> iap_entry=(IAP) IAP_LOCATION;
> iap_entry(command_iap,result_iap);
>
> command_iap[0]R; //erase sectors
> command_iap[1]SEC_L;
> command_iap[2]SEC_H;
> command_iap[3]CCLK;
> iap_entry=(IAP) IAP_LOCATION;
> iap_entry(command_iap,result_iap);
>
> command_iap[0]S; //blankcheck sectors
> command_iap[1]SEC_L;
> command_iap[2]SEC_H;
> iap_entry=(IAP) IAP_LOCATION;
> iap_entry(command_iap,result_iap);
>
> MEMMAP = memmap & 0x03; // restore the memory map
> __enable_interrupt(); > Joel
>




> Thanks for the snippet, I tried everything in this code and almost
> gave up, then just by accident I noticed that erase has a 3rd
> parameter (CCLK). Cant believe I wasted 2 days trying to fix
> something so simple.

You bet!

Joel


Hi Joe,
I got it work but as soon as I turn on any interrupt it hang.
do you have some thing that works already?
thanks

--- In lpc2000@lpc2..., "Joel Winarske" <joelw@i...> wrote:
>
> This code works:
> http://groups.yahoo.com/group/lpc2000/files/EE_demo.zip
> (code here modified from original)
>
> unsigned int command_iap[5];
> unsigned int result_iap[3];
> unsigned char memmap;
>
> __disable_interrupt();
> memmap = MEMMAP; // get current memory map
> MEMMAP = MEMMAP_FLASH; // map User Flash into low 64 bytes
>
> command_iap[0]P; //prepare sectors for erase
> command_iap[1]SEC_L;
> command_iap[2]SEC_H;
> iap_entry=(IAP) IAP_LOCATION;
> iap_entry(command_iap,result_iap);
>
> command_iap[0]R; //erase sectors
> command_iap[1]SEC_L;
> command_iap[2]SEC_H;
> command_iap[3]CCLK;
> iap_entry=(IAP) IAP_LOCATION;
> iap_entry(command_iap,result_iap);
>
> command_iap[0]S; //blankcheck sectors
> command_iap[1]SEC_L;
> command_iap[2]SEC_H;
> iap_entry=(IAP) IAP_LOCATION;
> iap_entry(command_iap,result_iap);
>
> MEMMAP = memmap & 0x03; // restore the memory map
> __enable_interrupt(); > Joel
>


I have example project for IAR. It uses the code as listed below.

Joel > Hi Joe,
> I got it work but as soon as I turn on any interrupt it hang.
> do you have some thing that works already?
> thanks
>
> --- In lpc2000@lpc2..., "Joel Winarske" <joelw@i...> wrote:
> >
> > This code works:
> > http://groups.yahoo.com/group/lpc2000/files/EE_demo.zip
> > (code here modified from original)
> >
> > unsigned int command_iap[5];
> > unsigned int result_iap[3];
> > unsigned char memmap;
> >
> > __disable_interrupt();
> > memmap = MEMMAP; // get current memory map
> > MEMMAP = MEMMAP_FLASH; // map User Flash into low 64 bytes
> >
> > command_iap[0]P; //prepare sectors for erase
> > command_iap[1]SEC_L;
> > command_iap[2]SEC_H;
> > iap_entry=(IAP) IAP_LOCATION;
> > iap_entry(command_iap,result_iap);
> >
> > command_iap[0]R; //erase sectors
> > command_iap[1]SEC_L;
> > command_iap[2]SEC_H;
> > command_iap[3]CCLK;
> > iap_entry=(IAP) IAP_LOCATION;
> > iap_entry(command_iap,result_iap);
> >
> > command_iap[0]S; //blankcheck sectors
> > command_iap[1]SEC_L;
> > command_iap[2]SEC_H;
> > iap_entry=(IAP) IAP_LOCATION;
> > iap_entry(command_iap,result_iap);
> >
> > MEMMAP = memmap & 0x03; // restore the memory map
> > __enable_interrupt();
> >
> >
> > Joel
> > Yahoo! Groups Links >



Joel Winarske wrote:
> I have example project for IAR. It uses the code as listed below.
>
> Joel >
>>Hi Joe,
>>I got it work but as soon as I turn on any interrupt it hang.
>>do you have some thing that works already?
>>thanks
>>

I read something in the manual, that interrupts _must_ be turned off
while using IAP routines. Otherwise it may result in unexpected behaviour. --
/************************************************
Do you need a tiny and efficient real time
operating system (RTOS) with a preemtive
multitasking for LPC2000 or AT91SAM7?

http://nanortos.net-attack.de/

Or some open-source tools and code for LPC2000?

http://www.net-attack.de/

************************************************/



Hi Joel,
My MEMMAP EQU 0XE01FC040
but I can't find my MEMMAP_FLASH.
is this something you define? right
if so I am using the LPC2138, therefore it should be the beginning of my code?
Thanks Joel Winarske <joelw@joel...> wrote:
I have example project for IAR. It uses the code as listed below.

Joel > Hi Joe,
> I got it work but as soon as I turn on any interrupt it hang.
> do you have some thing that works already?
> thanks
>
> --- In lpc2000@lpc2..., "Joel Winarske" <joelw@i...> wrote:
> >
> > This code works:
> > http://groups.yahoo.com/group/lpc2000/files/EE_demo.zip
> > (code here modified from original)
> >
> > unsigned int command_iap[5];
> > unsigned int result_iap[3];
> > unsigned char memmap;
> >
> > __disable_interrupt();
> > memmap = MEMMAP; // get current memory map
> > MEMMAP = MEMMAP_FLASH; // map User Flash into low 64 bytes
> >
> > command_iap[0]P; //prepare sectors for erase
> > command_iap[1]SEC_L;
> > command_iap[2]SEC_H;
> > iap_entry=(IAP) IAP_LOCATION;
> > iap_entry(command_iap,result_iap);
> >
> > command_iap[0]R; //erase sectors
> > command_iap[1]SEC_L;
> > command_iap[2]SEC_H;
> > command_iap[3]CCLK;
> > iap_entry=(IAP) IAP_LOCATION;
> > iap_entry(command_iap,result_iap);
> >
> > command_iap[0]S; //blankcheck sectors
> > command_iap[1]SEC_L;
> > command_iap[2]SEC_H;
> > iap_entry=(IAP) IAP_LOCATION;
> > iap_entry(command_iap,result_iap);
> >
> > MEMMAP = memmap & 0x03; // restore the memory map
> > __enable_interrupt();
> >
> >
> > Joel
> > Yahoo! Groups Links >


SPONSORED LINKS
Microprocessor Microcontrollers Pic microcontrollers 8051 microprocessor

---------------------------------
YAHOO! GROUPS LINKS ---------------------------------
---------------------------------
Yahoo! DSL Something to write home about. Just $16.99/mo. or less