|
| 1 | +[](https://www.microchip.com) |
| 2 | + |
| 3 | +# pymcuprog - Python MCU programmer |
| 4 | +pymcuprog is a Python utility for programming various Microchip MCU devices using Microchip CMSIS-DAP based debuggers |
| 5 | + |
| 6 | +Install using pip from [pypi](https://pypi.org/project/pymcuprog): |
| 7 | +```bash |
| 8 | +pip install pymcuprog |
| 9 | +``` |
| 10 | + |
| 11 | +Browse source code on [github](https://github.com/microchip-pic-avr-tools/pymcuprog) |
| 12 | + |
| 13 | +Read API documentation on [github](https://microchip-pic-avr-tools.github.io/pymcuprog) |
| 14 | + |
| 15 | +Read the changelog on [github](https://github.com/microchip-pic-avr-tools/pymcuprog/blob/main/CHANGELOG.md) |
| 16 | + |
| 17 | +## Usage |
| 18 | +pymcuprog can be used as a command-line interface or a library |
| 19 | + |
| 20 | +### CLI help |
| 21 | +For more help with using pymcuprog CLI see [help](./help.md) |
| 22 | + |
| 23 | +### CLI examples |
| 24 | +When installed using pip, pymcuprog CLI is located in the Python scripts folder. |
| 25 | + |
| 26 | +Test connectivity by reading the device ID using Curiosity Nano: |
| 27 | +```bash |
| 28 | +pymcuprog ping |
| 29 | +``` |
| 30 | + |
| 31 | +Erase memories then write contents of an Intel(R) hex file to flash using Curiosity Nano (pymcuprog does NOT automatically erase before writing): |
| 32 | +```bash |
| 33 | +pymcuprog erase |
| 34 | +pymcuprog write -f app.hex |
| 35 | +``` |
| 36 | + |
| 37 | +Erase memories and write an Intel hex file (using the --erase switch): |
| 38 | +```bash |
| 39 | +pymcuprog write -f app.hex --erase |
| 40 | +``` |
| 41 | + |
| 42 | +Erase memories, write an Intel hex file and verify the content: |
| 43 | +```bash |
| 44 | +pymcuprog write -f app.hex --erase --verify |
| 45 | +``` |
| 46 | + |
| 47 | + |
| 48 | +### Serial port UPDI (pyupdi) |
| 49 | +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. |
| 50 | + |
| 51 | +<pre> |
| 52 | + Vcc Vcc |
| 53 | + +-+ +-+ |
| 54 | + | | |
| 55 | + +---------------------+ | | +--------------------+ |
| 56 | + | Serial port +-+ +-+ AVR device | |
| 57 | + | | +----------+ | | |
| 58 | + | TX +------+ 1k +---------+ UPDI | |
| 59 | + | | +----------+ | | | |
| 60 | + | | | | | |
| 61 | + | RX +----------------------+ | | |
| 62 | + | | | | |
| 63 | + | +--+ +--+ | |
| 64 | + +---------------------+ | | +--------------------+ |
| 65 | + +-+ +-+ |
| 66 | + GND GND |
| 67 | +</pre> |
| 68 | + |
| 69 | +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. |
| 70 | + |
| 71 | +Example: checks connectivity by reading the device identity |
| 72 | +```bash |
| 73 | +pymcuprog ping -d avr128da48 -t uart -u com35 |
| 74 | +``` |
| 75 | + |
| 76 | +For more examples see [pymcuprog on pypi.org](https://pypi.org/project/pymcuprog/) |
| 77 | + |
| 78 | +### Library usage example |
| 79 | +pymcuprog can be used as a library using its backend API. For example: |
| 80 | +```python |
| 81 | +""" |
| 82 | +Example usage of pymcuprog as a library to read the device ID |
| 83 | +""" |
| 84 | +# pymcuprog uses the Python logging module |
| 85 | +import logging |
| 86 | +logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.WARNING) |
| 87 | + |
| 88 | +# Configure the session |
| 89 | +from pymcuprog.backend import SessionConfig |
| 90 | +sessionconfig = SessionConfig("atmega4808") |
| 91 | + |
| 92 | +# Instantiate USB transport (only 1 tool connected) |
| 93 | +from pymcuprog.toolconnection import ToolUsbHidConnection |
| 94 | +transport = ToolUsbHidConnection() |
| 95 | + |
| 96 | +# Instantiate backend |
| 97 | +from pymcuprog.backend import Backend |
| 98 | +backend = Backend() |
| 99 | + |
| 100 | +# Connect to tool using transport |
| 101 | +backend.connect_to_tool(transport) |
| 102 | + |
| 103 | +# Start the session |
| 104 | +backend.start_session(sessionconfig) |
| 105 | + |
| 106 | +# Read the target device_id |
| 107 | +device_id = backend.read_device_id() |
| 108 | +print ("Device ID is {0:06X}".format(int.from_bytes(device_id, byteorder="little"))) |
| 109 | +``` |
| 110 | + |
| 111 | +## Supported devices and tools |
| 112 | +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. |
| 113 | + |
| 114 | +### Debuggers / Tools |
| 115 | +pymcuprog supports: |
| 116 | +* PKOB nano (nEDBG) - on-board debugger on Curiosity Nano |
| 117 | +* MPLAB PICkit 4 In-Circuit Debugger (when in 'AVR mode') |
| 118 | +* MPLAB Snap In-Circuit Debugger (when in 'AVR mode') |
| 119 | +* Atmel-ICE |
| 120 | +* Power Debugger |
| 121 | +* EDBG - on-board debugger on Xplained Pro/Ultra |
| 122 | +* mEDBG - on-board debugger on Xplained Mini/Nano |
| 123 | +* JTAGICE3 (firmware version 3.0 or newer) |
| 124 | + |
| 125 | +Although not all functionality is provided on all debuggers/boards. See device support section below. |
| 126 | + |
| 127 | +### Devices |
| 128 | +pymcuprog supports: |
| 129 | +* All UPDI devices, whether mounted on kits or standalone |
| 130 | +* PIC devices mounted on Curiosity Nano kits, or similar board with PKOB nano (nEDBG) debugger |
| 131 | + |
| 132 | +Other devices (eg ATmega328P, ATsamd21e18a) may be partially supported for experimental purposes |
| 133 | + |
| 134 | +## Notes for Linux® systems |
| 135 | +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 |
0 commit comments