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

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

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

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

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:

MKE02/04/06

SKEA

MKL02/04/05/14/15/16/17/24/25/26/27/33/34/36/43/46

MKM13/14/32/33/34/38

MKV10

MKW01

 

 

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!

Labels (1)
Attachments
Comments

Very Good~

The MKE06Z documentation states "ESFC enables the stall mechanism. This bit must be set only just before the flash operation is executed and must be cleared when the operation completes"; this code does not appear to follow that guideline.

Hi IAN,

First thanks for bringing this point to my attention.

when I wrote this article, I refer old MKL25 user manual. this statement "ESFC enables the stall mechanism. This bit must be set only just before the flash operation is executed and must be cleared when the operation completes" is not included there. for my understanding, if the code follows this statement, it definitely better, for example, it can reduce power consumption. but if doesn't follow it. code can work too. how do you think?

anyway, your suggestion is very good, I will update it later. thanks!

Best Regards,

Jennie

100% helpful (1/1)
Version history
Last update:
‎03-04-2015 09:28 PM
Updated by: