Problems using internal flash in MK22F

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

Problems using internal flash in MK22F

Jump to solution
516 Views
olavbirkeland
Contributor III

Hi

I do not get the "pflash_frdmk22f" example code from SDK 2.1 to work.

The code fails in main() after calling (line 180) :

result = FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);

result is set to 103 meaning:

"Command is not available under current mode/security."

However I cant understand why. The flash is not in secure mode and no flash blocks are protected. I am running on my own HW and had to modify the "BOARD_BootClockRUN()"  function to clock the MCU from internal instead of external clock source, other than that the code example is unchanged.

Any suggestions to what can be wrong?

0 Kudos
1 Solution
387 Views
olavbirkeland
Contributor III

I finally found the reason to the problem.

In the reference manual for K22F chapter 3.5.1.5 "Flash Program Restrictions" it is stated that the flash should not be programmed while operating in High Speed Run or VLPR power modes. As I explained in my question I changed the clock driving source (and run mode) and was running in High Speed Run mode. 

Everything worked after changing to RUN mode

View solution in original post

0 Kudos
1 Reply
388 Views
olavbirkeland
Contributor III

I finally found the reason to the problem.

In the reference manual for K22F chapter 3.5.1.5 "Flash Program Restrictions" it is stated that the flash should not be programmed while operating in High Speed Run or VLPR power modes. As I explained in my question I changed the clock driving source (and run mode) and was running in High Speed Run mode. 

Everything worked after changing to RUN mode

0 Kudos