I am using a MK10DX128 on a custom board, I have copied the flash code from AN2295. My compiler is GCC 4.7.2 . I am attempting to write a SD card bootloader.
I noticed that the flash erasing routine would reset my chip. After some troubleshooting, it was determined that disabling interrupts during this time would solve the problem.
I also noticed that sometimes the function in RAM would cause a hard fault for certain instructions, I rewrote the entire flash driver myself and stopped putting the function in RAM, this solved the hard fault problem and the bootloader still works.
I just wanted to share these two facts, perhaps the code provided with the application note can be improved with these changes so that future users can utilize the code easily.