MGSTAT0 occasionally set on flash erase

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

MGSTAT0 occasionally set on flash erase

871 Views
petersteinberg
Contributor I

I'm using a K20 (MK20DX128VLK7) processor.

Occasionally when I try to erase a block of the program flash I get an FTFL_FSTAT result with the MGSTAT0 bit set.

The block of flash still seems to have been erased properly.

It's very simple code:

FTFL_FCCOB0 = 0x09;

FTFL_FCCOB1 = (addr >> 16) & 0xff;

FTFL_FCCOB1 = (addr >> 8) & 0xff;

FTFL_FCCOB1 = (addr) & 0xff;

FTFL_FSTAT |= FTFL_FSTAT_CCIF_MASK;

while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK)) ;

Any ideas on how to avoid this error or detect what is causing it?

Thanks,

  Peter Steinberg

Labels (1)
0 Kudos
3 Replies

625 Views
johnreid
Contributor I

Was looking at MGSTAT0 as well and found it referenced in an errata for KINETIS: http://cache.freescale.com/files/microcontrollers/doc/errata/KINETIS_2N03G.pdf

This could be your issue.

0 Kudos

625 Views
petersteinberg
Contributor I

Disabling interrupts around the flash writes had no effect.

0 Kudos

625 Views
CCandido
Contributor V

Hi, test it,

                   __DI();

                       i =    flash_erase_sector( 0x10000 );

                       __EI();

//--------------------------------------------------------------------

unsigned int flash_erase_sector(unsigned int destination) // Sector = 4k

{

unsigned int returnCode=0;  

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

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

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

      FTFL_FCCOB0 = 0x09;

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

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

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

     FTFL_FSTAT = 0x80;     // launch command

     if(FTFL_FSTAT&0x30){

         return(0xff);

     }

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

     returnCode = FTFL_FSTAT&0b01110001;

         return(returnCode);

}

//---------------------------------------------------------------------

0 Kudos