Debug Multiple Boards with GDB at the Same Time

Many times it is very useful to debug multiple boards at the same time. For example if I’m debugging a communication stack between two boards: that way I can debug the protocol on both sides. Eclipse is a great framework which allows that. This post shows how to debug multiple boards (e.g. the NXP Freedom boards) in parallel from the same Eclipse IDE using GDB and the Segger J-Link:

Two NXP Freedom Boards debugged at the same time

Two NXP Freedom Boards debugged at the same time

Outline

For Eclipse and GDB it is not a problem to debug multiple boards (or cores) the same time: they show up as different debug sessions in the ‘Debug’ view. For example I’m debugging here two different applications on different boards, the same time:

Multi Board Debugging with NXP Kinetis Design Studio

Multi Board Debugging with NXP Kinetis Design Studio

To switch the ‘current’ debug context I use the ‘Debug’ view and select the ‘thread’ I want to debug: then all the other views follow that thread context. For eclipse it does not matter if they are ‘threads’ like in an RTOS environment, separate cores on a multicore SoC or multiple boards: it is all the same.

Multiple board debugging is easily possible if I’m using two different debug (hardware) connections, e.g. one P&E Multilink Universal and one Segger J-Link.

💡 It does not matter if it is a ‘real’ Segger J-Link or P&E Universal Multilink: the same applies for the ‘OpenSDA‘ version of both.

With using GDB I need to understand a bit the inner working so I can play with multiple GDB debug sessions. In this post I show how to debug multiple boards with the same GDB server, but for multiple boards. I’m using the NXP Kinetis Design Studio (Eclipse based IDE), but the same principles apply both for command line GDB debugging or using any other Eclipse based IDE as long as they are using the GNU Debugger (GDB).

GDB

With using GDB it is important to understand the chain from the Eclipse IDE down to the target Microcontroller (see “DIY Free Toolchain for Kinetis: Part 3 – Debugger (GDB Server with P&E and Segger)“). The GDB in Eclipse talks over TCP/IP to the vendor (P&E/Segger) GDB Server which then talks to the Debug probe and microcontroller:

GDB with GDB Server

GDB with GDB Server

So if I have two microcontroller and two debug probes from the same vendor (e.g. Segger), I need to have different TCP/IP connections to the vendor GDB Server. The ports are listed for example if I run the Segger GDB Server:

SEGGER J-Link GDB Server V5.02k Command Line Version

JLinkARM.dll V5.02k (DLL compiled Nov 13 2015 18:22:26)

-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               on
Init regs on start:            on
Silent mode:                   off
Single run mode:               on
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 MKL25Z128xxx4
Target interface:              SWD
Target interface speed:        1000kHz
Target endian:                 little

From the Segger UM08001_JLink.pdf (Source: Segger):

3.3.5.19 -port
Description
Starts GDB Server listening on a specified port. This option overrides the default listening port of the GDB Server. The default port is 2331.
Note: Using multiple instances of GDB Server, setting custom values for this
option is necessary.
Syntax
-port <Port>
Example
jlinkgdbserver -port 2345

In the GNU ARM Eclipse debugger panel for Segger J-Link I can specify the port number.

Segger GDB Ports

Segger GDB Ports

To debug another board with that GDB server, I’m specifying different ports for my other launch configuration:

Different ports for extra connection

Different ports for extra connection

💡 There is as well a possibility to *not* start the GDB server locally (topmost option in above dialog) and have the GDB server started e.g. from the command line. However somehow this failed in the case of running multiple GDB servers: the board did not get programmed. I have not investigated this further, but this might be a bug in the GDB server or the GNU ARM Eclipse plugins (I really don’t know). But starting the GDB server locally with different ports worked for me 🙂

If I start the debugger, I get a dialog from Segger where I can choose the emulator I want to use. In the case of two NXP Freedom Boards with Segger OpenSDA firmware, they are both identical and show the same serial number (SN). So I have to guess and pick the correct one. If using a ‘real’ Segger J-Link it would show the serial number which is on the back of the J-Link probe.

Segger J-Link (OpenSDA) USB Identification

Segger J-Link (OpenSDA) USB Identification

For the above case with identical serial numbers it seems that the ‘#’ corresponds to the physical USB port. At least with my experiments the number stays with the USB port and is not depending on the order how the boards are plugged. That might be different for other host systems.

With this, I’m able to debug two boards the same time 🙂

Debugging two Freedom Boards

Debugging two Freedom Boards

Summary

It is possible to debug multiple microcontroller and boards the same time with a GDB based IDE like the NXP/Freescale Kinetis Design Studio. Because there is a TCP/IP connection with ports from the GDB client to the server, it is required to specify different ports for the board. Then it is up the GDB server to select the USB connection. In the case of the NXP OpenSDA implementation multiple boards might report the same USB SN (serial number), so it takes some guessing at this stage. But then I can debug multiple boards the same time from Eclipse.

💡 The remaining question is how to do the same with the P&E GDB Server? I tried that too, but there is no port setting possible in the debug panels. It is possible to launch the GDB server on the console with a different port (see Command Line Programming and Debugging with GDB). But as noted above, this would need not to launch the server from Eclipse, and with that flash programming somehow did not happen 😦

Happy Debugging 🙂

Links

Advertisements

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