IAP not working?

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

IAP not working?

784 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LeonCorleone on Thu Feb 05 09:37:10 MST 2015
Hello all
I'm confused and I don't know how to do with this.
I want to write some data from sram to flash and I use IAP ,however the code is compiled correctly but it doesn't write anything on flash.
I'm programming with Keil. maybe problem is with software .
If somebody can help me I appreciate it.


my code is>>

#include <lpc17xx.h> //lpc17xx
#include <absacc.h> //absacc

void disconnect_PLL(void);
void connect_PLL(void);

unsigned char IAP_Write(unsigned char *string);
unsigned char a[5] __at(0x10000200);

#define IAP_ADDRESS  0x1FFF1FF1
unsigned int command[5];
unsigned int result[5];
typedef unsigned int (*IAP)(unsigned int[], unsigned int[]);
static const IAP iap_entry = (IAP) IAP_ADDRESS;

int main(void)
{
unsigned char i=0;


LPC_SC->CLKSRCSEL|=0x00000001;//Define the main Oscillator as Clock Source.
LPC_SC->SCS|=0x00000020;//Set the main Oscillator and Set Clock between 1Mhz till 20MHZ.
LPC_SC->PLL0CON|=0x00000003;   //Enable PLL0 and connect to the Clock system.
LPC_SC->PLL0CFG|=0x00070067;  //Set the Msel=103 and Nsel=7 , means 16Mhz increases to 416MHZ.
LPC_SC->CCLKCFG|=0x00000003;  //Divide 416 MHz by 4 equals 104MHZ.So CPU Clock is 104MHZ.
LPC_SC->PCLKSEL0|=0x03000000; //Set the Adc Clock :104/8=13MHZ.
for(i=0;i<5;i++)
a=i;
IAP_Write(a);
}
unsigned char IAP_Write(unsigned char *string)
{
disconnect_PLL();
command[0]=50;
command[1]=8;  //Start sector number is 8
command[2]=8;  //Finish sector number is 8
  iap_entry(command,result);
if(result[0]!=0)
{
connect_PLL();
return 0;
}
command[0]=51;
command[1]=0x00008100;  //Addrees of Flash
command[2]=0x10000200;  //Addrees of Sram
command[3]=256;  //How many bytes want to transfer
command[4]=12000;  //Frequency in khz
iap_entry(command,result);
if(result[0]!=0)
{
connect_PLL();
return 0;
}
else
{
connect_PLL();
return 1;
}
}

void disconnect_PLL(void)
{
LPC_SC->PLL0CON=0x00000001;   //Enable PLL0 bud it is disconnected.

LPC_SC->PLL0FEED|=0xAA;//------|//      |=======>>   Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|//      |=======>>   Feed Sequence.

LPC_SC->PLL0CON=0x00000000;   //Disable PLL0 and it is disconnected.

LPC_SC->PLL0FEED|=0xAA;//------|//      |=======>>   Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|//      |=======>>   Feed Sequence.
}
void connect_PLL(void)
{
LPC_SC->PLL0CON=0x00000001;   //Enable PLL0

LPC_SC->PLL0FEED|=0xAA;//------|//      |=======>>   Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|//      |=======>>   Feed Sequence.

LPC_SC->PLL0CON=0x00000003;   //Connect PLL0 to the cpu clock.

LPC_SC->PLL0FEED|=0xAA;//------|//      |=======>>   Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|//      |=======>>   Feed Sequence.
}
Labels (1)
0 Kudos
Reply
2 Replies

690 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LeonCorleone on Fri Feb 06 03:06:51 MST 2015
thanks R2D2 to answer
In my program I'm also using the ADC unit for some work.
Actually for IAP I'm using clock 12Mhz and first I 've disabled the PLL unit.
but when I debug the program,it writes in sram but nothing in flash.  :(
I don't know what my problem is.
I also have the same problem with below code ==>
thanks again.

my code is>>

#include //lpc17xx
#include //absacc

void disconnect_PLL(void);
void connect_PLL(void);

unsigned char IAP_Write(unsigned char *string);
unsigned char a[5] __at(0x10000200);

#define IAP_ADDRESS 0x1FFF1FF1
unsigned int command[5];
unsigned int result[5];
typedef unsigned int (*IAP)(unsigned int[], unsigned int[]);
static const IAP iap_entry = (IAP) IAP_ADDRESS;

int main(void)
{
unsigned char i=0;
for(i=0;i<5;i++)
a=i;
IAP_Write(a);
}
unsigned char IAP_Write(unsigned char *string)
{
disconnect_PLL();
command[0]=50;
command[1]=8; //Start sector number is 8
command[2]=8; //Finish sector number is 8
iap_entry(command,result);
if(result[0]!=0)
{
connect_PLL();
return 0;
}
command[0]=51;
command[1]=0x00008100; //Addrees of Flash
command[2]=0x10000200; //Addrees of Sram
command[3]=256; //How many bytes want to transfer
command[4]=12000; //Frequency in khz
iap_entry(command,result);
if(result[0]!=0)
{
connect_PLL();
return 0;
}
else
{
connect_PLL();
return 1;
}
}

void disconnect_PLL(void)
{
LPC_SC->PLL0CON=0x00000001; //Enable PLL0 bud it is disconnected.

LPC_SC->PLL0FEED|=0xAA;//------|// |=======>> Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|// |=======>> Feed Sequence.

LPC_SC->PLL0CON=0x00000000; //Disable PLL0 and it is disconnected.

LPC_SC->PLL0FEED|=0xAA;//------|// |=======>> Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|// |=======>> Feed Sequence.
}
void connect_PLL(void)
{
LPC_SC->PLL0CON=0x00000001; //Enable PLL0

LPC_SC->PLL0FEED|=0xAA;//------|// |=======>> Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|// |=======>> Feed Sequence.

LPC_SC->PLL0CON=0x00000003; //Connect PLL0 to the cpu clock.

LPC_SC->PLL0FEED|=0xAA;//------|// |=======>> Feed Sequence.
LPC_SC->PLL0FEED|=0x55;//------|// |=======>> Feed Sequence.
}
0 Kudos
Reply

690 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Feb 05 11:52:54 MST 2015

Quote: LeonCorleone

...
  command[4]=12000;  //Frequency in khz
...



I'm confused  :~

What's your main clock speed  :quest: 12MHz, 16Mhz, 104Mhz, 23 7/8 MHz  :quest: 
0 Kudos
Reply