Hi fellow community members,
I'm wondering if anybody can give me some advice how to start developing a custom bootloader in flash for the Kinetis MKL27Z256? I'm using this MCU to connect with a BLE module through a UART channel (LPUART0) and would like to leverage this communication channel to a remote host to update the firmware through Bluetooth, i.e. OTA. Once the BLE module initialization is done and the connection is established, we will use our own protocol between remote host and the resident MCU to exchange data and re-program the flash during the firmware update.
I read through many documentation and app notes related to KBOOT but the information are pretty much scattered and I still don't know for sure how to execute this project using Kinetis Design Studio.
Here are what I know (please correct if I'm wrong at any point):
1. I have to set the FTFA_FOPT register so that the MCU will boot from flash, not from ROM. Normally I can do this by editing the file "startup_MKL27Z4.S" in the KDS tool (under Flash Configuration area, set byte address 0x40D to 0x3F)
2. I have to write my custom bootloader, which looks something like this:
a. read some push button, if pressed, continue the firmware update process. If not pressed, go to user application (normal mode)
b. initialize (some I/O pins, clocks, LPUART0 - which is the channel that connects to the BLE module)
c. issue some commands to initialize the BLE module and finally starts advertising.
d. when connected to the host, start the dialog and exchange data (in chunks) to get new firmware image and update the flash in user application area
e. when finished, jump to user application code.
My questions are as follows:
1. How do I integrate my "custom bootloader code" above into the normal "user application code" in KDS?
2. Is the entry point of the bootloader fixed at any location in flash area ? Or user programmable ?
3. Is there a need to call bootloader routine in user application (similar to ROM bootloader call provided in some example) ? Or MCU jumps to bootloader automatically upon boot (with FTFA_FOPT=0x3F)?
4. How do I set up the starting address of the user application code in KDS?
Your help would be greatly appreciated.