May 16, 2013

OpenOCD with TWRK60 - Kinetis K60 board (tutorial for Windows)

This post will be about openOCD and OSBDM on TWRK60. I'll cover here only in windows system, linux might come later.

To start, download precompiled binaries (everything should be enabled, check a text file inside. What I am interested at the moment are two flags there --enable-osbdm). Or if you prefer to compile it with own flags, please visit official openOCD website.
Download windows precompiled openOCD binaries [freddiechopin.info/en]

Read libusb-1.0 drivers text file, there's link to ZADIG. libusb must be installed if you want to use J-Link or OSBDM. Having said that, I was not able to make it work with libusb filtered version. I received error during initialization: Can't open OSBDM. Therefore I simply replaced libusb (default) driver by WinUSB. This is the problem I have to solve. I simply don't want to replace driver between using CodeWarrior or OpenOCD.
Zadig [sourceforge.net/projects/libwdi]


Create own .cfg file (in my case openocd.cfg) which contains the following text:
source [find ../scripts/interface/osbdm.cfg]
source [find ../scripts/board/twr-k60n512.cfg]
$_TARGETNAME configure -event gdb-attach {
   echo "Halting target"
   halt
}

Open the command line and type:
openocd-0.7.0.exe -f openocd.cfg

The output from the console:
Open On-Chip Debugger 0.7.0 (2013-05-05-10:41)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
cortex_m3 reset_config sysresetreq
Info : add flash_bank kinetis pflash.0
Info : add flash_bank kinetis pflash.1
Info : OSBDM has opened
Info : This adapter doesn't support configurable speed
Info : JTAG tap: k60.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00,
 ver: 0x4)
START...
Info : k60.cpu: hardware has 6 breakpoints, 4 watchpoints
END...

Keep the command line open which keeps the connection alive, open terminal (like Putty), create a new instance (telnet) with an address: localhost on port  4444. This should be the output on the terminal:
Open On-Chip Debugger


To flash our own image, halt the CPU.
>reset halt
JTAG tap: k60.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00009640 msp: 0x2000fbfc

Ready to flash the S19 image - LED demo (as an example).
> flash write_image erase c:/TWRK60_DEMO.afx.S19
auto erase enabled
Probing flash info for bank 0
Probing flash info for bank 1
no flash bank found for address 1fff0000
wrote 0 bytes from file c:/TWRK60_DEMO.afx.S19 in 0.064003s (0.000 KiB/s)

I am currently having problems to reset the CPU. What is not working currently, it's run command. But if I invoke reset init and resume, it works.

There are many commands which are described in OpenOCD User’s Guide. I'll continue with J-Link and GDB.

Update June 8th:
I posted how to communicate with the tower board and jlink in the eclipse and I published trivial gpio gcc example for TWRK60N512. See my other posts.

References:
Official openOCD site http://openocd.sourceforge.net/