pymcuprog documentation¶
Python MCU programmer utility¶
pymcuprog is a utility for programming various Microchip MCU devices using Microchip CMSIS-DAP based debuggers
Overview¶
- pymcuprog is available:
install using pip from pypi: https://pypi.org/project/pymcuprog
browse source code on github: https://github.com/microchip-pic-avr-tools/pymcuprog
read API documentation on github: https://microchip-pic-avr-tools.github.io/pymcuprog
read the changelog on github: https://github.com/microchip-pic-avr-tools/pymcuprog/blob/main/CHANGELOG.md
Command-line interface usage¶
For using pymcuprog as a CLI, see help.md (https://github.com/microchip-pic-avr-tools/pymcuprog/blob/main/help.md)
Library usage¶
pymcuprog can be used as a library using its backend API. For example:
# Setup logging - 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
from pymcuprog.backend import Backend
backend = Backend()
# Connect to tool using transport
backend.connect_to_tool(transport)
# Start the session
backend.start_session(sessionconfig)
# Read the target device_id
device_id = backend.read_device_id()
print ("Device ID is {0:06X}".format(int.from_bytes(d, byteorder="little")))
# Print the pymcuprog package version:
from pymcuprog import __version__ as pymcuprog_version
print("pymcuprog version {}".format(pymcuprog_version))
# In addition, the CLI-backend API is versioned for convenience:
print("pymcuprog backend API version: {}".format(backend.get_api_version()))
Logging¶
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)
Dependencies¶
pymcuprog depends on pyedbglib for its transport protocol. pyedbglib requires a USB transport library like libusb. See pyedbglib package for more information.
Supported devices and tools¶
Note: 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.
- The following Atmel/Microchip debuggers are supported:
PKOB nano (nEDBG)
MPLAB PICkit 4 ICD (only when in ‘AVR mode’)
MPLAB Snap ICD (only when in ‘AVR mode’)
Atmel-ICE
Power Debugger
EDBG
mEDBG
JTAGICE3 (only firmware version 3.x)
Although not all functionality is provided on all debuggers/boards. See device support section below.
- The following device-types are supported:
All AVR UPDI devices, whether mounted on kits or standalone
PIC devices mounted on Curiosity Nano kits, or similar board with PKOB nano (nEDBG) debugger
Other devices (eg ATmega328P, ATsamd21e18a) may be partially supported for experimental purposes
- pymcuprog package
- Subpackages
- pymcuprog.deviceinfo package
- pymcuprog.serialupdi package
- Submodules
- pymcuprog.serialupdi.application module
- pymcuprog.serialupdi.constants module
- pymcuprog.serialupdi.link module
- pymcuprog.serialupdi.nvm module
- pymcuprog.serialupdi.nvmp0 module
- pymcuprog.serialupdi.nvmp2 module
- pymcuprog.serialupdi.nvmp3 module
- pymcuprog.serialupdi.physical module
- pymcuprog.serialupdi.readwrite module
- pymcuprog.serialupdi.timeout module
- Module contents
- Submodules
- AVR8 target
AvrDevice
AvrDevice.activate_physical()
AvrDevice.deactivate_physical()
AvrDevice.enter_progmode()
AvrDevice.erase()
AvrDevice.is_blank()
AvrDevice.leave_progmode()
AvrDevice.memory_read()
AvrDevice.memory_write()
AvrDevice.memtype_read_from_string()
AvrDevice.read_memory_section()
AvrDevice.write_memory_section()
MegaAvrJtagTarget
TinyAvrTarget
TinyXAvrTarget
TinyXAvrTarget.activate_physical()
TinyXAvrTarget.breakpoint_clear()
TinyXAvrTarget.breakpoint_set()
TinyXAvrTarget.execute_instruction()
TinyXAvrTarget.execute_patch()
TinyXAvrTarget.memtype_write_from_string()
TinyXAvrTarget.ocdregfile_read()
TinyXAvrTarget.read_device_id()
TinyXAvrTarget.run_with_power_nap()
TinyXAvrTarget.setup_config()
TinyXAvrTarget.setup_debug_session()
TinyXAvrTarget.setup_prog_session()
TinyXAvrTarget.sib_read()
TinyXAvrTarget.stack_pointer_read()
XmegaAvrTarget
- AVR32 target (alpha)
- SAM target (alpha)
SamD2xTarget
SamD2xTarget.CMD_EAR
SamD2xTarget.CMD_LR
SamD2xTarget.CMD_PBC
SamD2xTarget.CMD_UR
SamD2xTarget.CMD_WAP
SamD2xTarget.CMD_WP
SamD2xTarget.DAP_TRANSFER_IDLE_CYCLES
SamD2xTarget.DAP_TRANSFER_MATCH_RETRY
SamD2xTarget.DAP_TRANSFER_RETRY_COUNT
SamD2xTarget.DSU_ADDRESS
SamD2xTarget.DSU_CHIP_ERASE_TIMEOUT_MS
SamD2xTarget.DSU_CTRL_OFFSET
SamD2xTarget.DSU_CTRL_STATUS_CE_COMMAND_MASK
SamD2xTarget.DSU_CTRL_STATUS_DONE_MASK
SamD2xTarget.DSU_CTRL_STATUS_PROT_MASK
SamD2xTarget.DSU_DID_OFFSET
SamD2xTarget.DSU_EXTERNAL_OFFSET
SamD2xTarget.FLASH_LOCK_REGIONS
SamD2xTarget.FLASH_LOCK_REGION_SIZE
SamD2xTarget.NVM_CTRLB_MANW_BIT
SamD2xTarget.NVM_CTRL_ADDRESS
SamD2xTarget.NVM_CTRL_ADDR_OFFSET
SamD2xTarget.NVM_CTRL_CTRLB_OFFSET
SamD2xTarget.NVM_CTRL_CTRL_OFFSET
SamD2xTarget.NVM_CTRL_INTFLAG_OFFSET
SamD2xTarget.NVM_CTRL_LOCK_OFFSET
SamD2xTarget.NVM_CTRL_STATUS_OFFSET
SamD2xTarget.NVM_INT_ERROR_BIT
SamD2xTarget.NVM_INT_READY_BIT
SamD2xTarget.NVM_STATUS_LOCKE
SamD2xTarget.NVM_STATUS_NVME
SamD2xTarget.NVM_STATUS_PROGE
SamD2xTarget.NVM_STATUS_SB
SamD2xTarget.chip_erase_dsu()
SamD2xTarget.connect()
SamD2xTarget.disconnect()
SamD2xTarget.erase_user_row()
SamD2xTarget.is_device_locked()
SamD2xTarget.is_flash_ready()
SamD2xTarget.nvm_command()
SamD2xTarget.post_flash_write()
SamD2xTarget.pre_flash_write()
SamD2xTarget.read_device_id()
SamD2xTarget.read_flash()
SamD2xTarget.read_user_row()
SamD2xTarget.reinitialise()
SamD2xTarget.set_nvmctrl_address()
SamD2xTarget.unlock_all_regions()
SamD2xTarget.wait_flash_ready()
SamD2xTarget.write_flash_page()
SamD2xTarget.write_user_row_word()
SamM4Target
SamTarget
- Backend API (library functions)
Backend
Backend.API_VERSION
Backend.connect_to_tool()
Backend.disconnect_from_tool()
Backend.end_session()
Backend.erase()
Backend.get_api_version()
Backend.get_available_hid_tools()
Backend.get_chiperase_effect()
Backend.get_device_info()
Backend.get_supported_devices()
Backend.hold_in_reset()
Backend.is_isolated_erase_possible()
Backend.read_device_id()
Backend.read_kit_device()
Backend.read_memory()
Backend.read_supply_voltage_setpoint()
Backend.read_target_voltage()
Backend.read_tool_info()
Backend.read_usb_voltage()
Backend.reboot_tool()
Backend.release_from_reset()
Backend.set_supply_voltage_setpoint()
Backend.start_session()
Backend.verify_hex()
Backend.verify_memory()
Backend.write_hex_to_target()
Backend.write_memory()
SessionConfig
- Programmer API
Programmer
Programmer.erase()
Programmer.get_device_memory_info()
Programmer.get_device_model()
Programmer.hold_in_reset()
Programmer.load_device()
Programmer.read_device_id()
Programmer.read_memory()
Programmer.release_from_reset()
Programmer.set_options()
Programmer.setup_device()
Programmer.start()
Programmer.stop()
Programmer.verify_memory()
Programmer.write_memory()
- AVR debugger API (alpha)
AvrDebugger
AvrDebugger.attach()
AvrDebugger.detach()
AvrDebugger.eeprom_read()
AvrDebugger.eeprom_write()
AvrDebugger.flash_read()
AvrDebugger.flush_events()
AvrDebugger.hardware_breakpoint_clear()
AvrDebugger.hardware_breakpoint_set()
AvrDebugger.poll_event()
AvrDebugger.program_counter_read()
AvrDebugger.program_counter_write()
AvrDebugger.register_file_read()
AvrDebugger.register_file_write()
AvrDebugger.reset()
AvrDebugger.run()
AvrDebugger.run_to()
AvrDebugger.setup_session()
AvrDebugger.software_breakpoint_clear()
AvrDebugger.software_breakpoint_clear_all()
AvrDebugger.software_breakpoint_set()
AvrDebugger.sram_read()
AvrDebugger.sram_write()
AvrDebugger.stack_pointer_read()
AvrDebugger.start_debugging()
AvrDebugger.status_register_read()
AvrDebugger.step()
AvrDebugger.stop()
AvrDebugger.stop_debugging()
- NVM Access (implementations)
- NVM implementation: UPDI
NvmAccessProviderCmsisDapUpdi
NvmAccessProviderCmsisDapUpdi.erase()
NvmAccessProviderCmsisDapUpdi.hold_in_reset()
NvmAccessProviderCmsisDapUpdi.read()
NvmAccessProviderCmsisDapUpdi.read_device_id()
NvmAccessProviderCmsisDapUpdi.release_from_reset()
NvmAccessProviderCmsisDapUpdi.start()
NvmAccessProviderCmsisDapUpdi.stop()
NvmAccessProviderCmsisDapUpdi.write()
- NVM implementation: serialUPDI
- NVM implementation: PIC
- NVM implementation: SAM M0+ (alpha)
- NVM implementation: debugWIRE (alpha)
- NVM implementation: SPI (alpha)
- NVM implementation: TPI (alpha)
- NVM implementation: megaAVR (JTAG) - (alpha)
- NVM implementation: XMEGA (alpha)
- NVM implementation: AVR32 (alpha)
- Utilities
- Hex file utilities
- Tool connections
- pymcuprog errors
PymcuprogDeviceLockedError
PymcuprogEraseError
PymcuprogError
PymcuprogNotSupportedError
PymcuprogSerialUpdiError
PymcuprogSerialUpdiLockedError
PymcuprogSerialUpdiNvmError
PymcuprogSerialUpdiNvmTimeout
PymcuprogSerialUpdiProtocolError
PymcuprogSessionConfigError
PymcuprogSessionError
PymcuprogTargetVoltageError
PymcuprogToolConfigurationError
PymcuprogToolConnectionError
- Module contents
- Subpackages