IAP problem LPC2138

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IAP problem LPC2138

2,475 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Mon Nov 04 23:41:36 MST 2013
Hi i have some problem in writing operation can anyone help me to understand what’s wrong in my codes??? (Sorry about my poor English)




#include "config.h"
#include "gpio.h"
//#include "iap_driver.h"
void delay_ms(us32 t)
{
  t=t*2000;
  while(t--);
}

enum state
{
  on,
  off
}x;

void main (void)
{
int javab =0  ;
  int *a[1000];
   
p1_out_init_bit(19);
p0_in_init_bit(6);
//p0_clr_bit(19);

while(1)
{


  if (p0_read_bit(6)==1)
  {

    if (x==on)
    {
      p1_set_bit(19);
      x=off;
    }
    else
    {
      p1_clr_bit(19);
      x=on;
    }
    p0_out_init_bit(19);
    while (1){
      #define IAP_LOCATION 0x7ffffff1;    
      char a[256];
      int b=0;
      for (b=0;b<256;b++)
        a=b;
     unsigned int command[5];
     unsigned int result[2];
     typedef void (*IAP)(unsigned int [],unsigned int[]);
     IAP iap_entry;
     iap_entry=(IAP) IAP_LOCATION;
     command[0]=50;
     command[1]=6;
     command[2]=6;
     iap_entry (command, result);
     //iap_entry=(IAP) IAP_LOCATION;
     command[0]=51;
     command[1]=(unsigned long)0x00058000;
     command[2]=(unsigned short)&a;
     command[3]=256;
     command[4]=12000;
    iap_entry (command, result);
   
     command[0]=53;
     command[1]=5;
     command[2]=5;//0x00027fff;
     command[3]=0;
     command[4]=0;
     iap_entry (command, result);     
     p0_set_bit(19);
     delay_ms(500);
     p0_clr_bit(19);
      delay_ms(500);
            while(1);

    }}



}
}
Labels (1)
0 Kudos
19 Replies

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 05:53:34 MST 2013
The problem are solve the address of the page are 0x6000  not 0x60000  ;-)
thank you very much
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 05:11:02 MST 2013
                                                                     at the end 
                                                              thank you capiman
                                                                          :bigsmile:
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 04:59:49 MST 2013
it’s not work   :((
#include "config.h"
#include "gpio.h"
//#include "iap_driver.h"
void delay_ms(us32 t)
{
  t=t*2000;
  while(t--);
}

enum state
{
  on,
  off
}x;

void main (void)
{
  //pll_init (4,1);  
p1_out_init_bit(19);
p0_in_init_bit(6);
//p0_clr_bit(19);

while(1)
{


  if (p0_read_bit(6)==1)
  {

    if (x==on)
    {
      p1_set_bit(19);
      x=off;
    }
    else
    {
      p1_clr_bit(19);
      x=on;
    }
    p0_out_init_bit(19);
    while (1){
      #define IAP_LOCATION 0x7ffffff1;    
      char a[256];
      int b=0;
      for (b=0;b<256;b++)
       a[ b ]=b;
     unsigned int command[5];
     unsigned int result[2];
     typedef void (*IAP)(unsigned int [],unsigned int[]);
     IAP iap_entry;
     iap_entry=(IAP) IAP_LOCATION;
   
    
    
    command[0]=50;
     command[1]=6;
     command[2]=6;
     iap_entry (command, result);
    
     command[0]=52;
     command[1]=6;
     command[2]=6;
     command[3]=12000;
     iap_entry (command, result);
    
     command[0]=50;
     command[1]=6;
     command[2]=6;
     iap_entry (command, result);
   
     iap_entry=(IAP) IAP_LOCATION;
    
     command[0]=51;
     command[1]=(unsigned long)0x00060000;
     command[2]=(unsigned long)&a;
     command[3]=256;
     command[4]=12000;
     iap_entry (command, result);

   
     command[0]=53;
     command[1]=5;
     command[2]=5;//0x00027fff;
     command[3]=0;
     command[4]=0;
     iap_entry (command, result);     
     p0_set_bit(19);
     delay_ms(500);
     p0_clr_bit(19);
      delay_ms(500);
            while(1);

    }}



}
}
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 04:46:38 MST 2013
my processor mode are in ARM mode is it important ?
i check the thumb mode and it’s not change  :~
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Tue Nov 05 04:40:50 MST 2013
I think you must prepare before erase (what you are already doing),
and then prepare again, before copy RAM to flash.

You have at the bottom a "blank check" which still uses sector 5, but i think does not matter at the moment.

Try to delete the following in your code:
int javab =0 ;
int *a[256];
Both are not used and especially "a" can make problems. You have a second one, which is ok.

for (b=0;b<256;b++)
a[ b ]=b;
a[ b ]=b;

Could be a cut&paste error, but the second "a[ b ]=b;" can make problems, because at the end of the loop b = 256 (to abort the loop),
so when you do the second "a[ b ]=b;" (which is behind/outside the loop), it is

a[256] = 256;

which is writing behind the variable "a". This can destroy any other variable (random, what is behind "a").
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 04:30:57 MST 2013
I change the code to :

#include "config.h"
#include "gpio.h"
//#include "iap_driver.h"
void delay_ms(us32 t)
{
  t=t*2000;
  while(t--);
}

enum state
{
  on,
  off
}x;

void main (void)
{
  //pll_init (4,1);
int javab =0  ;
int *a[256];
   
p1_out_init_bit(19);
p0_in_init_bit(6);
//p0_clr_bit(19);

while(1)
{


  if (p0_read_bit(6)==1)
  {

    if (x==on)
    {
      p1_set_bit(19);
      x=off;
    }
    else
    {
      p1_clr_bit(19);
      x=on;
    }
    p0_out_init_bit(19);
    while (1){
      #define IAP_LOCATION 0x7ffffff1;    
      char a[256];
      int b=0;
      for (b=0;b<256;b++)
        a[ b ]=b;
      a[ b ]=b;
     unsigned int command[5];
     unsigned int result[2];
     typedef void (*IAP)(unsigned int [],unsigned int[]);
     IAP iap_entry;
     iap_entry=(IAP) IAP_LOCATION;
    
   command[0]=52;
     command[1]=6;
     command[2]=6;
     command[3]=12000;
     iap_entry (command, result);
    
     command[0]=50;
     command[1]=6;
     command[2]=6;
     iap_entry (command, result);
     //iap_entry=(IAP) IAP_LOCATION;
    // iap_entry=(IAP) IAP_LOCATION;
     command[0]=51;
     command[1]=(unsigned long)0x00060000;
     command[2]=(unsigned long)&a;
     command[3]=256;
     command[4]=12000;
     iap_entry (command, result);

   
     command[0]=53;
     command[1]=5;
     command[2]=5;//0x00027fff;
     command[3]=0;
     command[4]=0;
     iap_entry (command, result);     
     p0_set_bit(19);
     delay_ms(500);
     p0_clr_bit(19);
      delay_ms(500);
            while(1);

    }}



}
}


When i send command 52 the returned code is zero
And then i send command 50 the retune code also is zero
But when i send command 51 the answer are 9
This IAP problem makes me mad
Thank you to help me to solve this problem

0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Tue Nov 05 04:01:45 MST 2013
Latest user manual (see here http://www.lpcware.com/content/nxpfile/um10120-lpc21312468-user-manual )
has description of error 9:

9 SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION
Command to prepare sector for write operation was
not executed.

So it looks like you have not executed a suitable prepare command, where the address of the later write is in this sector.

Does the prepare perhaps already give an error?

0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 02:37:27 MST 2013
i attach all of my project if it can help
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 02:11:39 MST 2013
i change them and the error change to 9 and the answer of 9 is not in the datasheet

1073749756 = 0x40001EFC

datasheet say
:
Param1(SRC): Source RAM address from which data bytes are to be read. This
address should be a word boundary
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Tue Nov 05 01:50:42 MST 2013
7932 = 0x1EFC
So it looks like only 16 bits (instead of 32 bits) of the address were used.
Have you changed the "unsigned short" to "unsigned long"?
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 01:39:48 MST 2013
the address of the a is 7932 but the jtage simulator say 0x40001EFC
I’m confuse   :~
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Tue Nov 05 01:22:26 MST 2013
Can you show what values you have when you call the IAP function?
Is it perhaps an alignment problem, that address of "a" must be on a 4 byte (or even higher) boundary?
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Tue Nov 05 01:20:50 MST 2013
Look into chapter 20.9.9
Error Code 4 means SRC_ADDR_NOT_MAPPED
Source address is not mapped in the memory map.
Count value is taken in to consideration where
applicable.

So it looks to be something in area of source address.

"unsigned short" is wrong, because you want to give an address in SRAM, which is not located in first 64 KBytes,
but unsigned short is only 2 bytes long, and can be a maximum of 65536.
Just try out an "unsigned long" instead of "unsigned short" and check if you still get the same error value 4.
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 01:18:52 MST 2013
Thx capiman for your answer
the error 4 is steel not change
I think the error 4 means SRC_ADDR_NOT_MAPPED |
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 01:14:04 MST 2013
I’m not sure about (unsigned short)
But the error code and the answer  datasheet writhe this 

Table 247. IAP Copy RAM to Flash command
Command Copy RAM to Flash
Input Command code: 5110
Param0(DST): Destination Flash address where data bytes are to be written. This
address should be a 256 byte boundary.
Param1(SRC): Source RAM address from which data bytes are to be read. This
address should be a word boundary.
Param2: Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
Param3: System Clock Frequency (CCLK) in kHz.
Return Code CMD_SUCCESS |
SRC_ADDR_ERROR (Address not a word boundary) |
DST_ADDR_ERROR (Address not on correct boundary) |
SRC_ADDR_NOT_MAPPED |
DST_ADDR_NOT_MAPPED |
COUNT_ERROR (Byte count is not 256 | 512 | 1024 | 4096) |
SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION |
BUSY |
Result None
Description This command is used to program the flash memory. The affected sectors should
be prepared first by calling "Prepare Sector for Write Operation" command. The
affected sectors are automatically protected again once the copy command is
successfully executed. The boot sector can not be written by this command.
Table 248.
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Tue Nov 05 01:08:56 MST 2013
command[2]=(unsigned short)&a;
"unsigned short" seems also to be wrong here.

Have you checked return value in result? Still error 4? Have you looked up, what it means?
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Tue Nov 05 01:06:10 MST 2013
Thx for you answer
i change the code to

command[0]=51;
     command[1]=(unsigned long)0x00060000;
     command[2]=(unsigned short)&a;
     command[3]=256;
     command[4]=12000;
But the problem not solve
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Mon Nov 04 23:58:50 MST 2013
Avoid doing the write action in a loop. Number of write actions are limited. When you do it in a loop, it writes and writes and writes...till sector is unusable...
0 Kudos

2,175 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Mon Nov 04 23:56:57 MST 2013
Hello,
you prepare sector 6 but write to sector 5.
You can only write to empty sectors.
Best regards,
Martin

0 Kudos