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.
Nice blog, after a bit of tinkering I got it to work.
I had to do the ./bootstrap command after git checkout -b cmsis origin/cmsis-dap before it worked.
Hi Rik,
Thank you very much for your feedback, I just updated the page to fix it.
Currently I’m using other alternative to debug MKL25Z128 microcontroller: I’m using a STLinkV2 (from STM32F4Discovery) to program the chip directly. I will post a tutorial about it.
Do you know the author of usbtiny? It is hosted at same site as your signature (http://www.xs4all.nl).
Hi Alan
Great job!
Have you posted the tutorial about programming MKL25 from STM32?
Thank you
Hi Mirco,
Yes, you can use a STM32 board with STLink-v2 (i.e. STM32F4Discovery) to program Kinetis KL25.
More info: https://acassis.wordpress.com/2013/05/22/adding-support-to-kinetis-microcontroller-on-openocd/
You are welcome!
Excellent, thanks for sharing! I’m writing up an article on do-it-yourself toolchain for Kinetis (http://mcuoneclipse.com/2013/07/20/dyi-free-toolchain-for-kinetis-part-1-gnu-arm-build-tools/), and OpenOCD with CMSIS-DAP needs to be par to it 🙂
Hi Erich,
It is a pleasure receive your comment here. I access your site often to get more information.
Unfortunately I do not use CodeWarrior / Processor Expert (I’m a former Freescaler and I always criticized them for selling software rather than focus on selling chips).
I’m glad my post help you in some way, thank you very much.
I have noticed some compiler errors where warnings are treated as such(c++). I use the following configure command:
./configure –enable-maintainer-mode –enable-cmsis-dap –disable-werror
Ran make afterwards, and all was well.
I can connect to the target using telnet, and halt and resume the target cpu(with current code loaded), but am failing to load new code using fast_load command.
I get a Error: CMSIS-DAP: Write Error (04).
Could you please post how go about loading new code to the target cpu?
Many thanks
Georg
I Georg,
Based on your comments at Erich’s site I think you got it working, right?
Normally this write access error is related to wrong initializition of openocd.
Thanks, Will look at that.
i am getting this error
Open On-Chip Debugger 0.7.0-dev-g1d8f0c1 (2013-08-01-22:18)
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
Error: Can’t find CMSIS-DAP Interface! Please check connection and permissions.
Error: Error selecting ‘cmsis-dap’ as transport
in procedure ‘interface’
when i plug in, the device is enumerated as /dev/ttyACM0 whose permissions are ok
Hi, I think you faced some issue during the cmsis firmware update, as you said in another comment. Please try to restore original P&EMicro firmware and repeat the process again.
If it don’t work you could try to use OpenOCD with original Freescale firmware using an OpenOCD patch modification that Nemui Trinomius implemented to get it working: http://nemuisan.blog.bai.ne.jp/?cid=8604
It was simple actually, set udev permissions or run as root. I am now learning debug commands using arm-none-eabi-gdb connecting to openocd with “target remote localhost:3333” . Question is, what is the summary of commands i have to run to step through code? the only one that seems to work is “monitor reset” followed by “continue” after that i dont know how to break the program. if you could point me somewhere…
Hi Karibe,
after you executed “target remote” you could use default GDB command for step debugging and it should work. Please refer to GDB documentation for more information. Currently I’m using NuttX directly, then all my debugs are running directly on this RTOS, then it is easier.
Yeah good advise, i just got there and trying them out, working pretty much well. I am referring to a http://www.chemie.fu-berlin.de/chemnet/use/info/gdb/gdb_6.html got a few and they work fine
Ok so one (i guess important) command i cant run that i am currently lookinng into is “reset”:
(gdb) monitor reset
invalid command name “jtag”
in procedure ‘reset’
So i think in the CMSIS-DAP implementation in openocd, the reset command is not working. looks like its beyong configuration. “reset init” doesnt run too. The only thing i can see in the kl25.cfg is soft reset being set.
Here is what I can do so far:
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x00000000 in ?? ()
(gdb) moitor halt
Undefined command: “moitor”. Try “help”.
(gdb) monitor halt
target was in unknown state when halt was requested
CMSIS-ADI: cmsis_dap_queue_ap_write 00 a2000002
CMSIS-ADI: cmsis_dap_queue_ap_write 04 e000edf0
CMSIS-ADI: cmsis_dap_queue_ap_write 10 a05f0003
CMSIS-ADI: cmsis_dap_queue_dp_write 08 00000010
CMSIS-ADI: cmsis_dap_run
CMSIS-ADI: cmsis_dap_queue_ap_read 10
03030003
CMSIS-ADI: cmsis_dap_run
CMSIS-ADI: cmsis_dap_queue_ap_read 10
00030003
CMSIS-ADI: cmsis_dap_run
(gdb) load LED_blink.elf
Loading section .interrupts, size 0xc0 lma 0x0
Loading section .text, size 0x2b8 lma 0x800
Loading section .romp, size 0x18 lma 0xab8
Start address 0xa5d, load size 912
Transfer rate: 19 KB/sec, 304 bytes/write.
(gdb) symbol-file LED_blink.elf
Reading symbols from LED_blink/Debug/LED_blink.elf…done.
(gdb) break main
Breakpoint 1 at 0x88e: file ../Sources/main.c, line 40.
(gdb) break 46
Breakpoint 2 at 0x8a4: file ../Sources/main.c, line 46.
(gdb) monitor resume
CMSIS-ADI: cmsis_dap_queue_ap_write 00 a2000002
CMSIS-ADI: cmsis_dap_queue_ap_write 04 e000edf0
CMSIS-ADI: cmsis_dap_queue_ap_read 18
CMSIS-ADI: cmsis_dap_queue_dp_write 08 00000010
20002ffc
CMSIS-ADI: cmsis_dap_queue_ap_write 18 00000a5d
CMSIS-ADI: cmsis_dap_queue_ap_write 14 0001000f
CMSIS-ADI: cmsis_dap_run
CMSIS-ADI: cmsis_dap_queue_ap_write 18 20002ffc
CMSIS-ADI: cmsis_dap_run
CMSIS-ADI: cmsis_dap_queue_ap_write 10 a05f0001
CMSIS-ADI: cmsis_dap_run
(gdb) step
Single stepping until exit from function __thumb_startup,
which has no line number information.
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x88e: Unknown error -1.
Cannot insert breakpoint 2.
Error accessing memory address 0x8a4: Unknown error -1.
(gdb)
Hi Karibe,
It is very strange. Maybe some changes has broken the working code.
As an alternative option you could use OpenOCD with a ST-Link programmer to flash and debug Freedom board:
https://acassis.wordpress.com/2013/05/22/adding-support-to-kinetis-microcontroller-on-openocd/
openOCD implementation for reset was changed and now it works fine
Hi Karibe,
Thank you very much for this information. []’s
Thank you it worked for me.
Since this is an old post from 2013, what i did is, copied CMSIS-DAP firmware from “FRDM-KL05Z Quick Start Package” for my FRDM-KL05Z board. Again openOCD showed error like “unable to open cmsis-dap device”, after that i modified udev rules.
Then it worked.
-c “interface cmsis-dap” was a crucial tip. , thanks again.
Hi Abhilash,
Nice to know it helped you!