AnsweredAssumed Answered

K22 FTFA Erase Sector command failing with ACCERR

Question asked by NORMAN BALLARD on Jun 28, 2015
Latest reply on Jun 29, 2015 by Kerry Zhou

Hi Everyone,

 

I have been using a set of flash functions (mainly Erase block and program longword) on Kinetis K and L series with Codewarrior 10.5 for a while now. However I have recently moved to Kinetis Design Studio 3.0.0 with the MK22FN128VLH10. I've been having problems with getting the Erase Sector command (0x09) working.

 

I am trying to erase the memory sector starting at 0x1A000. It fails with the ACCERR bit being set. I have not changed any other security settings.

 

This function has always worked on other Kinetis micros, so why is it failing now? Is there something different about the K22? I've checked all of the security settings I can find to no avail (flash memory should be set to 'unprotected' out of the box anyway, shouldn't it?).

 

This is my code. Destination is set to 0x1A000.

 

unsigned int flash_erase_sector(unsigned int destination)

{

         unsigned int returnCode;      /* return code variable */

 

         if(FTFA_FSTAT&0b01000000){FTFA_FSTAT&=0b01000000;}

         if(FTFA_FSTAT&0b00100000){FTFA_FSTAT&=0b00100000;}

         if(FTFA_FSTAT&0b00010000){FTFA_FSTAT&=0b00010000;}

 

         /* set the default return code as FTFx_OK */

         returnCode = 0;

 

       FTFA_FCCOB0 = 0x09;

       FTFA_FCCOB1 = (unsigned char)(destination >> 16);

       FTFA_FCCOB2 = (unsigned char)((destination >> 8) & 0xFF);

       FTFA_FCCOB3 = (unsigned char)(destination & 0xFF);

 

       FTFA_FSTAT = 0x80;     // launch command

 

       if(FTFA_FSTAT&0x30){return(0xff);}

       while(!(FTFA_FSTAT&(1<<7))){}

 

       returnCode=FTFA_FSTAT&0b01110001;

 

         return(returnCode);

}

Outcomes