AnsweredAssumed Answered

FTFE Flash sector command always return ACCERR

Question asked by Jacky Lau on Mar 10, 2016
Latest reply on Mar 14, 2016 by jeremyzhou


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!

Outcomes