Hello Jingjing,
I have using the post that you indicate to try to find the offending position in the code.
The hard fault interrupt is not caused by the flash sector erasing code.
In fact, erase routine finishes without error. I can even send new commands from the PC to erase other sectors (or the same sector) and KL15 responds correctly.
But if I send other commands from the PC, such as a command to read a flash area, the program crash and enters the hard fault interrupt.
This command to read the contents of the flash does not fail until I have not deleted the critical sector of the flash (sector 2).
I inserted the code for debugging the Hard Fault that appears in the post that you suggested me but the address captured corresponds to a zone with no program code (this area is set to 0xFF). The captured address is not always the same, have appeared the following addresses: 0x200, 0x208 and 0x20C.
For me it makes no sense that the program jumps to an address in the flash in which there are no program code and this only happen after erasing the sector 2 and then sending a command to read a flash sector. At that moment the bootloader program is running only in RAM !!
Do you have any ideas that could help me?
Thank you very much.
Joan