In a previous post it was already shown how to setup Eclipse for debugging STM32 applications. However, since I’m a big fan of QtCreator IDE, I figured out how to set it up in this as well. This does not mean you can use Qt code for developing your application! We’re only using the IDE.
You’ll need the following software:
- arm-none-eabi-gcc toolchain
- Python2.7 for i386
I am running this on Linux Mint 17.1, but it should be similar for other Linux distributions or versions.
Download it from www.qt.io and install.
Find the download link for OpenOCD on their website. Install in any location you like. I installed it to /opt/openocd. Excellent installation instructions can be found here: http://gnuarmeclipse.livius.net/blog/openocd-install/
Download GNU tools for ARM embedded from launchpad. I installed it to:
It is not necessary to add it to any paths or whatsoever. We will tell QtCreator where to look for it.
The debugger needs a 32-bit version of python libraries. If you’re running on a 64-bit machine, this requires some extra steps. First, add i386 architecture to the package manager and run an update:
sudo dpkg --add-architecture i386 sudo apt-get update
Then, install the i386 version of python libraries by typing:
sudo apt-get install libpython2.7:i386
First thing to do in QtCreator is to go to Help->About Plugins. Under device support, enable the BareMetal plugin by Tim Sander. Restarting QtCreator is required.
Next, go to Tools->Options->Build & Run. We are going to setup a new Kit, but first the compiler and debugger. Go to the Compilers tab and add a GCC compiler. Select the arm-none-eabi-gcc compiler from the directory in which you have it installed.
Next, we’re going to add the debugger. Be sure to select arm-none-eabi-gdb-py. QtCreator is only compatible with the python version of gdb.
In the BareMetal menu, add OpenOCD with default settings.
Then, go to the Devices menu and add a new Bare Metal device.
Now, we have everything setup to make a new kit. Go back to the Build & Run menu and select the Kits tab. Add a new kit and select the following settings. The first time I tried this, I encountered a bug with the compiler selection which was grayed out, so I could not select the GCC ARM compiler. The workaround for this is to add a random other compiler so that you have at least two to choose from.
Debugging a CX-10 project
To demonstrate the debugger, I downloaded an existing cx-10 custom firmware project (which does not support the XN297 radio chip I’m working on).
git clone https://github.com/samuelpowell/cx10_fnrf.git
In QtCreator, create a New Project. Select Import Project -> Import Existing Project. Specify the directory you cloned it to and you should be good to go.
Now, in order to build this project and run it with the debugger, we’ll need to configure build and run settings for the project. Go to Projects Mode (Ctrl+5). If the newly created kit is not your default kit, you need to change the kit first. Then, set the build directory to the project path if it isn’t already, and add the debug argument for make. DEBUG=GDB is specific for the makefile of this project. If you’re doing this for another project, make sure to compile the sources with debug flags -ggdb.
Under Run Settings, add a new run configuration. Select via GDB server or hardware debugger. I don’t know why, but you need to enter the full path to the generated elf file.
Now we’re almost there. The final thing before we can start debugging is to start OpenOCD.
cd /opt/openocd/0.9.0-201505190955/bin ./openocd -f interface/stlink-v2.cfg -f target/stm32f0x.cfg
These flags are specific for the STM32F0x, which is present on the CX-10. Now that OpenOCD is running, start a debug session in QtCreator by pressing the Debug button or F5. You can add breakpoints and do awesome stuff!