Content originally posted in LPCWare by KISHORE_WeP on Fri Feb 20 00:03:17 MST 2015
Thanks for your reply.
As you have mentioned about the size of different sectors, I have clearly taken care of that in my code. But, the problem is, when I try to erase the 17th sector, the control is transferred to HardFault_Handler and it is getting hanged.
/*Defines for 1777 On-chip flash:*/
#define IAP_LOCATION0x1FFF1FF1
#define BYTESIZE(unsigned long)4096
#define CMD_SUCCESS0
#define INVALID_COMMAND1
#define SRC_ADDR_ERROR2
#define DST_ADDR_ERROR 3
#define SRC_ADDR_NOT_MAPPED 4
#define DST_ADDR_NOT_MAPPED 5
#define COUNT_ERROR 6
#define INVALID_SECTOR 7
#define SECTOR_NOT_BLANK 8
#define SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION 9
#define COMPARE_ERROR 10
#define BUSY 11
#define READY 0
#define PrepareSectrforWrite 50
#define CopyRAM2Flash 51
#define EraseSector 52
#define BlankCheckSector 53
#define ReadPartID 54
#define ReadBootCodeVer 55
#define Compare 56
#define ReinvokeISP 57
typedef void (*IAP) (unsigned int [],unsigned int []);
IAP iap_entry;
/*Function Definitions of IAP:*/
unsigned long PrepareSectorForWrite (unsigned long strtsectrno, unsigned long endsectrno)
{
unsigned long *command = (unsigned long*)0x10003000;
unsigned long *output = (unsigned long*)0x10003100;
*command++ = PrepareSectrforWrite;
*command++ = strtsectrno;
*command++ = endsectrno;
return(IAPHandle());
}
unsigned long EraseSectors(unsigned long strtsectrno, unsigned long endsectrno)
{
unsigned long *command = (unsigned long*)0x10003000;
unsigned long *output = (unsigned long*)0x10003100;
if(PrepareSectorForWrite(strtsectrno, endsectrno) == CMD_SUCCESS)
{
*command++ = EraseSector;
*command++ = strtsectrno;
*command++ = endsectrno;
*command++ = 72000UL;
return(IAPHandle());
}
}
unsigned long CopyRAMToFlash(unsigned long destaddr, unsigned long srcaddr, unsigned long size, unsigned long strtsectrno,
unsigned long endsectrno)
{
unsigned long *command = (unsigned long*)0x10003000;
unsigned long *output = (unsigned long*)0x10003100;
if(PrepareSectorForWrite(strtsectrno,endsectrno) == CMD_SUCCESS)
{
*command++ = CopyRAM2Flash;
*command++ = destaddr;
*command++ = srcaddr;
*command++ = size;
*command++ = 72000UL;
return(IAPHandle());
}
}
unsigned long IAPHandle(void)
{
unsigned long *command = (unsigned long*)0x10003000;
unsigned long *output = (unsigned long*)0x10003100;
unsigned long statuscode=0xFF;
iap_entry = (IAP) IAP_LOCATION;
iap_entry(command,output);
statuscode = *output;
return(statuscode);
}
void BootLoaderHandler (void)
{
while((EraseSectors(17,17)) != CMD_SUCCESS)
{
;
}
while(CopyRAMToFlash((unsigned long)0x00018000,(unsigned long)0x10004000,BYTESIZE,17,17) != CMD_SUCCESS)
{
;
}
}
void main(void)
{
SCB->VTOR = 0x00000000 & 0x3FFFFF80;
BootLoaderHandler();
}
Actually, my intention is, for the first case I would program through JTAG interface, and from next time onwards, to store the firmware in IROM I am using IAP.
I need to write the generated Binary file to IROM because once programmed through JTAG, I will be using parallel interface for receiving the binary file and this file has to be wriiten to on-chip flash using the above algorithm.
I am running the above algorithm in on-chip RAM but, once the EraseSectors() function is called
then I am not able to receive the bytes through parallel interface because the entire flash is getting erased and the code is not running.
So, please suggest me a method to overcome this.Thanks.