pyOCD is another piece of software we can use on our PC to program microcontrollers using a cmsis-dap tool. It is also a debugging tool, meaning we can setup an IDE to use breakpoints / etc when it is connected to the board we are programming.

This one is built in python, hence the name: so it has a python API that I am sure is useful when i.e. automating bootloader-loading, etc.

  1. pyOCD
  2. Installing
  3. Setup / Config
  4. Basic Use


The project’s install documentation is better than mine, you can read it here to complete this step.

I (on windows) had to install python, visualstudio, and had to make sure python was on my PATH so that I could invoke it from the command prompt. I also had to add the pyocd scripts to my PATH, they were located at c\users\<username>\appdata\roaming\python39\scripts.

Setup / Config

pyOCD comes out of the box with support for a bunch of microcontrollers, but not the SAMD11, D21 and D51 series. Target support is managed well in pyOCD but I couldn’t find my chips with their ‘target find’ tools, so I just downloaded them myself.

Downloads for Atmel Chips are at, you can ctrl+f for D21 etc and get the most recent. Importantly you need to rename the .atpack to .pack - don’t ask my why microchip is trying to use different file extensions than anyone else.

To point pyOCD at these packs, they have a great little yaml config tool. I made a new folder this exercise, and added a pyocd.yaml file there, which simply includes this:

  - Microchip.SAMD51_DFP.3.3.76.pack
  - Microchip.SAMD21_DFP.3.3.98.pack

That points pyOCD at these files (which are also in the folder) so that anytime I call a pyOCD script from this folder, it uses this config. Rad. I included that folder in this repo.

Basic Use

Open a terminal to the folder where you have the pyocd.yaml file, and throw the .bin binary file you’d like to flash in there as well.

To verify that pyOCD is available, do

pyocd -v

You should see the version you’ve installed appear. Now you can do the magic:

  • connect the cmsis-dap tool to your circuit
  • connect the cmsis-dap tool to your computer
  • make sure the circuit has power (cmsis-dap tools detect voltage, they don’t provide it)
  • open a terminal / command prompt / etc in the pyOCD folder with your config and hex file in it
  • run pyocd flash -t <your target> <your .hex or .bin>
  • i.e. pyocd flash -t atsamd51j19a bootloader-feather_m4-v3.10.0.bin

To find your target name (against all available targets) you can do pyocd list --targets