I’m writing a bootloader for a Kinetis KL15Z128VFM4 to load a program through a UART. The problem that I have is that I get a Hard Fault error in the middle of the process.
Previously to that I have made the same process in a Kinetis K10 project without problems.
The process that a try to do is the next:
- Start condition: The only code I have in KL15 flash is the bootloader program.
- When start the KL15 the bootloader copy the needed functions to RAM.
- Disable all interrupts.
- Jump to main bootloader function to start the process (located in RAM).
- Start a PC program that sends the commands and data to load the new code in the KL15 flash with the next sequence:
- Erase the flash above bootloader area (that allows that if the power supply fails the bootloader start again).
- Send the code to fill the erased flash area.
- Erase the initial flash area occupied by the bootloader
- Send the code to fill the initial flash area.
- Make a KL15 reset to start the new program.
When I try to do this process I get a jump to Hard Fault interrupt (interrupt number 3 located at address 0x0000000C of vectortable). This interrupt occurs at the step 5.c : after deleting the flash sector number 2, when the PC program sends a new command interruption occurs.
I can see the problem because I run the program through the debugger.
If I run the program step by step (F5, F6 KDS debug) I can not get the problem appears.
I have checked all the program and once started the bootloader in RAM I no longer call any routine in flash.
Serial communications I make by pooling because I cannot use any interrupt.
In my old project running on a K10 have no problem using the same method.
Any suggestions to solve the problem? (It seems a particular problem of KL15)
Thanks in advance,