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, 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")))
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
Contents:
- 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
AvrDeviceAvrDevice.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()
MegaAvrJtagTargetTinyAvrTargetTinyXAvrTargetTinyXAvrTarget.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)
SamD2xTargetSamD2xTarget.CMD_EARSamD2xTarget.CMD_LRSamD2xTarget.CMD_PBCSamD2xTarget.CMD_URSamD2xTarget.CMD_WAPSamD2xTarget.CMD_WPSamD2xTarget.DAP_TRANSFER_IDLE_CYCLESSamD2xTarget.DAP_TRANSFER_MATCH_RETRYSamD2xTarget.DAP_TRANSFER_RETRY_COUNTSamD2xTarget.DSU_ADDRESSSamD2xTarget.DSU_CHIP_ERASE_TIMEOUT_MSSamD2xTarget.DSU_CTRL_OFFSETSamD2xTarget.DSU_CTRL_STATUS_CE_COMMAND_MASKSamD2xTarget.DSU_CTRL_STATUS_DONE_MASKSamD2xTarget.DSU_CTRL_STATUS_PROT_MASKSamD2xTarget.DSU_DID_OFFSETSamD2xTarget.DSU_EXTERNAL_OFFSETSamD2xTarget.FLASH_LOCK_REGIONSSamD2xTarget.FLASH_LOCK_REGION_SIZESamD2xTarget.NVM_CTRLB_MANW_BITSamD2xTarget.NVM_CTRL_ADDRESSSamD2xTarget.NVM_CTRL_ADDR_OFFSETSamD2xTarget.NVM_CTRL_CTRLB_OFFSETSamD2xTarget.NVM_CTRL_CTRL_OFFSETSamD2xTarget.NVM_CTRL_INTFLAG_OFFSETSamD2xTarget.NVM_CTRL_LOCK_OFFSETSamD2xTarget.NVM_CTRL_STATUS_OFFSETSamD2xTarget.NVM_INT_ERROR_BITSamD2xTarget.NVM_INT_READY_BITSamD2xTarget.NVM_STATUS_LOCKESamD2xTarget.NVM_STATUS_NVMESamD2xTarget.NVM_STATUS_PROGESamD2xTarget.NVM_STATUS_SBSamD2xTarget.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()
SamM4TargetSamTarget
- Backend API (library functions)
BackendBackend.API_VERSIONBackend.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
ProgrammerProgrammer.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)
AvrDebuggerAvrDebugger.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
NvmAccessProviderCmsisDapUpdiNvmAccessProviderCmsisDapUpdi.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
PymcuprogDeviceLockedErrorPymcuprogEraseErrorPymcuprogErrorPymcuprogNotSupportedErrorPymcuprogSerialUpdiErrorPymcuprogSerialUpdiLockedErrorPymcuprogSerialUpdiNvmErrorPymcuprogSerialUpdiNvmTimeoutPymcuprogSerialUpdiProtocolErrorPymcuprogSessionConfigErrorPymcuprogSessionErrorPymcuprogTargetVoltageErrorPymcuprogToolConfigurationErrorPymcuprogToolConnectionError
- Module contents
- Subpackages