Day: March 22, 2013

How to debug Freedom Board (FRDM-KL25Z) using OpenOCD

This is a step-by-step to let you debug your board using OpenOCD:

First of all you need to install CMSIS-DAP firmware:
https://acassis.wordpress.com/2013/03/17/changing-frdm-kl25z-boards-firmware-to-become-cmsis-dap-compatible/

You need to install libusb version 1.0:

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

Download and compile OpenOCD with CMSIS-DAP support:

$ git clone https://github.com/TheShed/OpenOCD-CMSIS-DAP.git
$ cd OpenOCD-CMSIS-DAP
$ git checkout -b cmsis origin/cmsis-dap
$ ./bootstrap
$ ./configure --enable-maintainer-mode --enable-cmsis-dap
$ make
$ sudo make install

Time to run OpenOCD:

# openocd -c "interface cmsis-dap" -f tcl/target/kl25.cfg
Open On-Chip Debugger 0.7.0-dev-g1d8f0c1 (2013-03-18-19:24)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'cmsis-dap'
Info : CMSIS-ADI: cmsis_dap_select
Info : CMSIS-DAP: cmsis_dap_swd_init
Info : kernel driver active
Info : kernel driver now detached.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
cortex_m3 reset_config sysresetreq
adapter speed: 50 kHz
Info : CMSIS-DAP: cmsis_dap_init
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Packet Size  = 64
Info : CMSIS-DAP: Packet Count = 32
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1 
Info : CMSIS-DAP: cmsis_dap_reset_link
Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0)
Info : DAP Read IDCODE
Info : CMSIS-DAP: Interface ready
Info : clock speed 50 kHz
Info : CMSIS-ADI: cmsis_dap_init
Info : CMSIS-ADI: cmsis_dap_queue_idcode_read
Info : CMSIS-ADI: cmsis_dap_queue_dp_read 00
Info :                              0bc11477
Info : IDCODE 0x0bc11477
Info : CMSIS-ADI: cmsis_dap_queue_ap_abort
START...
Info : CMSIS-ADI: cmsis_dap_queue_dp_read 04
Info :                              00000040
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 04 00000020
Info : CMSIS-ADI: cmsis_dap_queue_dp_read 04
Info :                              00000040
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 04 50000000
Info : CMSIS-ADI: cmsis_dap_queue_dp_read 04
Info :                              f0000040
Info : CMSIS-ADI: cmsis_dap_run
Info : CMSIS-ADI: cmsis_dap_queue_dp_read 04
Info :                              f0000040
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 08 00000000
Info : CMSIS-ADI: cmsis_dap_queue_ap_read 00
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 08 00000000
Info :                              03000040
Info : CMSIS-ADI: cmsis_dap_queue_ap_read 04
Info :                              ddfdffff
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 08 000000f0
Info : CMSIS-ADI: cmsis_dap_queue_ap_read f4
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 08 000000f0
Info :                              00000000
Info : CMSIS-ADI: cmsis_dap_queue_ap_read f8
Info :                              f0002003
Info : CMSIS-ADI: cmsis_dap_queue_ap_read fc
Info :                              04770031
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 08 00000000
Info : CMSIS-ADI: cmsis_dap_queue_ap_write 00 a2000012
Info : CMSIS-ADI: cmsis_dap_queue_dp_write 08 00000000
Info : CMSIS-ADI: cmsis_dap_queue_ap_write 04 e000ed00
Info : CMSIS-ADI: cmsis_dap_queue_ap_read_block 01
Info : CMSIS-ADI: cmsis_dap_run
Info : CMSIS-ADI: cmsis_dap_queue_ap_write 04 e0002000
Info : CMSIS-ADI: cmsis_dap_queue_ap_read_block 01
Info : CMSIS-ADI: cmsis_dap_run
Info : CMSIS-ADI: cmsis_dap_queue_ap_write 04 e0001000
Info : CMSIS-ADI: cmsis_dap_queue_ap_read_block 01
Info : CMSIS-ADI: cmsis_dap_run
Info : kl25.cpu: hardware has 2 breakpoints, 2 watchpoints
END...

Now you can debug the FRDM board with openocd normally and even integrated on Eclipse.

That’s all folks, good luck!

UPDATE: After some more tests I noticed the debugging using GDB is not completely functional, then the best approach will be connecting to OpenOCD over telnet at port 4444 and execute the commands to access registers and memory.