Adding support to kinetis microcontroller on OpenOCD

This is the way I got OpenOCD working to program Freedom board (Kinetis KL25) using patches from Nemui San: (どうもありがとうございました!)

$ git clone

Execute the bootstrap:

$ cd openocd
$ sh bootstrap 

If you receive this error message:

bootstrap: Error: libtool is required

Then install libtool:

$ sudo apt-get install libtool

If you receive this error message:

bootstrap: 27: bootstrap: aclocal: not found

Then install automake:

$ sudo apt-get install automake

Apply the patches to openocd:

$ patch -p1 < ../nemui/openocd_20130412_nemui.patch
$ patch -p1 < ../nemui/kinetis_kl.patch

Run configure passing this parameters:

$ ./configure --enable-internal-jimtcl --enable-maintainer-mode --disable-werror --disable-shared --enable-stlink --enable-jlink --enable-rlink --enable-vslink --enable-ti-icdi --enable-remote-bitbang --enable-usb-blaster --enable-presto --enable-osbdm

If you receive this error message:

checking for usb.h... no
configure: error: libusb or libusb-1.0 are required to build some OpenOCD driver(s)

Then install libusb and libusb-1.0 (yes, both! Not one OR other as suggested above) :

$ sudo apt-get install libusb-dev
$ sudo apt-get install libusb-1.0-0-dev

Compile it:

$ make

If you receive this error message:

/comum/workspace/kinetis/openocd/openocd/missing: linha 52: makeinfo: comando não encontrado
WARNING: `makeinfo' is missing on your system.  You should only need it if
         you modified a `.texi' or `.texinfo' file, or any other file
         indirectly affecting the aspect of the manual.  The spurious
         call might also be the consequence of using a buggy `make' (AIX,
         DU, IRIX).  You might want to install the `Texinfo' package or
         the `GNU make' package.  Grab either from any GNU archive site.
make[2]: ** [] Erro 1

The install texinfo:

$ sudo apt-get install texinfo

Now finally install OpenOCD:

$ sudo make install

I used STM32F4Discovery (stlink-v2) as SWD programmer, this is the command line I used:

# openocd -f interface/stlink-v2.cfg -f target/kl25z_hla_flash.cfg -c "mt_flash nuttx.elf"
Open On-Chip Debugger 0.8.0-dev-00011-g70a2ffa-dirty (2013-05-22-15:19)
Licensed under GNU GPL v2
For bug reports, read
none separate
Info : add flash_bank kinetis pflash
Info : This adapter doesn't support configurable speed
Info : STLINK v2 JTAG v17 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : Target voltage: 2.904142
Info : kl25z.cpu: hardware has 2 breakpoints, 2 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x61000000 pc: 0x00000410 msp: 0x1ffffa14
Rize up to Internal PLLed Clock!
auto erase enabled
Info : Probing flash info for bank 0
Info : Padding image section 0 with 832 bytes
Warn : flash configuration field erased, please reset the device
Warn : Kinetis L Series supports Program Longword execution only.
wrote 31744 bytes from file nuttx.elf in 223.414917s (0.139 KiB/s)
verified 30798 bytes in 0.676004s (44.491 KiB/s)
shutdown command invoked

I need to investigate why it is too slow, last time I tested OpenOCD it was more than 15x faster.

You need to download the patches files reference above from this link:

Note: I soldered also the 3V pin from STM32F4Discovery on pin 1 of Freedom board. To use it I need to remove the mini-USB cable from STM32F4Discovery and from Freedom board, then I connected the mini-USB to Freedom board and then connect the mini-USB of STM32F4Discovery and finally remove the mini-USB from Freedom board. After that I can run the above command.

2 thoughts on “Adding support to kinetis microcontroller on OpenOCD

  1. Can OpenOCD be used to program the KL25 with an arbitrary OpenOCD compatible dongle based on the FT-2232?

    I have several old dongles and I’d like to use them to program up KL25Z boards I have without having to repurpose a FRDM-KL25Z board.

    Any pointers would be helpful. thanks.

  2. Hi David,
    Good question, but I don’t have a definitive answer to you.

    Mr. Spencer Oliver is working on it and there are patches on gerrit to support it, but I didn’t have the chance to test it yet. I just used OpenOCD when I was doing board bring-up to port NuttX to Freedom KL25 board. Now all my programming and debugging are happening using NuttX infrastructure. It is similar what happens when you are porting Linux for a high end processor.

    I’ll test it soon and will post my results here.
    []’s Alan

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s