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

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

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

Jump to solution
881 Views
jeds
Contributor I

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!

Labels (1)
0 Kudos
1 Solution
710 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Jed,

The incorrect launch command sequence and erase execution in protected area will cause the kind of issue.

Regarding to the launch command sequence, you can refer to the figure below and relocate the launch command sequence in the RAM instead of the Flash.In addition, you should check what the value of the program flash protection registers (FTFL_FPROTn) are.

Hope it helps.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
3 Replies
710 Views
mjbcswitzerland
Specialist V

Hi

Is this comment incorrect in the code?

/* clear CCIF bit */

If this is the command execution it is setting the bit and not clearing it - the code will be running from SRAM (unless acting on a different Flash plane) and interrupts will be disabled.

Errors will be due to incorrect setup of the command - eg. not initially setting valid parameters before issuing the flashing command - or trying to delete a sector that is protected.

Regards

Mark

Kinetis for professionals: http://www.utasker.com/

0 Kudos
711 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Jed,

The incorrect launch command sequence and erase execution in protected area will cause the kind of issue.

Regarding to the launch command sequence, you can refer to the figure below and relocate the launch command sequence in the RAM instead of the Flash.In addition, you should check what the value of the program flash protection registers (FTFL_FPROTn) are.

Hope it helps.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
710 Views
jeds
Contributor I

After checking the FTFL_FPROTn registers I was able to determine that the issue was from an earlier part of my code instead of the problem line I had outlined above.  I was trying to set the flash protection to "gNV_FLASH_NOT_SECURE_c", and this was not unsecuring the flash but rather causing issues with it overall.  Thank you for the speedy response!

0 Kudos