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:
Enjoy Flash Programming!
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