DIY Free Toolchain for Kinetis: Part 6 – Linux Host with OpenOCD and CMSIS-DAP

For everyone who wants to build a Do-It-Yourself toolchain for Kinetis on Linux, I recommend to read the following excellent post by Karibe:

Setting up Linux opensource build and debug tools for freescale freedom board FRDM-KL25Z

He describes how to get OpenOCD with CMSIS-DAP working with Eclipse on Ubuntu to debug the FRDM-KL25Z board.

List of Tutorials

Happy Linuxing 🙂

Advertisements

32 thoughts on “DIY Free Toolchain for Kinetis: Part 6 – Linux Host with OpenOCD and CMSIS-DAP

  1. Pingback: DIY Free Toolchain for Kinetis: Part 5 – FreeRTOS Eclipse Kernel Awareness with GDB | MCU on Eclipse

  2. Pingback: DIY Free Toolchain for Kinetis: Part 1 – GNU ARM Build Tools | MCU on Eclipse

  3. Pingback: DIY Free Toolchain for Kinetis: Part 2 – Eclipse IDE | MCU on Eclipse

  4. Pingback: DIY Free Toolchain for Kinetis: Part 3 – Debugger (GDB Server with P&E and Segger) | MCU on Eclipse

  5. Pingback: DIY Free Toolchain for Kinetis: Part 4 – Processor Expert for Eclipse | MCU on Eclipse

  6. Looks like the CMSIS-DAP support has finally been pulled into a branch of the official OpenOCD repository and is starting to get tested and code reviewed, maybe it will be included by default when OpenOCD v0.8 comes out. Presumably openocd+cmsis-dap will become the best “free toolchain” choice even on windows, since it’s so widely used (in the “free toolchain” world).

    I assume it will have none of the restrictions of the P&E Micro or SEGGER “lite” / eval-boards-only versions. I wonder if it will even let us debug non-Freescale Cortex-Ms using a Freedom Board’s OpenSDA as just a “debug access port”?

    Like

  7. Pingback: DIY Free Toolchain for Kinetis: Part 7 – GNU ARM Eclipse Plugins | MCU on Eclipse

  8. Pingback: DIY Free Toolchain for Kinetis: Part 8 – Processor Expert, Eclipse and GNU ARM Eclipse Plugins | MCU on Eclipse

  9. Pingback: DIY Free Toolchain for Kinetis: Part 9 – Express Setup in 8 Steps | MCU on Eclipse

  10. Pingback: DIY Free Toolchain for Kinetis: Part 10 – Project Creation with GNU ARM Eclipse 2.1.1 | MCU on Eclipse

  11. I follow all the steps and it work well for me. The problem, which I’m facing now is that I can’t flash my FRDM-KL25Z board. I start opeocd and after I start gdb, I get this error:

    Open On-Chip Debugger 0.8.0-dev-00175-g8b7acca-dirty (2015-02-15-10:15)
    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-DAP: SWD Supported
    Info : CMSIS-DAP: Interface Initialised (SWD)
    Info : add flash_bank kinetis kl25.flash
    cortex_m reset_config sysresetreq
    adapter speed: 50 kHz
    Info : CMSIS-DAP: FW Version = 1.0
    Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
    Info : DAP_SWJ Sequence (reset: 50+ ‘1’ followed by 0)
    Info : CMSIS-DAP: Interface ready
    Info : clock speed 50 kHz
    Info : IDCODE 0x0bc11477
    Info : kl25.cpu: hardware has 2 breakpoints, 2 watchpoints
    Error: CMSIS-DAP: Read Error (0x04)
    Polling target kl25.cpu failed, GDB will be halted. Polling again in 100ms
    Polling target kl25.cpu succeeded again
    Info : accepting ‘gdb’ connection from 3333
    Error: CMSIS-DAP: Read Error (0x04)
    in procedure ‘halt’

    Warn : Cannot communicate… target not halted.
    Error: auto_probe failed
    Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use ‘gdb_memory_map disable’.
    Error: attempted ‘gdb’ connection rejected
    Error: CMSIS-DAP: Read Error (0x04)
    Polling target kl25.cpu failed, GDB will be halted. Polling again in 100ms
    Polling target kl25.cpu succeeded again
    Info : Halt timed out, wake up GDB.

    Any help appreciated

    Like

      • After some googling, I have suspicion, that this problem of mine could be related with hardware issues. Just can’t find any remedies for it…
        I’ll take a try on your proposal and will see how it works out…

        Like

      • I had this happening to me, when you write a binary with a mistake, like wrong clock configurations, openocd isn’t able to halt the CPU, among other things. One solution is to use alternative debug server like PE or USBDM first , needs changing the firmware, then flash a sample known to work binary from apllication note or something with that debug server, then openocd behaves. Openocd is not that bruteforce when there are issues at startup.
        Another trick is to add gdb events in the openocd initialization target scripts, like this:

        adapter_khz 500

        $_TARGETNAME configure -event gdb-attach {
        halt
        }
        $_TARGETNAME configure -event gdb-attach {
        reset init
        }
        kinda try to catch the target early on.

        Also, try to use hot air gently around the microcontroller chips, may be you have a hardware problem after all.

        Liked by 1 person

      • oh, that sounds like a really good thing. I was running today into such a problem where OpenOCD was not able to halt the CPU. I need to add this one to my kinetis.cfg file to see if it will help me in the future 🙂

        Like

      • Hi,

        Thanks for replay. Since my last post I switched to Kinetis Design Studio. Although I’m not very satisfied with workflow, but it does its job and I have my kl25z board working with it perfectly.

        I made changes to kl25z.cfg file as you advised, but I got different error now 😦 :
        Error message from debugger back end:
        Error erasing flash with vFlashErase packet
        Error erasing flash with vFlashErase packet
        …..
        Info : only one transport option; autoselect ‘cmsis-dap’
        Info : CMSIS-DAP: SWD Supported
        Info : CMSIS-DAP: Interface Initialised (SWD)
        Info : add flash_bank kinetis kl25.flash
        cortex_m reset_config sysresetreq
        adapter speed: 500 kHz
        Info : CMSIS-DAP: FW Version = 1.0
        Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
        Info : DAP_SWJ Sequence (reset: 50+ ‘1’ followed by 0)
        Info : CMSIS-DAP: Interface ready
        Info : clock speed 500 kHz
        Info : IDCODE 0x0bc11477
        Info : kl25.cpu: hardware has 2 breakpoints, 2 watchpoints
        Error: CMSIS-DAP: Read Error (0x04)
        Polling target kl25.cpu failed, GDB will be halted. Polling again in 100ms
        Polling target kl25.cpu succeeded again
        Info : accepting ‘gdb’ connection from 3333
        target state: halted
        target halted due to debug-request, current mode: Thread
        xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
        Info : Probing flash info for bank 0
        Warn : acknowledgment received, but no packet pending
        Error: CMSIS-DAP: Write Error (0x04)
        Warn : erase sector 0 failed
        Error: failed erasing sectors 0 to 0
        Error: flash_erase returned -902
        Info : dropped ‘gdb’ connection

        Like

      • First change the value of adapter_khz from 500 to 50 in the config file.
        Then for the purpose of clarity, just run openocd from terminal:

        openocd -c “interface cmsis-dap” -f /path-to-kl25.cfg

        and on another terminal run the following gdb commands:

        arm-none-eabi-gdb
        target remote localhost:3333
        monitor reset init
        file /path-to.elf
        load

        without any IDE, . This will allow you to at least run individual gdb commands and see at what step the error will occur, from the output above, target was halted, but erasing flash didn’t work. Try a working binary from somewhere else other than your project.

        Like

      • Strange, I just copied CMSIS-DAP_OpenSDA.s19 file to be kl25z board, compiled the same project and debug just started working. Can’t recall now what was the sequence of my actions previous time, probably some problems with my environment, but now it works 🙂 So your last changes in cfg file really helped. Thanks 😉

        p.s. Cloud you help to configure eclipse so it would print binary file size, I just can’t make it with Cross gcc tool chain

        Like

  12. Pingback: OpenOCD/CMSIS-DAP Debugging with Eclipse and without an IDE | MCU on Eclipse

  13. Karibe’s comment was helpful when faced with “Cannot communicate… target not halted.” issue. Added this to .cfg:

    $_TARGETNAME configure -event gdb-attach {
    halt
    }
    $_TARGETNAME configure -event gdb-attach {
    reset init
    }

    Like

What do you think?

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s