AnsweredAssumed Answered

Flash Protection Violation Flag(FPVIOL) set while clearing CCIF bit

Question asked by Jed Swanton on Aug 2, 2016
Latest reply on Aug 3, 2016 by Jed Swanton

When trying to erase a sector in flash by using "NV_FlashEraseSector", the error "gNV_ERR_PVIOL_c" is returned.  After some digging I found that the error is coming from the following snippet:


static uint32_t NvFlashCommandSequence
        pNvConfig_t pConfig,
        uint8_t index,
        uint8_t* pCommandArray
/* clear CCIF bit */
    gNV_REG_WRITE(pConfig->ftfxRegBase + gNV_FSTAT_OFFSET_c, gNV_FSTAT_CCIF_c);      <----  Issue occurs here
//* checking protection error */
    else if(0 != (registerValue & gNV_FSTAT_FPVIOL_c))
        /* return an error code gNV_ERR_PVIOL_c */
        returnCode = gNV_ERR_PVIOL_c;                                     <----  Error "found" and returned here


The code above is a snipet of a method from C90TFS that was provided to me by Freescale. 


The issue that I am running into is that the FPVIOL flag is flipped while writing to this location. The address written to is correct for setting the CCIF bit.  And the value of gNV_FSTAT_CCIF_c is a correct mask to test the bit needed ( The relevant values can be found below)

#define gNV_FSTAT_CCIF_c                 0x80
#define gNV_FSTAT_OFFSET_c               0x00000000
#define gNV_FTFX_REG_BASE_c              0x40020000             <---- pconfig->ftfxRegBase is set to this.


The value of FTFL_FSTAT (0x40020000) goes from 0x0680 to 0x0690 in the issue line.  Why does FPVIOL get flagged during this step of the flash command sequence?


I am using a Freescale K21 MCU (Model: MKW21D512VHA5) and IAR Embedded Workbench.  I am new to both of these so the solution could be very simple.  Thanks!