Hello,
I'm using a Kinetis K61 (MK61FN1M0) and trying to use the FTFE module for boot loading.
I'm able to get Erase Sector and Program Phrase to work, but somehow I spend hours and still couldn't get Flash sector to work (always return ACCERR). I follow through Table 30-53 and verify that my parameters are correct - below is a section of the code that I'm using. I copied the data onto 0x14000000 (the programming acceleration RAM) and if I understand the reference manual correctly, I should be able to flash 4k byte at a time using the Program Sector command.
#define FLASH_PROGRAM_SECTOR 0x0B
#define PROGRAM_SECTOR_INDEX 0x06
LWord FLASH_ProgramSector(LWord destination, LWord size)
{
/* destination must be 128-bit aligned */
unsigned long NumOfDoublePhrase;
/* double phrase align check */
if (destination & 0x0F)
return 0;
NumOfDoublePhrase = size * 8 / 128;
CommandObj.regsLong.fccob3210 = destination;
CommandObj.regs.fccob0 = FLASH_PROGRAM_SECTOR;
CommandObj.regs.fccob4 = (NumOfDoublePhrase & 0xFF00) >> 8;
CommandObj.regs.fccob5 = NumOfDoublePhrase & 0x00FF;
return FLASH_FlashCommandSequence(PROGRAM_SECTOR_INDEX); /* always return ACCERR */
}
/* FLASH_FlashCommandSequenceStart cames from Freescale's Kinetis Serial Bootloader A2295 */
LWord FLASH_FlashCommandSequenceStart(Byte index)
{
Byte* ptrFccobReg = (Byte*)&FLASH_BASE_PTR->FCCOB3;
Byte* ptrCommandObj = (Byte*)&CommandObj;
/* wait till CCIF bit is set */
while(!(FLASH_FSTAT & FLASH_FSTAT_CCIF_MASK)){};
/* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */
FLASH_FSTAT = FLASH_FSTAT_ACCERR_MASK | FLASH_FSTAT_FPVIOL_MASK | FLASH_FSTAT_RDCOLERR_MASK;
/* load FCCOB registers */
while(index--)
*ptrFccobReg++ = *ptrCommandObj++;
/* launch a command */
FLASH_FSTAT |= FLASH_FSTAT_CCIF_MASK;
/* waiting for the finishing of the command */
while(!(FLASH_FSTAT & FLASH_FSTAT_CCIF_MASK)){};
/* Check error bits */
/* Get flash status register value */
return (FLASH_FSTAT & (FLASH_FSTAT_ACCERR_MASK | FLASH_FSTAT_FPVIOL_MASK | FLASH_FSTAT_MGSTAT0_MASK));
}
Thank you for your help!
Hi
Two options:
1. You can use the FLASH_ProgramSectionByPhrases() fuction to program the Flash which is provided by AN2295 demo code too.
2. I'd also like to suggest that you can use use the C90TFS flash driver which include a quite of flash functions, and you can use these functions directly.
C90TFS flash driver:cache.freescale.com/files/32bit/software/C90TFS_FLASH_DRIVER.exe?fromsite=zh-Hans
Hope it helps.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------