SWD Debugging with the FRDM-KL25Z Board

The OpenSDA on the FRDM-KL25Z board is a cool feature: I do not need any external debugging device to program and debug my board :-). But my KL25Z custom board will not have that OpenSDA on it: first because it would add additional costs, and I do not see a way how I could use it for my board. I better start using a SWD/JTAG debugger for my Freedom board to have everything in place.

What I need to add to the black Freedom board is the SWD header:

SWD J6 (populated) and J11 (unpopulated)

SWD J6 (populated) and J11 (unpopulated)

💡 With that header usually both JTAG and SWD debugging is possible. If it is SWD (lower pincount) or JTAG depends which microcontroller signals are routed to the header. But many times the terms JTAG and SWD are mixed even if technically not correct.

For the part numbers see this post.

Looking at the schematics and the SWD connector, there is a J11 jumper (unpopulated) which can isolate the SWD (Single Wire Debug) clock signal between OpenSDA and the target.

The Freedom Board User Guide (chapter 5.2.1 Debug Interface) seems to indicate that it is possible to cut the J6 trace and then to debug another board with the connector. However, this is not possible, as it seems that the OpenSDA firmware is tight to the processor on the board. You will receive an error that this is not possible:

Error 17926 Target MCU mismatch

Error 17926 Target MCU mismatch

💡 Cutting that trace is *not* needed for me to debug the target over the SWD connector. Cutting that trace is *only* needed if I want to debug another board with OpenSDA (e.g. see “Using the Freedom Board as SWD Programmer“). For debugging the FRDM board with an external SWD cable the trace/jumper has to be installed!

SWD Connector with J11 (Source: Freescale FRDM-KL25Z Schematics)

SWD Connector with J11 (Source: Freescale FRDM-KL25Z Schematics)

The good thing is that I can use my existing P&E Universal Multilink. The debugging connection settings are very transparent between OpenSDA and USB Multilink: all what I need to do is to change the interface in the run/debug launch settings:

USB Multilinke instead of OpenSDA in CodeWarrior

USB Multilinke instead of OpenSDA in CodeWarrior

With this, ready to connect the Multilink with the Freedom board:

❗ Do *not* power the board with the OpenSDA USB port if debugging with a SWD/JTAG cable! Use the KL25Z USB connector as shown in the picture above! I have been told that otherwise either the diode D1 or D2 on the board might get burned, so be warned! I have not seen that problem for myself.

Freedom Board and Multilink side-by-side

Freedom Board and Multilink side-by-side

Debugging with the P&E Multilink just worked fine. OpenSDA already is pretty fast, but felt that using the Multilink was even a bit snappier. In any case, if OpenSDA would not be able to connect to my KL25Z on the Freedom board, I have now a second way to get access to it. And something like this has been always been useful for me in the past. I hope I have not to count on it, but always good to have it 😉

Happy SWDing 🙂

23 thoughts on “SWD Debugging with the FRDM-KL25Z Board

  1. Hi Erich

    I installed the headers and cable but am unsure of the instructions. I want to use the Freedom board as a pod. So I connected from my custom k20dx256z JTAG to J6, and connected the pc usb to the SDA. But I get no connection in CW although the drivers installed. I built a new connection with the OOSJTAG – USB port and left the interface as USB Mulitlink. But I get no connection. Do you have any advice please?

    Like

  2. First a caveat: I have not tried this yet. However, based on discussions with Michael Norman of Freescale and also looking at the FRDM-KL25Z User’s Manual, this should be possible. Instructions are in 5.2.1 beginning on page 7. The key seems to be cutting a trace on the bottom side of the FRDM board that connects the SWD_CLK to the KL25Z MCU so the KL25Z won’t interfere with communication between the K20 and whatever offboard MCU you have connected via J6.

    Like

    • Hi Roger, I tried this now, as you suggested, and it does not work for me. Error 17926 is shown. I have updated the post with that information. So as I feared: this does not work for me.

      Like

      • I even had my Freescale FAE tell me that I could use the KL25Z Freedom Board to program my kinetis µP for my projects and pointed me to the same 5.2.1 document. I’ve tried it today and also get the 17926 message. I’ve also tried copying the s19 .HEX file to the freedom board and that does not work either.

        Don’t let the name “Freedom” fool you with their Freedom boards. PEMICRO does not want to lose sales on their $119 Multilink or $399 Multilink FX by having some $12.95 toy do the job.

        BTW, since it is now March, do you know if there have been any recent solutions to the Freedom boards to allow the user to program external processors?

        Like

        • I have borrowed my FRDM board with the JTAG headers to a friend, so I cannot try it out. But I saw that P&E has published on their website (www.pemicro.com/opensda) a new firmware (Jan 7th). So it could be that this one supports programming another processor.

          Like

  3. Hello Erich,
    I have a board with KL25Z,I develop it with IAR,but i “Download and Debug” with jlink,It runs well,

    but re-plug jlink ,it runs abnormal..

    Like

  4. Hi Erich,

    Nice documentary. P&E shall have thanked you for all these useful tips.

    I’d like add one tip: If you use Code Warrior to debug with MultiLink USB, you have to make one critical selection in Code Warrior IDE. If not, the debug will always tell you can’t connect to device, but it doesn’t tell you the problem.

    Click on Debug Configuration->Edit, Select USB Multilink in “Interface”. Then in “Additional Options”, tick “Use SWD reduced pin protocol for communications”. Then click “OK” to apply changes.

    It will be much nicer for P&E having this in your manual.

    Cheers,
    Michael

    Like

    • Hi Michael,
      thanks 🙂
      That ‘SWD vs. JTAG’ is not a P&E only thing: it applies to other ARM run control solutions like Segger too. You are right: without the proper selection, it is not possible to talk to the device. As a general rule: if using the small 10pin ribon cable, then ‘SWD’ needs to be selected, otherwise ‘JTAG’. As the default is JTAG, it happened to me several times to miss that setting change too. It would be nice if there could be an automatic detection of the setting, or that the run control unit would try the other setting in case of failure.

      Like

      • Hi everyone,

        I’d really like to emphasize that you can’t program the FRDM-KL25Z or FRDM-KL46Z boards with a P&E programmer if you cut the trace! Cutting the trace will result in the following error:

        “Error launching test01_FLASH_PnE U-MultiLink
        ARM GDI Protocol Adapter : Can’t connect. The Debugger can not connect to the P&E device”

        Me and a coworker spent half a day trying to figure out why CodeWarrior kept giving us this error. In fact, a lot of people are confused about this in the Freescale Community forums! Like most people, we cut the trace, got the error and then we thought that there was a problem with the drivers. So we manually updated and re-installed the Jungo drivers many times and we reset our computers after each re-install. Huge waste of time!

        Finally, I saw this post by Erich and read that he didn’t cutoff the trace to get his P&E Multilink to work. Then I put a jumper to join the pins and the program was finally downloaded to the FRDM-KL46Z!

        Please, if you see people posting about this problem then first ask them if they cut the trace before sending them to re-install their drivers! It will save them a lot of trouble.

        Thanks and let’s spread the word!

        Like

  5. Hi Erich,

    It’s ok, we figured it out eventually 🙂 However, it would be nice if we could figure out a way to spread the word about the jumper and programming with a P&E Multilink. Like I said, the Freescale Community forums are filled up with people going crazy thinking they have a problem with drivers. (That can happen, but it’s easier to check first if they have cut the trace)

    For now, I posted a comment on your post “Using the Freedom board as an SWD programmer” to let people now what to do if they have this problem. But it might just get lost within all the other comments. Maybe it’d be easier to see if it was mentioned within the post itself?

    Frohes neues jahr!

    Like

  6. Thank you for your post. The FRDM-KL25Z handbook was quite fuzzy.

    I can positively confirm that the FRDM-KL25Z works with Segger J-Link:

    – J11 closed
    – Connect J-Link via J6
    – Power the FRDM-KL25Z via the KL25Z USB

    Like

  7. Pingback: How to Recover the OpenSDA V2.x Bootloader | MCU on Eclipse

  8. Pingback: Tutorial: Using Single Wire Output SWO with ARM Cortex-M and Eclipse | MCU on Eclipse

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.