AnsweredAssumed Answered

Setting up Kinetis bootloader on MK22FN128 unsuccessful.

Question asked by Arjun Nair on Aug 9, 2017
Latest reply on Aug 11, 2017 by Arjun Nair

Setting up Kinetis bootloader on MK22FN128 unsuccessful.

 

I am a bit stuck with the bootloader. Any help is appreciated.

 

I have a custom PCB with a MK22FN128VLH10 microcontroller. The significant peripherals are :
1) 20-pin J-Tag connector for connecting the SEGGER J-Link debugger.
2) USB micro-B port connected to the microcontroller.
3) Few pins connected to a header (for I/O).
4) Few LEDs as indicators.

 

Stuff that is already working :
I have written a program to blink LEDs, read Analog Input and send data through the USB as a virtual com port. This program was flashed to the board using the SEGGER J-Link debugger and tested. It works exactly as intended.

 

The problem :
I want to use USB to flash the program. But the bootloader isn't working for some reason.

 

What I have tried :
- Downloaded Kinetis Bootloader v2 from NXP website.
- Imported the project 'flashloader' into KDS (Kinetis Design Studio).
- Built the project (in 'release' configuration) and created 'flashloader.elf'.
- Used the python scripts provided and generated 'flashloader_image.c'.
- Imported the project 'flashloader_loader' into KDS.
- Added the file 'flashloader_image.c' to the 'flashloader_loader' project and fixed the #include to point to the right file.
- Built the project (release) and flashed the microcontroller using the J-Link debugger.

 

So far, everything looks fine. I connected the USB to my computer and executed the following command with blhost -

$./blhost -u -- get-property 1

It's a success. I get the expected response from the microcontroller.

 

Next, I execute the following commands to flash the microcontroller through the bootloader -

$./blhost -u -- flash-erase-all

$./blhost -u -- write-memory 0xA000 AppICreated.bin
$./blhost -u -- reset

All three commands run successfully.

 

And that's it. Nothing else happens. I reset the controller, turned off power and turned it on, waited for a few minutes. My program doesn't execute. Also, the bootloader doesn't work anymore.

 

I tried the same thing with Kinetis FlashTools (in a Windows system) at location 0xA000 and it gives the same result. But, the bootloader continues to works in this case.

 

I also tried writing to location 0x0. The program starts working, but I'm pretty sure the bootloader is overwritten and lost. I used the code in "Kinetis Bootloader v2.0.0 Reference manual" page 19 to call the bootloader within my code when I send a character through the virtual com, but the controller just stops working till I reset it.

 

Please let me know if you need to know more. I spent a lot of time and tried a lot of useless hacks to try to fix it.

 

If anybody knows what I did wrong, I would love to know. Thank you.

Outcomes