Building a debugger isn't strictly necessary for developing on the STM32. However it can make certain debugging tasks easier, and it is relatively simple to do, so we'll do it here. As with the tools in the last post, the version of gdb used (7.6) worked for me. Your mileage may vary. If you fail to cross-compile gdb, then try a slightly newer or older version and try again on your development setup. If you can't build gdb, you can safely skip this step, though you may run into some problems later.
To build gdb, we'll assume you installed the tools to the path from the last post. If you changed path, you'll have to edit the PREFIX path below.
As before, we start out by exporting some environment variables:
The TOPDIR environment variable is the directory in which the sources are stored. The TARGET environment variable is the architecture that we want our compiler to emit code for. For ARM chips without an operating system (like the STM32), we want arm-none-eabi. The PREFIX environment variable is the location we want our cross-compile tools to end up in; feel free to change this to something more suitable. The BUILDPROCS environment variable is the number of processors that we can use; we will use all of them while building to substantially speed up the build process. Finally, we need to add the location of the cross-compile binaries to our PATH so that later building stages can find it.
$ export TOPDIR=~/cross-src $ export TARGET=arm-none-eabi $ export PREFIX=~/opt/cross $ export BUILDPROCS=$( getconf _NPROCESSORS_ONLN ) $ export PATH=$PREFIX/bin:$PATH
Next we'll download, unpack, and build gdb:
We download gdb, unpack it, then configure and build it. The flags to configure deserve some explanation. The --target flag tells gdb what target you want the tools to build for; that is, what kind of code will be emitted by the code. In our case, we want ARM with no operating system. The --prefix flag tells gdb that we want our debugger to be installed to $PREFIX. The --enable-interwork flag allows binutils to emit a combination of ARM and THUMB code; if you don't know what that is, don't worry about it for now. Assuming this step went fine on your development machine, there should be a binary in ~/opt/cross/bin (or whatever your top-level output directory is) called arm-none-eabi-gdb.
$ cd $TOPDIR $ wget ftp://ftp.gnu.org/gnu/gdb/gdb-7.6.tar.gz $ tar -xvf gdb-7.6.tar.gz $ mkdir build-gdb $ cd build-gdb $ ../gdb-7.6/configure --target=$TARGET --prefix=$PREFIX \ --enable-interwork $ make -j$BUILDPROCS $ make install