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 */
/* 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