AN2295 bootloader hands on tutorial on FRDM-KL25Z

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AN2295 bootloader hands on tutorial on FRDM-KL25Z

AN2295 bootloader hands on tutorial on FRDM-KL25Z

Status: Text content finished, to be updated with more diagrams/images.

Foreword

First of all. I have to say sorry for my English since I am not a native speaker.

This is my personal experience of using AN2295 on FRDM-KL25Z. I want to share it with anyone who is suffering on it, since the existing release from FSL has not been fully tested on FRDM-KL25Z. (I can figure it out in many ways.)

Components and Documents

The lastest microcontrollers always have some kind of bootloader to download user code to the flash memory. FSL does offer many bootloaders for various mcu families. Among them, AN2295 bootloader is general purpose for most of these families, since it only requires an UART, either hardware or software UART.

To make AN2295 work for a system, the developer must have three components:

  • AN2295 bootloader running on target MCU, such as MKL25Z128VLK4 on FRDM-KL25Z.
  • AN2295 bootloader PC software, such as win_hc08sprg, or my Python script, FcBootloaderProgrammer.py
  • AN2295 aware user application, which has different start address and special treatment for interrupt vector.

UPDATE

Add an2295_programmer_v1.zip for Python source code, you need install PySerial module for Python 2.5.

Please visit following URLs to download necessary files:

http://www.freescale.com/files/microcontrollers/doc/app_note/AN2295.pdf

http://cache.freescale.com/files/32bit/doc/app_note/AN4767.pdf

Software for AN2295

AN4767: UART Boot Loader Design on the Kinetis E Series, a more detail application note for AN2295 on E series.

Updates for AN2295 on IAR 6.5

The released AN2295 has to be updated before downloading into FRDM. When you open the AN2295_Kinetis project in IAREW, please update the following setup items in IDE.

  1. In workspace window, switch to Kinetis L Debug configuration.
  2. Right click on AN2295_Kinetis and open Options.
  3. Click on Debugger category. In Setup tab, select PE micro in driver, disable Run to options. (The release leaves it as simulator, and run to __main, which makes warning report when you downloading code to debugger)
  4. In Download tab, enable Verify download, Use flash loader, Override default .board file, with $TOOLKIT_DIR$\config\flashloader\Freescale\FlashKLxx128K.board . Disable Attach to program.
  5. In PE micro, select interface type as OpenSDA - USB
  6. In Tools|Options (IDE Options)|stack, you can leave Stack points not valid until program reaches as blank (Optional).
  7. In AN2295_LinkerFile.icf, change IntVectTable_end__ from 0x0000003f to 0x000003FF (Optional).
  8. In bootloader_cfg.h, enable AN2295_FRDM_KL25Z_cfg.h, comment out AN2295_TWR_KL25Z_cfg
  9. In AN2295_FRDM_KL25Z_cfg.h, #define BOOT_UART_BAUD_RATE 57600
  10. Add gpio.h/gpio.c to project, in case you want use them to indicate something.

We can conclude a fact that AN2295 is good enough as a bootloader as it has been tested on many MCU families. The source code is open, so you can custom it for your own specific purposes. However, you have to do it yourself.

The reason why I change baudrate is I found VCP of OpenSDA will decode 0x00 send from KL25Z as 0x80. So I slow down to 57600.

Updates for PC software of AN2295

Unfortunately, The released (10.0.12.0) and updated (10.0.16.0) versions of bootloader PC software don't work with my bootloader. The released PC software of AN2295 is open source as well. However I am not fan for VC++. I prefer to make my own programmer software with Python, as knows as a clue language.

The programmer software is released in Windows exe format and works in command line prompt. The user don't bother to install Python/PySerial and other components.

The programmer software works in a simple single shot mode, blank/erase/program actions.

D:\an2295_programmer>FcBootloaderProgrammer --help

##################################################

FC Booloader Programmer v0.1-alpha
- An alternative to Freescale AN2295 on FRDM-KL25Z

  by Allan K Liu (C)2013 Ennovation LLC

##################################################

Usage:
-h, --help      :       This help information
-p, --port      :       Serial port setting in Windows, like COMxx, depends on your VCP installation
-b, --baudrate  :       Baud rate setup from 9600/19200/38400/57600/152000
-f, --file      :       Hex file (Motorola SREC or Intel HEX)
-a, --action    :       Action [blank/erase/program]
-d, --debug     :       Debug [0:1]    

In order to make it simpler, I prepare some DOS batch files.

blank.bat
FcBootloaderProgrammer --port=COM14 --baudrate=57600 --debug=1 --action=blank
erase.bat
FcBootloaderProgrammer --port=COM14 --baudrate=57600 --debug=1 --action=erase
program.bat
FcBootloaderProgrammer --port=COM14 --baudrate=57600 --debug=1 --action=program --file=DemoApp_4_FC_Bootloader_freedom.srec

You can disable debug output optionally.

Updates for Demo projects for AN2295 on IAR6.5

In order to run a user application with AN2295 bootloader, you have to rebuild it with modified linker script.

You can generate a new app based upon Kinetis L Sample Codeby following steps.

  1. Run make_new_project.exe under Kinetis L Sample Code\kl25_sc_rev5\klxx-sc-baremetal\build\iar\
  2. Offer a new project name "DemoApp_4_FC_Bootloader_freedom" according to prompt.
  3. Open it in IAR IDE.
  4. Change project linker options, enable Override default with $PROJ_DIR$\..\config files\Pflash_32KB_AN2295.icf, the modified linker file.

The major changes are:

define symbol __ICFEDIT_region_ROM_start__ = 0x00001000;
define symbol __ICFEDIT_region_ROM_end__   = 32*1024;
define exported symbol __VECTOR_TABLE      = 0x00001000;
define symbol __code_start__ = 0x00001410;

After building the project, we can get similiar srec file, which has start address at 0x1000.

S027000044656D6F4170705F345F46435F426F6F746C6F616465725F66726565646F6D2E7372656331
S1131000F80B0020111400002929000029290000F0
S11310102929000029290000292900002929000084
......
S1132B200A0D4B4C300000000A0D4B4C31000000E4
S1132B300A0D4B4C320000000A0D4B4C33000000D0
S10B2B400A0D4B4C34000000A7
S9032B0DC4

According to SREC file format, its filename: DemoApp_4_FC_Bootloader_freedom.srec. And it ranges from 0x1000 to 0x1B47

Finally, run "erase.bat", then "blank.bat", then "program.bat"

Simple!

Other Useful Tools

During my development for AN2295, I used some other tools, especially PC terminal to monitor events/traffics on RS232/UART.

Future Development

Here are my plan.

  • More images for step on step.
  • Smart detection for OpenSDA VCP port.
  • Mutli-thread GUI for bootloader tool.
  • More labs to reduce unnecessary empty flash space on VECTOR_TABLE and flash_protection_table in user application.
  • Support cryptographic/authentication in bootloader to support licenses.
Attachments
Comments

I have no idea why ICF and SREC files are in zip format. Anyway, I have verified the integrity of attached files.

Known Limitation:

FcBootloaderProgrammer only works on linear and complete memory SREC file. I am working on it. By now, you can manually fill up memory holes/gaps between memories blocks.

For example:

S1131190000000000000000000000000000000004B
S11311A0FFFFFFFFFFFFFFFF0A0000000100000038
S113141000B51149002003E000220A71401C10317C
S11314200A28F9D300BD10B5010000240A4800229F

It has a memory gap between 0x11B0 and 0x140F, takes up about 6 flash blocks:

  • 0x1180~0x11FF (to be updated)
  • 0x1200~0x127F (leave it as is)
  • 0x1280~0x12FF (leave it as is)
  • 0x1300~0x137F (leave it as is)
  • 0x1380~0x13FF (leave it as is)
  • 0x1400~0x147F (to be updated)

Just an alert.


Update

By using above skill, I have downloaded my ADB board via AN2295 bootloader. And it works. I know manually fill up is a bad approach. Keep tune for the next release for FcBootloaderProgrammer.

Hi.

Excuse me please for my ignorance (and for my english too), but I think that in the ICF file modifications specifically at the line:

define symbol __ICFEDIT_region_ROM_end__   = 32*1024; 

you must write:

define symbol __ICFEDIT_region_ROM_end__   = 128*1024; 

if you're using a MKL25Z128VLK4 MCU, because it has a 128Kb flash.

Correct me if I'm wrong please.

Best regards!

100% helpful (1/1)
Version history
Last update:
‎09-10-2020 03:38 AM
Updated by: