I was successful in writing in the flash in K64F.
However, modifications were needed.
1.Define FTFE
K64F has not FTFA and FTFL.
Must use the FTFE.
#ifdef TARGET_K64F
# include "MK64F12.h"
# define FTFA FTFE
# define FTFA_FSTAT_FPVIOL_MASK FTFE_FSTAT_FPVIOL_MASK
# define FTFA_FSTAT_ACCERR_MASK FTFE_FSTAT_ACCERR_MASK
# define FTFA_FSTAT_RDCOLERR_MASK FTFE_FSTAT_RDCOLERR_MASK
# define FTFA_FSTAT_CCIF_MASK FTFE_FSTAT_CCIF_MASK
# define FTFA_FSTAT_MGSTAT0_MASK FTFE_FSTAT_MGSTAT0_MASK
#else
//Different names used on at least the K20:
# ifndef FTFA_FSTAT_FPVIOL_MASK
# define FTFA FTFL
# define FTFA_FSTAT_FPVIOL_MASK FTFL_FSTAT_FPVIOL_MASK
# define FTFA_FSTAT_ACCERR_MASK FTFL_FSTAT_ACCERR_MASK
# define FTFA_FSTAT_RDCOLERR_MASK FTFL_FSTAT_RDCOLERR_MASK
# define FTFA_FSTAT_CCIF_MASK FTFL_FSTAT_CCIF_MASK
# define FTFA_FSTAT_MGSTAT0_MASK FTFL_FSTAT_MGSTAT0_MASK
# endif
#endif
2.Add "ProgramPhrase" command and change the code to 64 bit unit.
K64F has not ProgramLongword. It is necessary to use the ProgramPhrase instead.
enum FCMD
{
Read1s = 0x01,
ProgramCheck = 0x02,
ReadResource = 0x03,
ProgramLongword = 0x06,
ProgramPhrase = 0x07,
EraseSector = 0x09,
Read1sBlock = 0x40,
ReadOnce = 0x41,
ProgramOnce = 0x43,
EraseAll = 0x44,
VerifyBackdoor = 0x45
};
IAPCode program_flash(int address, char *data, unsigned int length) {
#ifdef IAPDEBUG
printf("IAP: Programming flash at %x with length %d\r\n", address, length);
#endif
if (check_align(address))
return AlignError;
IAPCode eraseCheck = verify_erased(address, length);
if (eraseCheck != Success)
return eraseCheck;
IAPCode progResult;
#ifdef TARGET_K64F
for (int i = 0; i < length; i+=8) {
progResult = program_word(address + i, data + i);
if (progResult != Success)
return progResult;
}
#else
for (int i = 0; i < length; i+=4) {
progResult = program_word(address + i, data + i);
if (progResult != Success)
return progResult;
}
#endif
return Success;
}
IAPCode program_word(int address, char *data) {
#ifdef IAPDEBUG
printf("IAP: Programming word at %x, %d - %d - %d - %d\r\n", address, data[0], data[1], data[2], data[3]);
#endif
if (check_align(address))
return AlignError;
//Setup command
#ifdef TARGET_K64F
FTFA->FCCOB0 = ProgramPhrase;
FTFA->FCCOB1 = (address >> 16) & 0xFF;
FTFA->FCCOB2 = (address >> 8) & 0xFF;
FTFA->FCCOB3 = address & 0xFF;
FTFA->FCCOB4 = data[3];
FTFA->FCCOB5 = data[2];
FTFA->FCCOB6 = data[1];
FTFA->FCCOB7 = data[0];
FTFA->FCCOB8 = data[7];
FTFA->FCCOB9 = data[6];
FTFA->FCCOBA = data[5];
FTFA->FCCOBB = data[4];
#else
FTFA->FCCOB0 = ProgramLongword;
FTFA->FCCOB1 = (address >> 16) & 0xFF;
FTFA->FCCOB2 = (address >> 8) & 0xFF;
FTFA->FCCOB3 = address & 0xFF;
FTFA->FCCOB4 = data[3];
FTFA->FCCOB5 = data[2];
FTFA->FCCOB6 = data[1];
FTFA->FCCOB7 = data[0];
#endif
run_command();
return check_error();
}
Write size is 64bit, but FreescaleIAP worked by this patch.
Hi there
I am looking for a way to write the flash memory of K64F from the program.
FlexRAM seems to good but I can not find out good sample and application note.
Anyone know application notes or sample programs?