Skip to content

Debugging with pyOCD

Overview

pyOCD is an open source Python package for programming and debugging Arm Cortex-M microcontrollers using multiple supported types of USB debug probes. It is fully cross-platform, with support for Linux, macOS, and Windows.

A command line tool is provided that covers most use cases, or you can make use of the Python API to enable low-level target control. A common use for the Python API is to run and control CI tests.

Upwards of 70 popular MCUs are supported built-in. In addition, through the use of CMSIS-Packs, nearly every Cortex-M device on the market is supported.

This guide demonstrates the basic usage of pyOCD with M.2 Dock. For more detailed information, refer to the pyOCD GitHub repository.

What you'll need

Installing

The latest stable version of pyOCD may be installed via pip as follows:

pip install -U pyocd

Alternatively, to install the latest prerelease version from the HEAD of the master branch, you can do the following:

pip install --pre -U https://github.com/mbedmicro/pyOCD/archive/master.zip

Basic Usage

The pyocd command line tool gives you total control over your target with these subcommands:

  • gdbserver: GDB remote server allows you to debug using gdb via either GNU MCU Eclipse plug-in or the console.
  • flash: Program files of various formats into flash memory.
  • erase: Erase part or all of an MCU's flash memory.
  • pack: Manage CMSIS Device Family Packs that provide additional target device support.
  • commander: Interactive REPL control and inspection of the MCU.
  • list: Show connected devices.

Target support

When pyOCD connects to a target, it needs to know what type of target it is controlling. To see the available target types you can run:

pyocd list --targets

Debugging

pyOCD contains a GDB remote server which allows you to debug using gdb. You can get additional help by running: pyocd gdbserver --help.

You will be able to execute the following in order to start a GDB server:

pyocd gdbserver -t nrf52840

In the second terminal window, connect to the GDB server and load firmware by running:

$ arm-none-eabi-gdb application.elf

<gdb> target remote localhost:3333
<gdb> load
<gdb> monitor reset

The GDB server also works well with Eclipse and the GNU MCU Eclipse plug-ins. GNU MCU Eclipse fully supports pyOCD with an included pyOCD debugging plugin.

For instructions on GNU MCU Eclipse for pyOCD, please refer to:

Create an Issue

Interested in contributing to this project? Want to report a bug? Feel free to click here: