{"id":26679981,"url":"https://github.com/wagiminator/mcu-flash-tools","last_synced_at":"2025-04-09T08:08:04.645Z","repository":{"id":192407581,"uuid":"686668744","full_name":"wagiminator/MCU-Flash-Tools","owner":"wagiminator","description":"Simple ISP Flash Tools for various Microcontrollers","archived":false,"fork":false,"pushed_at":"2025-01-05T09:53:53.000Z","size":107,"stargazers_count":83,"open_issues_count":5,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T07:07:28.520Z","etag":null,"topics":["attiny","ch32v003","ch32v203","ch32x035","ch552","ch559","ch55x","flash","isp","programmer","py32f002a","stc8","stm32g030","tinyavr"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wagiminator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-03T15:04:18.000Z","updated_at":"2025-03-20T18:47:27.000Z","dependencies_parsed_at":"2023-10-04T21:37:40.739Z","dependency_job_id":"5b5297e2-828e-43ce-809c-e8ae7f2e9fd8","html_url":"https://github.com/wagiminator/MCU-Flash-Tools","commit_stats":null,"previous_names":["wagiminator/mcu-flash-tools"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagiminator%2FMCU-Flash-Tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagiminator%2FMCU-Flash-Tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagiminator%2FMCU-Flash-Tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagiminator%2FMCU-Flash-Tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wagiminator","download_url":"https://codeload.github.com/wagiminator/MCU-Flash-Tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999859,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attiny","ch32v003","ch32v203","ch32x035","ch552","ch559","ch55x","flash","isp","programmer","py32f002a","stc8","stm32g030","tinyavr"],"created_at":"2025-03-26T06:19:30.273Z","updated_at":"2025-04-09T08:08:04.625Z","avatar_url":"https://github.com/wagiminator.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MCU ISP Flash Tools\nThis is a compilation of straightforward In-System Programming (ISP) flash tools for different microcontrollers, all written as individual Python scripts. Their single-script format makes them incredibly easy to integrate into any toolchain. Furthermore, these tools can also be installed via pip and then executed as command-line commands.\n\n- [chprog.py - Flashing CH5xx, CH32Fxxx, CH32Vxxx, CH32Xxxx via embedded USB bootloader](#chprog)\n- [rvprog.py - Flashing CH32Vxxx with WCH-LinkE via serial debug interface](#rvprog)\n- [puyaisp.py - Flashing PY32F0xx with USB-to-serial converter via embedded UART bootloader](#puyaisp)\n- [stc8isp.py - Flashing STC8G/8H with USB-to-serial converter via embedded UART bootloader](#stc8isp)\n- [stc8usb.py - Flashing STC8H8KxxU via embedded USB bootloader](#stc8usb)\n- [stm32isp.py - Flashing entry-level STM32 with USB-to-serial converter via embedded UART bootloader](#stm32isp)\n- [tinyupdi.py - Flashing tinyAVR with USB-to-serial converter via UPDI](#tinyupdi)\n\nIn order for these tools to work, Python3 must be installed on your system. To do this, follow these [instructions](https://www.pythontutorial.net/getting-started/install-python/). In addition [PyUSB](https://github.com/pyusb/pyusb), [PySerial](https://github.com/pyserial/pyserial) and [pyhidapi](https://pypi.org/project/hid/) must be installed. On Linux (Debian-based), all of this can be done with the following commands:\n\n```\nsudo apt install python3 python3-pip\npip install pyusb pyserial hid\n```\n\nWindows users in particular may also need to install [libusb](https://github.com/libusb/libusb).\n\n## chprog\n### Description\nWith this tool, almost all WCH microcontrollers (CH5xx, CH6xx, CH32Fxxx, CH32Vxxx, CH32Xxxx, and CH32Lxxx) which have a factory-builtin bootloader (v2.x.x) can be flashed via USB.\n\n### Preparations\nOn Linux you do not need to install a driver for the USB bootloader. However, by default Linux will not expose enough permission to upload your code. In order to fix this, open a terminal and run the following commands:\n\n```\necho 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"4348\", ATTR{idProduct}==\"55e0\", MODE=\"666\"' | sudo tee /etc/udev/rules.d/99-ch55x.rules\necho 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"1a86\", ATTR{idProduct}==\"55e0\", MODE=\"666\"' | sudo tee -a /etc/udev/rules.d/99-ch55x.rules\nsudo udevadm control --reload-rules\n```\n\nFor Windows, you need the [CH372 driver](http://www.wch-ic.com/downloads/CH372DRV_EXE.html). Alternatively, you can also use the [Zadig](https://zadig.akeo.ie/) tool to install the correct driver. Here, click \"Options\" -\u003e \"List All Devices\" and select the USB module. Then install the libusb-win32 driver. To do this, the board must be connected and the microcontroller must be in bootloader mode.\n\n### Usage as a Script\nThe bootloader must be started manually for new uploads. To do this, the board must first be disconnected from the USB port and all voltage sources. Now press the BOOT button and keep it pressed while reconnecting the board to the USB port of your PC. The chip now starts in bootloader mode, the BOOT button can be released and new firmware can be uploaded via USB. Alternatively, you can leave the board connected to the USB port, press and hold the BOOT button, press and release the RESET button and then release the BOOT button to enter the bootloader mode. If there is no BOOT button on the board, look at the datasheet to find out which pin needs to be pulled to which voltage level for the microcontroller to go into boot mode.\n\nNow run the following command (example):\n```\npython3 chprog.py firmware.bin\n```\n\n### Installation via pip\nTake a look [here](https://pypi.org/project/chprog/).\n\n## rvprog\n### Description\nWith this tool, the WCH RISC-V microcontrollers CH32Lxxx, CH32Vxxx, and CH32Xxxx can be programmed with the [WCH-LinkE or WCH-LinkW](http://www.wch-ic.com/products/WCH-Link.html) (pay attention to the \"E\" or \"W\" in the name) via its serial debug interface.\n\n### Preparations\nTo use the WCH-Link on Linux, you need to grant access permissions beforehand by executing the following commands:\n```\necho 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"1a86\", ATTR{idProduct}==\"8010\", MODE=\"666\"' | sudo tee /etc/udev/rules.d/99-WCH-LinkE.rules\necho 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"1a86\", ATTR{idProduct}==\"8012\", MODE=\"666\"' | sudo tee -a /etc/udev/rules.d/99-WCH-LinkE.rules\nsudo udevadm control --reload-rules\n```\n\nOn Windows, if you need to you can install the WinUSB driver over the WCH interface 1 using the [Zadig](https://zadig.akeo.ie/) tool.\n\n### Usage as a Script\nTo upload firmware, you should make the following connections to the WCH-Link (SWCLK is not present on CH32V00x and therefore does not need to be connected):\n\n```\nWCH-Link      RISC-V MCU\n+------+      +--------+\n| SWCLK| ---\u003e |SWCLK   |\n| SWDIO| \u003c--\u003e |SWDIO   |\n|   GND| ---\u003e |GND     |\n|   3V3| ---\u003e |VDD     |\n+------+      +--------+\n```\n\nIf the blue LED on the WCH-Link remains illuminated once it is connected to the USB port, it means that the device is currently in ARM mode and must be switched to RISC-V mode initially. There are a few ways to accomplish this:\n- You can utilize the rvprog tool with the -v option (see below).\n- Alternatively, you can select \"WCH-LinkRV\" in the software provided by WCH, such as MounRiver Studio or WCH-LinkUtility.\n- Another option is to hold down the ModeS button on the device while plugging it into the USB port.\n\nMore information can be found in the [WCH-Link User Manual](http://www.wch-ic.com/downloads/WCH-LinkUserManual_PDF.html).\n\n```\nUsage: rvprog.py [-h] [-a] [-v] [-b] [-u] [-l] [-e] [-G] [-R] [-f FLASH]\n\nOptional arguments:\n  -h, --help                show help message and exit\n  -a, --armmode             switch WCH-Link to ARM mode\n  -v, --rvmode              switch WCH-Link to RISC-V mode\n  -b, --unbrick             unbrick chip (power cycle erase)\n  -u, --unlock              unlock chip (remove read protection)\n  -l, --lock                lock chip (set read protection)\n  -e, --erase               perform a whole chip erase\n  -G, --pingpio             make PD7 a GPIO pin (CH32V00x only)\n  -R, --pinreset            make PD7 a reset pin (CH32V00x only)\n  -f FLASH, --flash FLASH   write BIN file to flash\n\nExample:\npython3 rvprog.py -f firmware.bin\n```\n\n### Installation via pip\nTake a look [here](https://pypi.org/project/rvprog/).\n\n## puyaisp\n### Description\nWith this tool, PUYA microcontrollers of the series PY32F0xx (and maybe other PY32) can be flashed via a simple USB-to-serial converter by utilizing the factory built-in embedded UART bootloader.\n\n### Preparations\nIf necessary, a driver for the USB-to-serial converter used must be installed.\n\n### Usage as a Script\nConnect your USB-to-serial converter to your PY32F0xx MCU as follows:\n\n```\nUSB2SERIAL            PY32F0xx\n+--------+      +-------------------+\n|     RXD| \u003c--- |PA2 or PA9  or PA14|\n|     TXD| ---\u003e |PA3 or PA10 or PA15|\n|     VDD| ---\u003e |VDD                |\n|     GND| ---\u003e |GND                |\n+--------+      +-------------------+\n```\n\nSet your MCU to bootloader mode by using ONE of the following methods:\n- Disconnect your USB-to-serial converter, pull BOOT0 pin (PF4) to VCC (or press and hold the BOOT button, if your board has one), then connect the converter to your USB port. BOOT0 pin (or BOOT button) can be released now.\n- Connect your USB-to-serial converter to your USB port. Pull BOOT0 pin (PF4) to VCC, then pull nRST (PF2) shortly to GND (or press and hold the BOOT button, then press and release the RESET button and then release the BOOT button, if your board has them).\n\n```\nUsage: puyaisp.py [-h] [-u] [-l] [-e] [-o] [-G] [-R] [-f FLASH]\n\nOptional arguments:\n  -h, --help                show this help message and exit\n  -u, --unlock              unlock chip (remove read protection)\n  -l, --lock                lock chip (set read protection)\n  -e, --erase               perform chip erase (implied with -f)\n  -o, --rstoption           reset option bytes\n  -G, --nrstgpio            make nRST pin a GPIO pin\n  -R, --nrstreset           make nRST pin a RESET pin\n  -f FLASH, --flash FLASH   write BIN file to flash and verify\n\nExample:\npython3 puyaisp.py -f firmware.bin\n```\n\n### Installation via pip\nTake a look [here](https://pypi.org/project/puyaisp/).\n\n## stc8isp\n### Description\nWith this tool, STC8G/8H microcontrollers can be flashed via a simple USB-to-serial converter by utilizing the factory built-in embedded UART bootloader.\n\n### Preparations\nIf necessary, a driver for the USB-to-serial converter used must be installed.\n\n### Usage as a Script\n- Connect your USB-to-serial converter to your MCU as shown below.\n- Run stc8isp.py (see below for arguments).\n- Perform a power cycle of your MCU (reconnect to power) when prompted.\n\n```\nUSB2SERIAL         STC8G/8H\n+--------+         +------+\n|     VCC| --/ --\u003e |VCC   |    interruptible (for power cycle)\n|     RXD| --|R|-- |P3.1  |    resistor (100R - 1000R)\n|     TXD| --|\u003c|-- |P3.0  |    diode (e.g. 1N5819)\n|     GND| ------- |GND   |    common ground\n+--------+         +------+\n```\n\n```\nUsage: stc8isp.py [-h] [-p PORT] [-t TRIM] [-e] [-f FLASH]\n\nOptional arguments:\n  -h,       --help          show this help message and exit\n  -p PORT,  --port PORT     set COM port (default: /dev/ttyUSB0)\n  -t TRIM,  --trim TRIM     trim IRC to frequency in Hz (128000 - 36000000)\n  -e,       --erase         perform chip erase (implied with -f)\n  -f FLASH, --flash FLASH   write BIN file to flash\n\nExample:\npython3 stc8isp.py -p /dev/ttyUSB0 -t 24000000 -f firmware.bin\n```\n\n### Installation via pip\nTake a look [here](https://pypi.org/project/stc8isp/).\n\n## stc8usb\n## Description\nThis tool allows you to flash STC8H8KxxU microcontrollers through their USB interface, using the pre-installed embedded USB bootloader.\n\n## Preparations\nBecause the USB bootloader functions as a Human Interface Device (HID), there's no need to install drivers. However, Linux doesn't initially grant sufficient permissions to access the bootloader. To resolve this issue, open a terminal and execute the following commands:\n\n```\necho 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"34bf\", ATTR{idProduct}==\"1001\", MODE=\"666\"' | sudo tee /etc/udev/rules.d/99-STC-ISP.rules\nsudo udevadm control --reload-rules\n```\n\n### Usage as a Script\nTo initiate new uploads, the bootloader needs to be manually started. Begin by unplugging the board from the USB port and disconnecting all power sources. Then, press and hold the BOOT button while reconnecting the board to your PC's USB port. This action triggers the chip to enter bootloader mode. Once in this mode, you can release the BOOT button and proceed to upload new firmware via USB.\n\nIf your board doesn't have a BOOT button, you'll need to short pin P3.2 to ground while connecting to achieve the same effect.\n\n```\nUsage: stc8usb.py [-h] [-t TRIM] [-e] [-f FLASH]\n\nOptional arguments:\n  -h,       --help          show this help message and exit\n  -t TRIM,  --trim TRIM     set MCU system frequency\n  -e,       --erase         perform chip erase (implied with -f)\n  -f FLASH, --flash FLASH   write BIN file to flash\n\nExample:\npython3 stc8usb.py -t 24000000 -f firmware.bin\n```\n\n### Installation via pip\nTake a look [here](https://pypi.org/project/stc8usb/).\n\n## stm32isp\n### Description\nWith this tool, some entry-level STM32 microcontrollers can be flashed via a simple USB-to-serial converter by utilizing the factory built-in UART bootloader. It currently supports the following devices:\n- STM32C011/031\n- STM32F03xx4/6\n- STM32G03x/04x\n- STM32L01x/02x\n\n### Preparations\nIf necessary, a driver for the USB-to-serial converter used must be installed.\n\n### Usage as a Script\nConnect your USB-to-serial converter to your STM32 MCU as follows:\n\n```\nUSB2SERIAL      STM32C011/031\n+--------+      +------------+\n|     RXD| \u003c--- |PA9  (PA11) |\n|     TXD| ---\u003e |PA10 (PA12) |\n|     3V3| ---\u003e |VDD (3V3)   |\n|     GND| ---\u003e |GND         |\n+--------+      +------------+\n\nUSB2SERIAL      STM32F03xx4/6\n+--------+      +------------+\n|     RXD| \u003c--- |PA9  or PA14|\n|     TXD| ---\u003e |PA10 or PA15|\n|     3V3| ---\u003e |VDD (3V3)   |\n|     GND| ---\u003e |GND         |\n+--------+      +------------+\n\nUSB2SERIAL      STM32G03x/04x\n+--------+      +------------+\n|     RXD| \u003c--- |PA2 or PA9  |\n|     TXD| ---\u003e |PA3 or PA10 |\n|     3V3| ---\u003e |VDD (3V3)   |\n|     GND| ---\u003e |GND         |\n+--------+      +------------+\n\nUSB2SERIAL      STM32L01x/02x\n+--------+      +------------+\n|     RXD| \u003c--- |PA2 or PA9  |\n|     TXD| ---\u003e |PA3 or PA10 |\n|     3V3| ---\u003e |VDD (3V3)   |\n|     GND| ---\u003e |GND         |\n+--------+      +------------+\n```\n\nSet your MCU to boot mode by using ONE of the following method:\n- Disconnect your board from all power supplies, pull BOOT0 pin to VCC (or press and hold the BOOT button if your board has one), then connect the board to your USB port. The BOOT button can be released now.\n- Connect your USB-to-serial converter to your USB port. Pull BOOT0 pin to VCC, then pull nRST shortly to GND (or press and hold the BOOT button, then press and release the RESET button and then release the BOOT button, if your board has them).\n\nOn STM32G03x/04x microcontrollers, the BOOT0 pin is initially disabled. When the chip is brand new or the main flash memory is erased, this isn't an issue as the embedded bootloader automatically kicks in. By using the stm32isp tool, the BOOT0 pin will be activated for subsequent use. However, if the chip has been previously programmed using a different software tool, the bootloader might not be accessible through the BOOT0 pin anymore. In such cases, the nBOOT_SEL bit in the User Option Bytes must be cleared (set to 0) using an SWD programmer like ST-Link and the appropriate software.\n\n```\nUsage: stm32isp.py [-h] [-u] [-l] [-e] [-f FLASH]\n\nOptional arguments:\n  -h, --help                show this help message and exit\n  -u, --unlock              unlock chip (remove read protection)\n  -l, --lock                lock chip (set read protection)\n  -e, --erase               perform chip erase (implied with -f)\n  -f FLASH, --flash FLASH   write BIN file to flash and verify\n\nExample:\npython3 stm32isp.py -f firmware.bin\n```\n\n### Installation via pip\nTake a look [here](https://pypi.org/project/stm32isp/).\n\n## tinyupdi\n### Description\nThis tool allows tinyAVR series 0, 1, and 2 microcontrollers to be programmed using a USB-to-serial converter connected in a special way to the UPDI pin (also called SerialUPDI). More information can be found [here](https://github.com/SpenceKonde/AVR-Guidance/blob/master/UPDI/jtag2updi.md).\n\n### Preparations\nIf necessary, a driver for the USB-to-serial converter used must be installed.\n\n### Usage as a Script\nConnect the USB-to-serial converter via USB to the PC and via the circuit described below to the UPDI pin of the microcontroller.\n\n```\nUSB2SERIAL                       tinyAVR\n+--------+                    +-----------+\n|     RXD| \u003c------------+---\u003e |UPDI (PA0) |\n|        |              |     |           |\n|     TXD| ---|1kOhm|---+     |           |\n|        |                    |           |\n|     VDD| -----------------\u003e |VDD        |\n|     GND| -----------------\u003e |GND        |\n+--------+                    +-----------+\n```\n\nAlternatively, a pre-assembled [SerialUPDI programmer](https://github.com/wagiminator/AVR-Programmer) can be used.\n\n```\nUsage: tinyupdi.py [-h] [-d DEVICE] [-e] [-f FLASH] [-fs [FUSES [FUSES ...]]]\n\nOptional arguments:\n  -h, --help                show help message and exit\n  -d, --device              set target device (if not set, it will be auto-detected)\n  -e, --erase               perform a chip erase (implied with --flash)\n  -f FLASH, --flash FLASH   BIN file to flash\n  -fs [FUSES [FUSES ...]], --fuses [FUSES [FUSES ...]]\n                            fuses to set (syntax: fuse_nr:0xvalue)\n  -t TRIM, --trim TRIM      configure oscillator for given frequency (set fuse 2)\nExample:\npython3 tinyupdi.py -f firmware.bin -fs 6:0x04 7:0x00 8:0x00 -t 8000000\n```\n\n### Installation via pip\nTake a look [here](https://pypi.org/project/tinyupdi/).\n\n## Links\n1. [MCU Templates](https://github.com/wagiminator/MCU-Templates)\n2. [MCU Development Boards](https://github.com/wagiminator/Development-Boards)\n3. [AVR Development Boards](https://github.com/wagiminator/AVR-Development-Boards)\n4. [SerialUPDI Programmers](https://github.com/wagiminator/AVR-Programmer)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwagiminator%2Fmcu-flash-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwagiminator%2Fmcu-flash-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwagiminator%2Fmcu-flash-tools/lists"}