I wonder if you might be able to help me with a problem I am having here using the KL28..
Basically, I am using a function to erase a sector of flash on the KL28, the function is running from RAM (and code is generated using GCC compiler)..
If I run the function as shown below without a “nop” instruction at the end of the function I get a ‘hard-fault’ generated.. I can’t figure out why the ‘nop’ instruction would have any effect..
I have compared the disassembly with and without the ‘nop’ and its pretty much the same…
Here's the function..

here's is the disassembly comparison of the code generated when i insert the 'NOP' versus the when the 'NOP' is removed, they are practically the same except for whats shown in the snippet below..

I wonder is there a delay required after issuing the flash cache instruction before returning from the function..
Any help would be much appreciated.. I am pulling our hair out here.. :-)
regards
Trevor