Debugging Embedded projects with PyOCD

This tutorial shows how to debug embedded projects using the PyOCD tool and VisualGDB. PyOCD is significantly less functional than OpenOCD, however it is better integrated with mbed-specific boards, so we recommend using it as a fallback if OpenOCD doesn’t work with your board. Before you begin, install VisualGDB 5.3 or later.

  1. Download and install Python 2.7 for Windows. Then open a command-line Python prompt and install PyOCD by running “pip install pyocd”:01-get
  2. You can quickly check that PyOCD works by connecting your board to the USB port and running “pyocd-gdbserver -t <target name>”:
    02-pyocd
  3. Now we will create a project with VisualGDB. Start Visual Studio and select the VisualGDB Embedded Project Wizard:03-prj
  4. Select “Create a new project with MSBuild -> Embedded Binary”:04-msb
  5. As PyOCD is typically used with mbed-based projects, we will demonstrate its use for the LPC812 mbed/Xpresso board, however any other board supported by PyOCD will work as well.  Select “use ARM mbed” and pick your board in the list:
    05-device
  6. On the next page proceed with the default “LEDBlink” example:06-sample
  7. On the last page of the wizard switch to “Debug Methods” instead of “USB Devices” and locate “PyOCD there”. If it is not shown, click the download button and install the PyOCD package:
    07-methods
  8. Once PyOCD is selected, specify the full path to the pyocd-gdbserver.exe executable (normally located in the <Python>\scripts directory) and choose your target:
    08-targetNote that as PyOCD support is more basic compared to OpenOCD, so it won’t automatically recognize/fix driver issues and won’t support live variables, profiling and other features that require background memory reads.
  9. Press “Finish” to create the project. Build it with Ctrl-Shift-B:09-build
  10. Now you can set a breakpoint in main() and press F5 to start debugging. Your breakpoint will hit as soon as the code reaches that point:10-step
  11. The PyOCD output will be displayed in the “VisualGDB Program Output” pane, so you can use it to diagnose PyOCD issues.11-output