Hi,
unfortunately I do not think I understood your question well.
The following is an example of how I implemented the "Program Section" command:
/* ========================================================================== */
/* */
/* Execute the PGMSEC FTFC command */
/* Programs the data found in the section program buffer to previously erased */
/* locations in the flash memory (Address must be 128bit-aligned in PFlash */
/* or 64-bit aligned in DFlash) */
/* */
/* retval WAITING, SUCCESSFUL e FAILED */
/* */
/* ========================================================================== */
UINT8 ProgramSectionCommand(UINT32 address, UINT8 *buff, UINT16 size)
{
register UINT8 res;
UINT16 number;/* Number of double-phrases (128bit) for PFlash and phrases (64bit) for DFlash */
if ((FTFC->FSTAT&FTFC_FSTAT_CCIF_MASK)==0)/* Waiting for previous command completed */
return WAITING;
if ((address>=PFLASH_START_ADDR)&&(address<=PFLASH_END_ADDR))
{
/* Check if destination address is aligned or not */
if ((address&0x0000000F)!=0)/* Must be 128bit aligned */
return FAILED;
number = size/8;/* Number of double-phrases */
}
else if ((address>=DFLASH_START_ADDR)&&(address<=DFLASH_END_ADDR))
{
/* Check if destination address is aligned or not */
if ((address&0x00000007)!=0)/* Must be 64bit aligned */
return FAILED;
number = size/4;/* Number of phrases */
address |= (1<<23);/* bit 23 of the command address select between PFlash (0) and DFlash (1) */
}
else
{
return FAILED;
}
if (size>((FLEXRAM_END_ADDR-FLEXRAM_START_ADDR+1)/4))/* The maxsize of the section program buffer must be less than 1/4 FlexRAM size */
return FAILED;
/* Set FlexRAM function command to make the FlexRAM available As traditional RAM */
do
{
res = SetFlexRamFunctionCommand(EEE_DISABLE, 0, NULL, NULL, NULL);/* Make FlexRAM available as RAM */
}
while (res==WAITING);
if (res==SUCCESSFUL)
{
memcpy((void *)FLEXRAM_START_ADDR, buff, size);
/* Clear old errors */
FTFC->FSTAT = (FTFC_FSTAT_FPVIOL(1)|
FTFC_FSTAT_ACCERR(1)|
FTFC_FSTAT_RDCOLERR(1));
/* Write FCCOB registers with the required command parameters */
SET_FCCOB0(PGMSEC);
SET_FCCOB1(GET_BIT_23_16(address));
SET_FCCOB2(GET_BIT_15_08(address));
SET_FCCOB3(GET_BIT_07_00(address));
SET_FCCOB4(GET_BIT_15_08(number));
SET_FCCOB5(GET_BIT_07_00(number));
DISABLE_INTERRUPTS();
FTFC->FSTAT = FTFC_FSTAT_CCIF(1); /* Clear the CCIF flag to launch the command */
while((FTFC->FSTAT&FTFC_FSTAT_CCIF_MASK)==0); /* Waiting for command completed */
ENABLE_INTERRUPTS();
/* Check if an error is occurred */
if ((FTFC->FSTAT&(FTFC_FSTAT_MGSTAT0_MASK|/* Run-time errors */
FTFC_FSTAT_FPVIOL_MASK| /* Protection error */
FTFC_FSTAT_ACCERR_MASK| /* Access error */
FTFC_FSTAT_RDCOLERR_MASK))!=0U)/* Read Collision Error */
res = FAILED;
else
res = SUCCESSFUL;
}
if (emulatedEEpromEnabled==TRUE)
{
do
{
res = SetFlexRamFunctionCommand(EEE_ENABLE, 0, NULL, NULL, NULL);/* Make FlexRAM available for emulated EEPROM */
}
while (res==WAITING);
}
return res;
}
Hoping to help you,
Best regards
E.