Hello Mark, David and Chris,
I thank you all for your great help, explanations and interesting ideas.
I was not very clear on what I want to achieve and what I have already tested.
My Bootloader does not have much space for variations. It must be very small (<3k), UART with a Baudrate of 115200 and as fast as possible.
The size is of most importance especially for the smallest of the KL02 series with just 8k Flash memory and most Freescale Bootloaders are just too big for that.
The idea is that a bigger main MCU is connected to the small KL02 MCUs using Rx/Tx PIN UART and programms them with a new application code if an update is needed. The two MCUs are only connected with RX and Tx.
We are still not sure which kind of data package we are going to use. At the moment I am using .s19 Files thanks to Code Warrior "Create Flash Image" option.
The protocol looks more or less like this:
Main MCU send change flash command -> KL02 write fixed byte a special value -> software reset -> enter Bootloader mode -> programm flash -> erase fixed byte -> software reset -> enter normal application code (normal run mode).
I am using the PC with various Terminal programms to simulate the main MCU.
Like Mark has mentioned, XON/XOFF is out of the question, but FLow Control with RTS/CTS could be emulated using a defined protocol. I am already sending an acknoledge byte to the Main MCU after every successful flashed line.
@Chris: Your fear of writing after each line of the S-Record transfer is like Mark has mentioned of no concern. The flash process stops if the CRC detects a faulty line. Than you can e.g. erase the total flash and reset the MCU to enter the Bootloader again. Or you could ask for the same line again (e.g. 3 times) and then stop the process as mentioned.
@Mark: Thank you very much. I am going to need some time to analyse all the information I have received from you, but I am sure I will find something useful. Thx.
I am very interested in the binary data content and the KBOOT decoding methode. What kind of files are they (.elf, ...)? How can I generate them for testing?
Solution:
I have solved my problem of the Read Collison Errors while writing the flash when an Rx Interrupt is triggert due to a continious sending of the .s19 data of the terminal programs.
At the beginning I thought I need to place the complete vector table into the Ram memory, but it turns out that you only need to place the functions you are using into the Ram memory which are
connected with the receiving process during the time a Read Collision Error would be triggert.
For relocating a function I followed the "Relocating Code and Data Using the CW GCC Linker File(.ld) for Kinetis", created my own Ram memory space and copied the functions using the
""void __attribute__((section(".myCodeInRAM"))) UART0_IRQHandler (void)"" command. As you can see it is very important that you copy the UART handler function.
We have analysed the writing process and triggering of the Rx-Interrupts using a scope and and can see now that both processes can work simultanious.
The flash process of a 44.618 Bytes .s19 File (44.618byte * 1/115200(1/s) * 10bits = 3.87s message transfere) now only takes 4 seconds of total flash time and it works every time.
It is now working even better than before when I wrote line by line and had to switch the interrupts of while writing to the flash.
There is just one problem which really really annoys me, but I might just open a new discussion for this.
Why is it possible to write one byte to the flash, but in order to override it you need to delete 1k of flash memory,
while PE can do this and the code next to the memory is not being erased, even though there is clearly an erase command visible
in PE when writing a new value to the flash adress!!!
I hope this helps,
Thanks again for your great support,
Edward.