This is the third part of a tutorial series how to ‘do-it-yourself’ a tool chain for the Freescale Kinetis microcontroller, with the FRDM-KL25Z as example. The tool chain is using GNU ARM gcc plus Eclipse Kepler release. So far I have the following parts:
List of Tutorials
- Part 1: Setting up ARM GNU tool chain
- Part 2: Setting up Eclipse IDE
- Part 3: Setting up the debugger (P&E and Segger)
- Part 4: Setting up Processor Expert
- Part 5: Setting up FreeRTOS Kernel Awareness
- Part 6: Linux Host Support with OpenOCD and CMSIS-DAP
- Part 7: GNU ARM Eclipse Plugins
- Part 8: Processor Expert with GNU ARM Eclipse Plugins
- Part 9: DIY Free Toolchain for Kinetis: Part 9 – Express Setup in 8 Steps
- Part 10 – Project Creation with GNU ARM Eclipse 2.1.1
So far things are very generic. But with debugging it means different hardware, and different hardware connections. And for this connection we need a GDB Server.
Eclipse CDT features a GNU Debugger (GDB), and this is what I want to use here: debugging my microcontroller with GDB inside Eclipse. In order to debug the microcontroller, I need two other things: a GDB Server and a Debug Probe.
- The ‘Debug Probe‘ is a hardware/software able to talk to the microcontroller, e.g. using JTAG, SWD, or using e.g. a serial protocol to talk to a special program on the microcontroller. This Debug Probe stops the target, does single stepping, and in many cases does as well flash programming. Typical examples are the P&E Multilinks, Segger J-Link, or as well the OpenSDA Debug Firmware on the FRDM boards.
- The ‘GDB Server‘ is a service or program which sits between the GDB inside Eclipse and the Debug Probe. GDB talks to the GDB server using TCP/IP and a port number, so that GDB Server can be either on your host machine, or on a remote machine. It translates and sends commands from the GDB in Eclipse to the Debug probe, things like setting breakpoints and so on. The communication between the GDB Server and the Debug Probe depends on the probe capabilities. It can be USB, TCP/IP, Serial or anything else.
I need a matching GDB Server to my Debug Probe used. There are many possible, and in this post I show:
- P&E GDB Server: for P&E OpenSDA and P&E Multilinks
- Segger GDB Server: for Segger OpenSDA and Segger J-Link
💡 I’m aware that CodeRed has a GDB server too which works with their OpenSDA implementation (see this post). However, CodeRed has been acquired by NXP back in May 2013, and they will stop support for non-NXP parts. If you want to try it out, the steps below should work with minor modifications too.
But the list does not stop here. There are other especially open source implementation of GDB Servers (mbed? USBDM? OpenOCD with CMSIS-DAP?). I wanted to show in this post OpenOCD, but run into some setup problems. So I plan to cover OpenOCD in one of the next tutorials.
In order to add GDB debugging to my DIY Tool Chain, I need
- Add ‘GDB Hardware Debugging’ to Eclipse
- Add a GDB Server
- Configure the Eclipse Launch Configuration to talk with the GDB Server
Eclipse and GDB Hardware Debugging
Eclipse comes with a lot of plugins already installed. But what is missing is the ability to debug a board like the FRDM-KL25Z. For this we need to install ‘GDB Hardware Debugging‘. I do this with “install new software”:
Then press ‘Add’:
Provide a name and point to
💡 If you are not using Kepler, then you will need to change the URL to point to the update site of the Eclipse release you are using.
Then select C/C++ GDB Hardware Debugging:
The rest is trivial: click next and through the details of installing the software. At the end, restart Eclipse.
P&E GDB Server
❗ After publication of this article, P&E has released a new Eclipse plugin which includes a much better intergration and includes as well the GDB server (free of charge). So instead following the steps below, please have a look at P&E Eclipse Update Site for GNU ARM Eclipse Plugins.
P&E offers a GDB server for Kinetis devices. There is free (basic, limited) version available, and an unlimited (paid) one.
- Works for all P&E run control devices (Multilinks, including P&E OpenSDA on the Freedom and Tower boards.
- Free (limited speed and code size) version available. Not clear what the code size limit really is (one information says ‘half of the flash size’, and in the software itself I see ’64 KByte’ (although I’m using a 128 KByte KL25Z, so that might be the same).
- Used with the P&E OpenSDA, it supports USB CDC virtual COM communication.
- Only Windows.
- Only for P&E firmware.
- Slow stepping and code size limitation in free version.
- Full version costs $299.
P&E GDB Server Configuration
Download and install the software from here. Make sure your target and debug connection has power.The FRDM-KL25Z needs to run the P&E OpenSDA Debug Application.
Start the server from the shortcut installed:
Use the refresh button to scan for a port on a given connection. Additionally, as the FRDM-KL25Z is using SWD, make sure that this option is selected, together with the selection of the device used:
Once connected with GDB in Eclipse (see later), you should see some status messages on the right hand side:
Segger GDB Server
Segger offers a GDB server for their J-Link debugging units on http://www.segger.com/jlink-gdb-server.html.
- Support for all Segger J-Link run control devices. Segger has an OpenSDA J-Link Lite implementation for the FRDM-KL25Z.
- Fast stepping and no code size limitation.
- ‘Unlimited‘ flash breakpoints.
- GUI and command line version for Windows.
- Linux and Mac support (command line version only).
- No USB CDC with the FRDM-KL25Z board with the Segger OpenSDA firmware.
- Only for Segger firmware.
- Using it with Segger OpenSDA is subject of restrictions.
Segger GDB Server Configuration
Start the J-Link Server. On my machine it is located in
C:\Program Files (x86)\SEGGER\JLinkARM_V472\JLinkGDBServer.exe
Configure it for SWD and the target device used:
Pressing OK, and it should be waiting for the connection from Eclipse GDB:
Eclipse Debug Configuration
Eclipse needs to have a Debug Configuration for the project to be debugged. For this I select the project in the Project Explorer, and use the ‘Debug Configurations…’ menu under the ‘debug icon’ in the tool bar:
Then select ‘GDB Hardware Debugging’ and use the ‘+’ icon to add a new configuration:
This populates the launch configuration with the project name and binary file to debug. I need to set it up to use the correct GDB. For this is choose ‘Select other…’:
In the next dialog I select the Standard GDB Hardware Debugging Launcher:
In the Debugger tab, point to the GDB executable within the ARM GNU installation folder which is this for me:
C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q2\bin\arm-none-eabi-gdb.exe
In the Startup tab I can specify what should happen on starting the application. Basically I can initialize registers or set breakpoints:
❗ Somehow ‘#’ is accepted in gdb init scripts for comment lines, but not in above Eclipse dialog. So if you see errors in the console view about this, my only solution is to remove the lines starting with #
The first edit box has first commands sent to the gdb server. Below is the script I’m using for P&E:
# connect to the gdb server # Ports used: P&E: 7224, Segger: 2331 target remote localhost:7224 # Set gdb server to little endian monitor endian LITTLE # Set JTAG speed to 1000 kHz monitor speed 1000 # Reset the target monitor reset 0 monitor sleep 100 # Set JTAG speed in khz monitor speed auto
The above script is very simple and should work with most GDB servers. What is different for each server is the port. Segger is listening on a different port (2331), so use for the first command this:
target remote localhost:2331
I have ‘Set break point at:’ specified with ‘main’: that way the debugger stops at this address. Alternatively I can use the ‘break’ command in the ‘Run Commands’ area. In my setup I’m using this:
tbreak main monitor reset 0 continue
which will start execution of the target.
💡 Use the GDB Server manual/reference to find out which other commands are supported.
With everything set up, I can start the debugger:
and I’m debugging with GDB :-):
In order to debug my microcontroller with GDB, I need a GDB server which works for my debug probe or debug connection. For the FRDM-KL25Z I can use the P&E GDB Server or the Segger GDB Server. The P&E one is free in a limited version only (limited code size, slower speed), while the Segger one is faster and unlimited, but does not offer USB CDC.
And I need to find out what it takes to have OpenOCD working too. Maybe somebody has written a tutorial about this already?
Happy Debugging 🙂