lpcware

LPC812 IAP Copy Command not Affecting Destination

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Rorrik on Wed Feb 18 13:18:48 MST 2015
I'm trying to copy from one part of flash memory to another on the LPC812. After running the code below, a compare between the two blocks of memory reveals that they are not the same, and by looking at the flash in disassembly, I can see the code in the source block is there, and that the destination block is still blank.
int eraseAddress = 0x1000;
int eraseEnd=0x2400;
int sectorSize = 0x400;
unsigned long PrepareCommand[4];
unsigned long results[3];
PrepareCommand[0]=50;
PrepareCommand[1]=eraseAddress/sectorSize;
PrepareCommand[2]=eraseEnd/sectorSize;
iap_entry (PrepareCommand,results);
unsigned long EraseCommand[4];
EraseCommand[0]=52;
EraseCommand[1]=eraseAddress/sectorSize;
EraseCommand[2]=eraseEnd/sectorSize;
EraseCommand[3]=12000;
iap_entry (EraseCommand,results);
iap_entry (PrepareCommand,results);
unsigned long CopyCommand[5];
CopyCommand[0]=51;
CopyCommand[4]=12000;
int startDestAddress=0x1000;
int startSrcAddress=0x2800;
int ProgramLength=0x1800;
int idx=0;
while(ProgramLength-idx*1024>0)
{
  CopyCommand[1]=startDestAddress+idx*1024;
  CopyCommand[2]=startSrcAddress+idx*1024;
  //Needs to be a power of 2 greater than 64, up to 1024
  if(ProgramLength-idx*1024>1024)
  {
  CopyCommand[3]=1024;
  }
  else
  {
  CopyCommand[3]=ProgramLength-idx*1024;
  }
  idx++;
  iap_entry (CopyCommand,results);
}

I suspect one of two things: 1) The system clock frequency for the copy is wrong, but I think the default clock is 12 MHz, is that wrong? 2) The copy command is specifically "Copy RAM to Flash" and I am trying to copy Flash to Flash. Could this be the problem?

Thanks

Outcomes