
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
pymcuprog is a utility for programming various Microchip MCU devices using Microchip CMSIS-DAP based debuggers
pymcuprog is available:
pymcuprog can be used as a command-line interface or a library
for help, use:
pymcuprog --help
checks connectivity by reading the device identity
Example:
pymcuprog ping
erases device memories
Example: chip erase the device
pymcuprog erase
writes device memories
Example: writes the content of an Intel® hex file to the appropriate memory areas on the device
pymcuprog write -f app.hex
Note: memory is not erased automatically before writing!
Example: erases memories and then writes an Intel hex file:
pymcuprog write -f app.hex --erase
Example: erases memories, writes an Intel hex file and then verifies the content:
pymcuprog write -f app.hex --erase --verify
reads device memories
Example: reads 64 bytes of flash memory from offset 0x1000
pymcuprog read -m flash -o 0x1000 -b 64
resets the target device
Example:
pymcuprog reset
reads the actual target operating voltage
Example:
pymcuprog getvoltage
reads the supply voltage (set-point)
Example:
pymcuprog getsupplyvoltage
reads the USB voltage (Vbus)
Example:
pymcuprog getusbvoltage
sets the target supply voltage
Example: sets the target supply voltage on a Curiosity Nano kit to 3.3V
pymcuprog setsupplyvoltage -l 3.3
reboots the debugger
Example: reboots a Curiosity Nano kit
pymcuprog reboot-debugger
converts Intel hex file to UF2 file
Example: converts myfile.hex to newfile.uf2
pymcuprog makeuf2 -f myfile.hex --uf2file newfile.uf2
The --uf2file argument is optional. By default pymcuprog will generate a UF2 file with the same name as the hex but with .uf2 extension.
Many of these switches are optional, and many parameters are automatically set when using a Curiosity Nano or Xplained Pro kit.
*Notes regarding PACKPATH argument
While pymcuprog itself contains sufficient information to program AVR devices (with UPDI interface), it is unable to program a PIC device without access to programming scripts for that device. These scripts are deployed in Device Family Packs (DFP) on https://packs.download.microchip.com and are only provided for PIC devices mounted on Curiosity Nano boards or other boards with the PKOB nano (nEDBG) debugger. To use pymcuprog with PIC devices, you will either need to download a DFP for the PIC in question, or have MPLAB X v5.25 or later installed. In either case the path to the particular device in the scripts folder inside the DFP must be passed into pymcuprog using the -p PACKPATH argument. Remember to quote the path ("<path>"
) if the path itself contains spaces.
NOTE FOR WINDOWS USERS: Avoid ending a quoted "<path>"
argument with a backslash ('\'
), this will cause the PACKPATH to not be found. "C:\foo\bar"
will work, while "C:\foo\bar\"
will not.
Example: Ping the device on a PIC16F15244 Curiosity Nano
pymcuprog ping -p "c:\Program Files (x86)\Microchip\MPLABX\v5.40\packs\Microchip\PIC16F1xxxx_DFP\1.4.119\scripts\pic16f15244"
The AVR UPDI interface implements a UART protocol, which means that it can be used by simply connecting TX and RX pins of a serial port together with the UPDI pin; with a series resistor (eg: 1k) between TX and UPDI to handle contention. (This configuration is also known as "pyupdi".) Be sure to connect a common ground, and use a TTL serial adapter running at the same voltage as the AVR device.
Vcc Vcc +-+ +-+ | | +---------------------+ | | +--------------------+ | Serial port +-+ +-+ AVR device | | | +----------+ | | | TX +------+ 1k +---------+ UPDI | | | +----------+ | | | | | | | | | RX +----------------------+ | | | | | | | +--+ +--+ | +---------------------+ | | +--------------------+ +-+ +-+ GND GND
pymcuprog includes this implementation as an alternative to USB/EDBG-based tools. To connect via a serial port, use the "uart" tool type with the UART switch in addition.
Example: checks connectivity by reading the device identity
pymcuprog ping -d avr128da48 -t uart -u com35
When using serial port UPDI it is optional to use:
Increasing the baud rate can decrease programming time. Decreasing the timeout can decrease the initial connection latency when UPDI is disabled and does not respond. These parameters can be tweaked to suit the serial port adapter in use.
pymcuprog can be used as a library using its backend API. For example:
# pymcuprog uses the Python logging module
import logging
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.WARNING)
# Configure the session
from pymcuprog.backend import SessionConfig
sessionconfig = SessionConfig("atmega4808")
# Instantiate USB transport (only 1 tool connected)
from pymcuprog.toolconnection import ToolUsbHidConnection
transport = ToolUsbHidConnection()
# Instantiate backend, connect to tool using transport, start session using sessionconfig
#
# The Backend constructor arguments `transport' and `sessionconfig' are optional,
# setting them will cause backend.connect_to_tool() and backend.start_session() respectively
# to be called during construction. Connection and session will be automatically
# torn down when backend object goes out of scope at end of with-block.
#
from pymcuprog.backend import Backend
with Backend(transport, sessionconfig) as backend:
# Read the target device_id
device_id = backend.read_device_id()
print("Device ID is {0:06X}".format(int.from_bytes(device_id, byteorder="little")))
This package uses the Python logging module for publishing log messages to library users. A basic configuration can be used (see example), but for best results a more thorough configuration is recommended in order to control the verbosity of output from dependencies in the stack which also use logging. See logging.yaml which is included in the package (although only used for CLI)
pymcuprog depends on pyedbglib for its transport protocol. pyedbglib requires a USB transport library like libusb. See pyedbglib package for more information.
pymcuprog version can be determined using the CLI:
pymcuprog -V
or using the library:
from pymcuprog import __version__ as pymcuprog_version
print("pymcuprog version {}".format(pymcuprog_version))
In addition, the CLI-backend API is versioned for convenience:
from pymcuprog.backend import Backend
backend = Backend()
print("pymcuprog backend API version: {}".format(backend.get_api_version()))
pymcuprog is primarily intended for use with PKOB nano (nEDBG) debuggers which are found on Curiosity Nano kits and other development boards. This means that it is continuously tested with a selection of AVR devices with UPDI interface as well as a selection of PIC devices. However since the protocol is compatible between all EDBG-based debuggers (pyedbglib) it is possible to use pymcuprog with a wide range of debuggers and devices, although not all device families/interfaces have been implemented.
pymcuprog supports:
Although not all functionality is provided on all debuggers/boards. See device support section below.
pymcuprog supports:
Other devices (eg ATmega328P, ATsamd21e18a) may be partially supported for experimental purposes
This package uses pyedbglib and other libraries for USB transport and some udev rules are required. For details see the pyedbglib package: https://pypi.org/project/pyedbglib
with Backend(...) as ...
block)FAQs
Tools for programming of MCUs using Microchip CMSIS-DAP based debuggers
We found that pymcuprog demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.