The NXP MCU-Link is a powerful $10 debug probe for ARM Cortex-M devices and works with the NXP LinkServer for debugging. The LinkServer does not an implement a gdb server, so it limits its usage e.g. for scripting or command line debugging. But as MCU-Link is also a CMSIS-DAP compatible debug probe, I can use it with OpenOCD which is open source and implements a GDB server. This article shows how I can use it with the MCU-Link.
In this article I show how you can use OpenOCD with Eclipse (MCUXpresso IDE or any other recent Eclipse) and the MCU-Link or any other CMSIS-DAP capable debug probe. I’m using the binaries and plugins from Liviu Ionescu and his great Eclipse Embedded CDT project (formerly GNU ARM Eclipse).
Why OpenOCD? It is open source and supports many micro-controller families. It allows you to use the NXP MCU-Link with GDB server which is great for command-line debugging and scripting. The downside is that using OpenOCD requires tweaking and without expert knowledge you are stuck with the devices supported by the OpenOCD distribution. So if you want to have professional tools, working out of the box and supporting many silicon vendors, I recommend to consider SEGGER or P&E.
The NXP MCU-Link debug probe (see “New MCU-Link Debug Probe from NXP“) enumerates as CMSIS-DAP debug probe and can be used with OpenOCD as such:
The first step is installing the pre-built OpenOCD binaries. Using OpenOCD is challenging for most users as for more than 3 years there has been no new releases from OpenOCD.org: instead it is expected that you configure and build your binaries. Which is OK but can be daunting for new users. Luckily there are pre-built binaries available provided by Liviu Ionescu on https://xpack.github.io/openocd/releases/.
Download the binaries and install them. In this article I’m using the v0.10.0-15 release and I have it installed on Windows in
C:\Program Files (x86)\GNU ARM Eclipse\OpenOCD\xpack-openocd-0.10.0-15
The next thing is to install the Eclipse Plugins: One way is to use the Eclipse Marketplace:
From there, search for the Eclipse Embedded C/C++ plugin:
Then install the plugin. I have installed it with all available options:
Finish the installation process and restart Eclipse.
In the workspace preferences, check that the global OpenOCD path is pointing to the installed OpenOCD binaries:
With this, everything is installed. The only thing missing is to configure the debug configuration(s) to be used.
To use OpenOCD, I have to setup a debug configuration first. Have the project selected and go to the Debug Configurations:
Double-Click on ‘GDB OpenOCD Debugging’.
This creates a new launch configuration based on the project selected.
Make sure the configuration points to the OpenOCD executable:
Make sure you use the gdb from the GNU toolchain used to build the application:
Now the most difficult part: OpenOCD needs a configuration file for the device used, passed with the -f command line option. For example for the FRDM-KL25Z board I can use
You can find existing board files in the OpenOCD installation folder, in my case it is in
C:\Program Files (x86)\GNU ARM Eclipse\OpenOCD\xpack-openocd-0.10.0-15\scripts\board
If your board is not listed, you can create a new board file, similar to the existing ones. Basically you need to set the interface (CMSIS-DAP for the MCU-Link) and the target. Below is the example for the FRDM-KL25Z.
# This is an Freescale Freedom eval board with a single MKL25Z128VLK4 chip. # http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-KL25Z # source [find interface/cmsis-dap.cfg] # increase working area to 16KB set WORKAREASIZE 0x4000 # chip name set CHIPNAME MKL25Z128VLK4 reset_config srst_only source [find target/kl25.cfg]
Last but not least: I recommend to store it as a ‘shared file’ (see “Sharing Debug Configuration with Eclipse“):
To launch the debug session, use the ‘green’ debugger icon:
With this, I’m debugging with OpenOCD:
In case you see some warnings about timeouts and the recommendation to increase it :
Warn : keep_alive() was not invoked in the 1000 ms timelimit. GDB alive packet not sent! (2150 ms). Workaround: increase "set remotetimeout" in GDB
Below is how it can be increased to 5 seconds:
set remotetimeout 5
Using OpenOCD with LPC845
One of my favorite NXP LPC devices is the LPC845. In order to use OpenOCD with the LPC845-BRK board, there are a few but important tweaks to be made.
First, create a new OpenOCD configuration file (lpc845-brk.cfg) and place it into scripts/board, with following content:
# File: board/lpc845-brk.cfg # This is the OpenOCD configuration for the NXP LPC845-BRK evaluation board with the LPC845M301JBD4 # MCU-Link is a CMSIS-DAP probe source [find interface/cmsis-dap.cfg] # LPC845 only supports SWD transport select swd # set chip name, internally it uses lpc8xx as well set CHIPNAME lpc84x # TAP ID is different from the others set CPUTAPID 0x0bc11477 # we do have up to 8K RAM, use a good portion of it set WORKAREASIZE 0x1000 # the lpc1xxx.cfg sets an adapter speed of just 10 which is *really slow* # comment it out in target/lpc1xxx.cfg and use the one below: adapter speed 5000 # LPC845 has a special IPA Entry point: set IAP_ENTRY 0x0F001FF1 # load LPC845 configuration source [find target/lpc84x.cfg]
The really important one is the thing about the adapter speed. The script uses the target/lpc1xxx.cfg configuration in the back end which by default sets a very slow speed of 10: as noted in the comment above, disable that value and use the one from the board/lpc845-brk.cfg:
With this, I can debut the LPC845 with OpenOCD:
💡 I recommend to use the McuLib FreeRTOS port on because this port has all the patches and tweaks implemented to make OpenOCD FreeRTOS debugging possible. The usual FreeRTOS ports do not have this included.
To get FreeRTOS thread awareness in OpenOCD, see “FreeRTOS Thread Debugging with Eclipse and OpenOCD“.
Be aware that at least with the GNU gdb (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 22.214.171.12490709-git there is a bug in the gdb preventing using it:
[Switching to thread 1 (Thread 1)] /mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/src/gdb/gdb/inferior.c:287: internal-error: inferior* find_inferior_pid(int): Assertion `pid != 0' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session?
So at least for that version I FreeRTOS thread awareness is not possible with OpenOCD.
Command Line Debugging
The benefit of using OpenOCD instead of the NXP LinkServer on the MCU-Link is that OpenOCD implements a GDB server. For details how to use OpenOCD as command line debugger see the instructions in OpenOCD/CMSIS-DAP Debugging with Eclipse and without an IDE
To have hardware register details, point in the debug configuration to the device CMSIS-SVD file:
See this article how you can get the SVD files as they are usually part of the SDK. With the SVD file I have now register details in the Peripheral view:
To get OpenOCD running is not the simplest task, but can be very rewarding. I’m able now to use it with the NXP MCU-Link and have an open source debug solution which implements a GDB server: great for scripting and automation. The Eclipse Embedded CDT (thanks Liviu!) greatly simplifies things if you don’t want to recompile the OpenOCD binaries. The downside is that not all and every device is supported by OpenOCD, but that might improve over time. At least popular devices are supported by the community, and with the MCU-Link I have a very low cost debug probe for it too.
Happy Probing 🙂