Debugging from GDB using pyOCD!

We are pleased to release a python library which allows to drive the Debug Access Port of Cortex-M microcontrollers over CMSIS-DAP!

What can be achieved with pyOCD?

  • Debugging using GDB, as a gdbserver is integrated on the library
  • Writing python applications that can communicate with the CMSIS-DAP and coresight debug interface:
    • read/write memory
    • read/write core registers
    • set breakpoints
    • flash new binary
    • run/stop/step the execution
  • Act as a great reference to show how the CMSIS-DAP protocol works

Currently, the library works on Windows (using pyWinUSB as backend) and on Linux (using pyUSB as backend).

Quick overview

Use python to control your mbed platform

from pyOCD.board import MbedBoard

board = MbedBoard.chooseBoard()

target =
flash = board.flash

print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0xA64

print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0xA30


print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0x10000000

print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0xAAC


Use GDB to debug your mbed projects

Before using GDB, a .elf file has to be generated with a GCC toolchain.

  • Python code to start a GDB server on port 3333

from pyOCD.gdbserver import GDBServer
from pyOCD.board import MbedBoard

board = MbedBoard.chooseBoard()

# start gdbserver on port 3333
gdb = GDBServer(board, 3333)
  • Debug the target from GDB:

arm-none-eabi-gdb l1_lpc1768.elf

<gdb> target remote localhost:3333
<gdb> load
<gdb> continue

Get Started

All the source code is available on our git repository under workspace_tools/debugger

You can quickly get started with pyOCD by reading the README. It provides all the information that you need to know concerning the dependencies, installation and how to use the library. There are even some sample programs to get started even quicker!


pyOCD provides a simple and efficient solution to debug mbed platforms over CMSIS-DAP.

We expect quite soon the support of all the mbed platforms in OpenOCD as well. There is even a fork of OpenOCD adding CMSIS-DAP support: cmsis-dap support in OpenOCD

Have fun with pyOCD!

9 comments on Debugging from GDB using pyOCD!:

10 Apr 2013

@Samuel Thanks for amazing works!! Many people asked me about CMSIS-DAP with gdb at Maker Faire Shenzhen. If I knew this, I could say "YES!!".

Why not supprting OS X? Is this because technical difficulties of HID handling on OS X?

16 Apr 2013

@Samuel, thanks for your good product.

@ytsuboi, as you know, it's hard to support OSX because of technical issues around HID. I've not tried but probably it can support also OSX by preparing the another transport based on HIDAPI. I'll hack it on first of May if no one try.

18 Apr 2013

Brilliant ! Thanks You very much for building this.

Are you planning on doing a video of the mbed with the DDD debugger ? If it works i think it could raise a lot of interest in the embedded community.

04 May 2013

@Samuel: While I was trying out pyOCD, I found a bug in If there are more than 1 usb device (apart from the mbed) connected to the host computer, then inside the function getAllConnectedInterface, not all the non-mbed usb devices will be removed from the all_devices list because when device is removed, the index of items change and the iteration skips the next device it wants to remove. Hence, this will not remove a non-mbed device:

  #keep devices with good vid/pid
  for d in all_devices:
      if (d.vendor_id != vid) or (d.product_id != pid):
          all_devices.remove(d) #this will cause the next item's index to decrement and gets skipped

I fixed this by using a temporary list temp_devices to remove the devices from it while iterating over all_devices, and then pointing all_devices to temp_devices after removal:

#keep devices with good vid/pid
        for d in all_devices:
            if (d.vendor_id != vid) or (d.product_id != pid):
        if not all_devices:
            logging.debug("No Mbed device connected")
        all_devices = list(temp_devices)

Other than that, pyOCD works great!

Timothy Teh

10 Sep 2013

I've used the python PyOCD gdb proxy. After uploading a file the KL25Z didn't react any more. Nothing, not even the MBED drive appears. I've tried to reflash the mbed_if_v2.0_frdm_kl25z.s19 File from windows: still dead. Unfortunately that happened to two (!) KL25Z of mine. So how can I get it alive again?

26 Nov 2013

I've got some very draft support for using pyOCD to target stm32 via the stlinkv2 transport at

There's a few impedance mismatches between mbed and stm32, but pyOCD is a much nicer smaller codebase to work with for flashing and gdb service than openocd!

29 Dec 2013

So, erm, the github repo link needs updating to, then? Or... ?

08 Mar 2014

If you want to use pyOCD on a linux system you need to add udev rules to set the permissions to allow users to access the USB device.

On ubuntu 12.04 I did the following:

Created /etc/udev/rules.d/mbed.rules with the content

SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", ATTR{idProduct}=="0204", MODE:="666"

Then I restarted udev

sudo udevadm trigger
22 Mar 2014

I am pretty ignorant when it comes to python, but I get this error on Win7 32 bit. I have tried a few different CMSIS-DAP devices and it doesn't look like it is finding them.

INFO:root:Waiting for a USB device connected

Please log in to start a discussion or ask a question.

Discussion topics

TopicRepliesLast post
Pyocd gdbserver error: No available boards are connected 1 26 May 2016 by Tim H