Attach with the Debugger to a Running Target

Sometime I’m pretty sure I wrote about a topic I can find or refer to, and I was pretty sure I did write about ‘attaching to a running target’ using MCUXpresso IDE in an article, but Google does not find it? The only rational outcome is that I can blame Google and I have to come up with a potential duplicate ;-).

Anyway: attaching to a running target is such an essential life saver it deserves a dedicated article.

Haltet Target

Why ‘attaching’ is such an important feature? Because it allows you to run the target for a very long time, and if it fails or if you want to inspect it you can re-attach the debug cable or connection, halt it and see what is going on without changing it or re-programming it

It basically works that way: the debug session is establishing a connection, but does not issue a reset or starts downloading the binary as it usually does. As a user I can then just halt the target as I would do normally in a debug session.

For example I can have multiple boards running some tests, and in case of test failure I would like to inspect I can turn on a LED and then wait in an infinite loop for the debugger to be attached. If one of the boards shows a failure, I can attach the debug cable, do an ‘attach’ action and then I can halt the target and inspect it’s state. For example if the target has halted on an assert like this:

How you can do it depends a bit on the IDE and debug connection as this is not something provided out of the box with Eclipse. The Eclipse Embedded CDT has it included and this is what I have used in my article using the Kinetis Design Studio.

In the MCUXpresso IDE this exists too with even more actions, but is probably a bit hidden to find it. The functionality is behind the ‘probe icons’ in the IDE Quickstart Panel:

Debug Probe Icons in Quickstart Panel

Each of the icons has a small drop-down with actions: From there I can use ‘attach’

Debug Actions behind probe icon

This is supported for all debug probes (LinkServer/CMSIS-DAP, PEMicro and Segger).

Note that there are other very useful actions to do like programming the flash or erase it.

If using ‘attach’ it will launch a debug session and the target will show up running:

Running Target in Debug View

To halt the target, use the Suspend action:

This halts the target and it is ready to be inspected:

Suspended Target

Note that the probe icon has now the last action stored:

And the Launch Config has a dedicated Icon decorator to indicate the mode:

If doing a ‘debug’ session using the main toolbar ‘blue debug icon’ it should revert back to normal ‘debug’:

Start Debug Session

But just in case it does not: make sure you you revert it back to the operation you want:

With this, I hope you find and can use that very useful feature.

Happy attaching 🙂

5 thoughts on “Attach with the Debugger to a Running Target

  1. Hi Erich

    > Sometime I’m pretty sure I wrote about a topic I can find or refer to, and I was pretty sure I did write about ‘attaching to a running target’ using MCUXpresso IDE in an article, but Google does not find it? The only rational outcome is that I can blame Google and I have to come up with a potential duplicate ;-).

    Are you thinking of this one? (I found it with a Google search for site:mcuoneclipse attach to running target MCUXpresso :-))

    https://mcuoneclipse.com/2020/11/03/debugging-bootloader-and-application-with-one-debug-session/

    I presume not this one since it doesn’t mention MCUXpresso?

    https://mcuoneclipse.com/2015/03/20/attaching-to-a-running-target-with-segger-j-link-gdb-and-eclipse/

    Regards
    Tommy

    Like

    • Hi Tommy,
      yes, the second link is for Kinetis Design Studio so does not apply to MCUXpresso IDE. I missed the first link with the bootloader but this is somewhat aiming at a different topic. Anyway I’m glad you have found them 🙂

      Like

  2. > a Google search for site:mcuoneclipse attach to running target MCUXpresso

    a Google search for site:mcuoneclipse.COM attach to running target MCUXpresso

    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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

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