Install pyOCD on Raspberry Pi

Installing pyOCD on Raspberry Pi turned out to be a bit more complicated than a simple pip install. The main problem is that pyOCD depend on cmsis-pack-manager but there is no wheel available for Raspberry Pi and the package can't be compiled without running out of memory. It is described in the documentation and a simple fix is also suggested. The problem is that the fix didn't work for me. Instead this is what worked for me:

Custom build pyOCD with cmsis-pack-manager removed

Install build package on system python on the Raspberry Pi

$ python -m pip install build

Clone pyocd source and checkout the version you need

$ git clone
$ git checkout tags/v0.33.1

Remove cmsis-pack-manager from dependencies in setup.cfg. It is one line under the install_requires option.

From the root folder of the pyOCD source build pyOCD with

$ python -m build --sdist

The build is saved as a .tar.gz file in the dist directory. You need the path to the .tar.gz in the next step.

Pip install custom built package and patch missing type

Create and activate a virtual environment and install your custom pyocd package

$ python -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -m pip install [path_to_local_pyocd_dist_tar_gz]

If you try to run pyocd now you get an error about a missing object. Patch the missing type in .venv/lib/python3.X/site-packages/pyocd/target/pack/ Add this to the start of

class Mock:
    class Cache:

cmsis_pack_manager = Mock()

Update: It seems that a better solution is to add

from __future__ import annotations

as the first line in instead of monkey-patching cmsis_pack_manager. Found here:

Copy udev rules for your debugger and download pack for mcu

pyOCD is now installed and ready to run. I am using an Atmel ICE debugger and to get access to it I had to copy some udev rules from the pyocd source and restart udev

$ cp <pyocd_source>/udev/50-cmsis-dap.rules /etc/udev/rules.d/
$ sudo udevadm control --reload
$ sudo udevadm trigger

Also since pyOCD is built without the cmsis-pack-manager you have to manually download the correct pack for your board which you can find here ( You can read more about manually installing packs here.

I am working on an SAMD21J17A from Microchip so I downloaded the corresponding pack

$ wget

And the last step is to create a pyocd config file (pyocd.yaml) that points to the downloaded pack

  - <abs_path_to_pack_file>

Ready to flash

Finally you are ready to flash

(.venv) $ python -m pyocd reset -t atsamd21j17a --frequency 400khz --method hw
(.venv) $ python -m pyocd flash -t atsamd21j17a --frequency 400khz [file_to_flash]