K22 FTFA Erase Sector command failing with ACCERR

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K22 FTFA Erase Sector command failing with ACCERR

790 Views
HummingbirdElec
Contributor I

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);

}

Labels (1)
0 Kudos
Reply
1 Reply

450 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Norman Ballard,

   Did you the interrupt before you do the flash sector earse?

   Before your do flash sector erase, you should disable your interrupt.

  I create a KDS project, and do the sector erase with your code, it works ok on my side.

Before erase, 0X0001A000  have data:0x00-0xff

pastedImage_1.png

After sector erase, the address 0x0001a000 can be erased, the ACCERR is not set:

pastedImage_2.png

You can try my code, and try it on your side, please find my project from the attachment.

Wish it helps you!

Regards,

Jingjing

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. It would be nice!

-----------------------------------------------------------------------------------------------------------------------