Derek Snell

Using IAR EWARM to program flash configuration field

Discussion created by Derek Snell Employee on Aug 30, 2013
Latest reply on Nov 24, 2015 by Scott Whitney

There are non-volatile registers in the Kinetis family flash that store the default protection and security settings of the MCU.  These include the registers FSEC, FOPT, FEPROT, and FDPROT at addresses 0x40C - 0x40F.  IAR, like many toolchains, has added protection against programming these locations accidentally, mainly because some values for FSEC can permanently secure the flash, and prevent any future changes to the flash.  The default value IAR programs in these locations is 0xFEFFFFFF, which leaves the MCU unsecured and flash sectors unprotected.  If you desire your application to program these registers to a non-default value, it's not enough to have these values in the application.  By default, IAR will ignore these values in your application, and program the flash with the default setting.  Your project must specify you want to program these locations as well, and that is done using the parameter --enable_config_write in the .board file used by the flash programmer.  Here are the steps for enabling this parameter in IAR:

 

In the project options, go to the Download Tab in the Debugger category.  Check the box "Override default .board file"  Then click the Edit button

Download_Tab.jpg

 

Select the memory range for the program flash, starting at address 0x0.  Click the Edit button

Flash_Loader.jpg

 

In the Extra Parameters field, add --enable_config_write.  Click OK.

Flash_Configuration.jpg

 

The Flash Loader settings are updated with the extra parameter.  Click OK.

New_flash_loader.jpg

 

IAR will ask you to save these settings as a new .board file.  After saving the file, the .board file is updated with your modified file.  Click OK to save the project settings.   

 

New_board_file.jpg

 

Now you can program the flash and change the values in the flash configuration field at addresses 0x40C - 0x40F.

 

BE SURE your FSEC register at 0x40C is set to the proper value that you want.  A wrong value here can permanently secure the flash, and your board will become a nice paperweight!

 

As a reference, here is the modified FlashK60Fxxx128K_enable_config_write.board file from this example:

 

<?xml version="1.0" encoding="iso-8859-1"?>


<flash_board>
  <pass>
    <loader>$TOOLKIT_DIR$\config\flashloader\Freescale\FlashK60Fxxx128K.flash</loader>
    <range>CODE 0x0 0xfffffff</range>
    <args>--enable_config_write</args>
  </pass>
  <pass>
    <loader>$TOOLKIT_DIR$\config\flashloader\Freescale\DFlashK60Fxxx128K.flash</loader>
    <range>CODE 0x10000000 0x13ffffff</range>
    <abs_offset>0x800000</abs_offset>
  </pass>
</flash_board>

Outcomes