lpcware

IAP not working?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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.
}

Outcomes