Using Pitaya-Link with pyOCD


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 Pitaya-Link. For more detailed information, refer to the pyOCD GitHub repository.

What you'll need


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

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


The flash programming may be the most frequently used option of Pitya-Link. pyOCD offers a variety of commands for programming with different options. You can get additional help by running:

pyocd erase --help
pyocd flash --help

The following commands demonstrate how to flash/erase an nRF52840-based target:

  • To erase all of the target flash:

    pyocd erase -t nrf52840 --chip

  • To flash the target with .hex-format firmware:

    pyocd flash -t nrf52840 Sample.hex

  • To flash the target with a plain binary:

    pyocd flash -t nrf52840 --base-address 0x1000 Sample.bin


    The --base-address option is used for setting the address where to flash a binary. Defaults to start of flash.


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: