Using ESFC bit - Flash programming routines in Cotex M0+ kinetis MCU

Document created by ZhangJennie Employee on Mar 4, 2015Last modified by ebiz_ws_prod on Dec 13, 2017
Version 8Show Document
  • View in full screen mode

In most of Freescale MCUs, there is only one Flash on chip.  When executes Flash programming we need copy Flash programming routine from Flash to RAM then execute it from RAM.  The reason is that when writing MCU Flash, program is also reading instruction from same Flash, but Flash can’t perform reading and writing parallel. So executing the flash programming routine from RAM can avoid Flash read/write conflict.


In Cotex M0+ core kinetis, Platform Control Register (MCM_PLACR) is added. The MCM_PLACR register selects the arbitration policy for the crossbar masters and configures the flash memory controller. A useful bit I am going to talk about is bit 16 ESFC: Enable Stalling Flash Controller. When this bit enabled, it can stall flash controller when flash is busy.  Setting ESFC bit can well-balance time sequence of Flash reading and writing – when writing Flash, reading Flash instruction can wait, and vice versa. Using ESFC bit can make our flash programming easier. Thus one Flash can write itself, which is not possible for other one Flash MCU without ESFC bit control.


Currently MCM_PLACR is supported in below chips with Cotex M0+ core embedded:









I didn’t find any official Flash Programming demo code on ESFC bit usage so far. So I made sample code under Codewarrior10.6 and KDS2.0 respectively. The demo codes are for MKL25, but the method is available for all Cotex M0+ MCU I listed above.

It’s easy to port the flash programming code to other Cotex M0+ chip. Here are porting steps for both KDS and CW environment:

  • - Create new project with project wizard with default setting to create a new project
  • - Copy flash_kinetis_m0.c and flash_kinetis_m0.h to project Source code folder
  • - Include the specific MCU header file in  "flash_kinetis_m0.h", for example  #include "MKL25Z4.h"
  • - Include "flash_kinetis_m0.h" to the related source file:  #include "flash_kinetis_m0.h”


Enjoy Flash Programming!

Original Attachment has been moved to:

Original Attachment has been moved to:

1 person found this helpful