pyOCD is an open-source Python library and command-line tool for programming and debugging Arm Cortex-M microcontrollers using various debug probes such as CMSIS-DAP, J-Link, and ST-Link. It provides a flexible Python API for low-level target control, suitable for automated testing and CI/CD workflows, alongside a powerful command-line interface for common operations like GDB server, flashing, and erasing. Currently at version 0.44.0, pyOCD maintains an active development cycle with several minor releases annually.
pip install pyocdVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a debug probe, halt the target microcontroller, program a firmware image (HEX format in this example), and then reset and run the target using the pyOCD Python API. Ensure a debug probe is connected and `your_firmware.hex` is replaced with an actual firmware file or created as a dummy for testing.
Upgrade your Python environment to 3.8 or a newer compatible version.
Review the official documentation for the `run` subcommand and update scripts to use the new features and configuration methods, particularly for RTT (`server` mode renamed from `telnet` in v0.44.0) and SystemView.
Adjust custom flash programming scripts to account for the explicit erase/program separation as detailed in the v0.44.0 changelog.
Update any configurations or scripts referencing the `telnet` RTT channel mode to use `server` instead.
While the `0.x` API is stable, be prepared for potential breaking changes when upgrading to version 1.0 and beyond. Refer to the release notes for migration guides.
Install `libusb` according to your operating system's instructions: `brew install libusb` on macOS, usually pre-installed on Linux, and manual DLL placement on Windows (matching Python's architecture).
Add appropriate udev rules for your debug probe to allow unprivileged user access. An example for NXP FRDM-K64F involves creating `/etc/udev/rules.d/50-mbed.rules` with `SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", ATTR{idProduct}=="0204", MODE:="666"`. Check `dmesg` for your device's Vendor/Product IDs.Ensure pyOCD is installed globally or in your virtual environment using `pip install pyocd`, and that your system's PATH includes the directory where Python scripts are installed.
Verify the debug probe is physically connected, ensure specific USB drivers are installed for your probe, and check for udev rules (Linux) or administrative privileges (Windows/macOS) if required.
Install pyOCD using `pip install pyocd` in your active Python environment.
Verify all physical connections to the target, ensure the target is powered correctly, try cycling power to the target, and ensure debug probe firmware is up-to-date.