MultiTech


MultiTech's official mbed team.

debugging mDot MTQ via command line

Introduction

This wiki page will walk you through setting up OpenOCD and debugging a mDot, xDot, or MTQ using GDB. The assumption is the reader is running Ubuntu 14.04. You will need mbed-cli set up before you can compile and debug applications. If you haven't set up mbed-cli, see the mbed-cli documentation.

Debug Symbols Required

Successful debugging requires an application to be built with debug symbols. If using mbed 2.0, include -o debug-info in your workspace_tools/build.py and workspace_tools/make.py commands to build with debug symbols. If using mbed 5.1, include -o debug-info in your mbed compile command to build with debug symbols. If using mbed 5.2, include

--profile mbed-os/tools/profiles/debug.json

in your mbed compile command to build with debug symbols.

Installing OpenOCD 0.9.0

  • Extract the tarball:
tar -xzvf openocd-0.9.0.tar.gz
  • Make and install OpenOCD 0.9.0
cd openocd-0.9.0
configure; make; sudo make install
  • Add your user to the plugdev group
sudo usermod -a -G plugdev <username>
  • Copy udev rules for the debug interfaces
cp /usr/local/share/openocd/contrib/99-openocd.rules to /etc/udev/rules.d/

Configuring OpenOCD 0.9.0

It is possible to start GDB and OpenOCD for the desired platform using a single command. This requires some one-time setup of a few configuration files.

gdb.cfg

By default OpenOCD runs a GDBServer on port 3333. It is also possible to use pipes as the means of communication between OpenOCD and GDB instead. The gdb.cfg file sets this up. The contents of gdb.cfg are below:

gdb_port pipe
log_output openocd.log

$_TARGETNAME configure -event gdb-detach {
    echo "Debugger detaching: resuming execution."
    resume
}

Board Files

OpenOCD needs to know what debug interface is being used (CMSIS-DAP, ST-Link, etc) and which target processor or board is being debugged. The f411re.cfg and l151cc.cfg files give OpenOCD this information by sourcing an interface file and a board file. Because the processor on the mDot and MTQ is a STM32F411RE (like the Nucleo board) and both use ST-Link interface for debugging and programming we can use the same board file. Because the processor on the xDot is a STM32L151CC and it uses the CMSIS-DAP interface, it needs a different board file. The contents of these files are below:

f411re.cfg

source [find interface/stlink-v2.cfg]

source [find board/st_nucleo_f4.cfg]

l151cc.cfg

source [find interface/cmsis-dap.cfg]

source [find target/stm32l1.cfg]

attach.gdb

The final file attach.gdb. This file is the one actually used in the one-liner that starts OpenOCD and GDB and attaches them to the running target. The contents are below:

target remote | openocd -f ./f411re.cfg -f ./gdb.cfg -c "init; halt"
monitor halt
monitor gdb_sync
stepi

Debugging

Now we're ready to debug! GDB needs to read the debug symbols from the .elf that gets built along with the .bin. To start OpenOCD and GDB and sync with the running target, issue the following command:

arm-none-eabi-gdb <full path to .elf> -x attach.gdb

Conclusion

You should now be set up to debug your mDot or MTQ using OpenoCD 0.9.0 and GDB. This link discusses using OpenOCD and GDB together in more detail than I've done here.

Questions can be posted on this wiki page or on the MultiTech developer forums for mDot or MTQ.

Happy debugging!


All wikipages