Hi ,
Thanks alot for pointing out the mistake.
I modified the flash program file as you said .If it has mistake correct me.Which is in bold colour.Why we are using that PFLASH_Send_Command(); function.
Do i need to change anything in main.
//////////////////////////////////////////////////////////
#include <hidef.h>
#include "lld_flash.h"
//or we can use linker pragmas for placing this function into RAM:
#pragma CODE_SEG DEFAULT_RAM
void PFLASH_Send_Command(void)
{
DisableInterrupts;
FSTAT_CCIF = 1; //launch command
while(FSTAT_CCIF == 0){}; //wait for done
EnableInterrupts;
}
#pragma CODE_SEG DEFAULT
//==============================================================================
//LLD_FLS_Erase_Verify_Section
//==============================================================================
u8 LLD_FLS_Erase_Verify_Section(u32 address, u32 number_of_phrases)
{
//check if address is aligned (global address [2:0] = 000)
if((address & 0x00000007) != 0)
return MISALIGNED_ADDRESS;
while(FSTAT_CCIF == 0){}; //wait if command in progress
FSTAT = 0x30; //clear ACCERR and PVIOL
FCCOBIX = 0x02; //we will write command up to FCCOB2
FCCOB0HI = 0x03;
FCCOB0LO = ((address & 0x00FF0000)>>16);
FCCOB1 = (address & 0x0000FFFF);
FCCOB2 = number_of_phrases;
PFLASH_Send_Command();
if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return ACCESS_ERROR;
//check if phrases are erased and return result
if(FSTAT_MGSTAT != 0)
return NON_ERASED;
else
return ERASED;
}
//==============================================================================
//LLD_FLS_Program
//==============================================================================
u8 LLD_FLS_Program(u32 address, u8 *ptr)
{
u8 i;
//check if address is aligned (global address [2:0] != 000)
if((address & 0x00000007) != 0)
return MISALIGNED_ADDRESS;
//check if the phrase is erased
if((LLD_FLS_Erase_Verify_Section(address, 1)) == NON_ERASED)
return NON_ERASED;
while(FSTAT_CCIF == 0){}; //wait if command in progress
FSTAT = 0x30; //clear ACCERR and PVIOL
FCCOBIX = 0x05; //we will write command up to FCCOB5
FCCOB0HI = 0x06;
FCCOB0LO = ((address & 0x00FF0000)>>16);
FCCOB1 = (address & 0x0000FFFF);
FCCOB2 = ptr[0];
FCCOB3 = ptr[1];
FCCOB4 = ptr[2];
FCCOB5 = ptr[3];
PFLASH_Send_Command();
if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return ACCESS_ERROR;
else
return OK;
}
//==============================================================================
//LLD_FLS_Erase_Sector
//==============================================================================
u8 LLD_FLS_Erase_Sector(u32 address)
{
//size of sector is 512B
//check if address is aligned (global address [2:0] != 000)
if((address & 0x00000007) != 0)
return MISALIGNED_ADDRESS;
while(FSTAT_CCIF == 0){}; //wait if command in progress
FSTAT = 0x30; //clear ACCERR and PVIOL
FCCOBIX = 0x01; //we will write command up to FCCOB1
FCCOB0HI = 0x0A;
FCCOB0LO = ((address & 0x00FF0000)>>16);
FCCOB1 = (address & 0x0000FFFF);
PFLASH_Send_Command();
if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return ACCESS_ERROR;
else
return OK;
}
//==============================================================================
//LLD_FLS_Read_Byte
//==============================================================================
u8 LLD_FLS_Read_Byte(u32 address)
{
u8 data8;
data8 = *(u8 *)address;
return data8;
}
//==============================================================================
//LLD_FLS_Read_Word
//==============================================================================
u32 LLD_FLS_Read_Word(u32 address)
{
u32 data16;
data16 = *(u32 *)address;
return data16;
}
//==============================================================================
//LLD_FLS_Init
//==============================================================================
void LLD_FLS_Init(u8 fdiv)
{
while(FSTAT_CCIF == 0){}; //wait if command in progress
FCLKDIV = fdiv; //osc = ? MHz
}