|
| 1 | +# mpflash |
| 2 | +mpflash is a command-line tool for working with MicroPython firmware. It provides various features to help you develop, build, and manage your MicroPython projects. |
| 3 | + |
| 4 | +This tool was created to be used in a CI/CD pipeline to automate the process of downloading and flashing MicroPython firmware to multiple boards, but it can also be used for manual flashing and development. |
| 5 | + |
| 6 | +mpflash has been tested on Windows x64, Linux X64 and ARM64, but not (yet) macOS. |
| 7 | + |
| 8 | +## Features |
| 9 | + 1. List the connected boards including their firmware details, in a tabular or json format |
| 10 | + 2. Download MicroPython firmware for specific boards and versions. |
| 11 | + 3. Flash one or all connected MicroPython boards with a specific firmware or version. |
| 12 | + Tested ports: rp2, samd, esp32, esp32s3, esp8266 and stm32 (requires cubeprogrammer) |
| 13 | + |
| 14 | +## Installation |
| 15 | +To install mpflash, you can use pip: `pip install mpflash` |
| 16 | + |
| 17 | +## How to use |
| 18 | +You can list the connected boards using the following command: |
| 19 | +```bash |
| 20 | +$ mpflash list |
| 21 | +D:\MyPython\micropython-stubber> mpflash list |
| 22 | +Getting board info ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:02 |
| 23 | + Connected boards |
| 24 | +┏━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━┓ |
| 25 | +┃ Serial ┃ Family ┃ Port ┃ Board ┃ CPU ┃ Version ┃ build ┃ |
| 26 | +┡━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━┩ |
| 27 | +│ COM11 │ micropython │ rp2 │ RPI_PICO_W │ RP2040 │ 1.20.0 │ │ |
| 28 | +│ COM12 │ micropython │ esp8266 │ ESP8266_GENERIC │ ESP8266 │ 1.22.2 │ │ |
| 29 | +│ COM18 │ micropython │ rp2 │ RPI_PICO_W │ RP2040 │ 1.23.0-preview │ 155 │ |
| 30 | +│ COM3 │ micropython │ samd │ SEEED_WIO_TERMINAL │ SAMD51P19A │ 1.23.0-preview │ 155 │ |
| 31 | +│ COM5 │ micropython │ stm32 │ PYBV11 │ STM32F405RG │ 1.23.0-preview │ 166 │ |
| 32 | +│ COM8 │ micropython │ esp32 │ ESP32_GENERIC_S3 │ ESP32S3 │ 1.23.0-preview │ 155 │ |
| 33 | +└────────┴─────────────┴─────────┴────────────────────┴─────────────┴────────────────┴───────┘ |
| 34 | +``` |
| 35 | + |
| 36 | +Suppose you want to download the MicroPython firmware for some boards, you can use the following command: |
| 37 | + |
| 38 | +```bash |
| 39 | +# download the firmware |
| 40 | +$ mpflash download --board ESP8266_GENERIC --board SEEED_WIO_TERMINAL |
| 41 | +``` |
| 42 | +This will download the latest stable version of the MicroPython firmware for the boards and save it in the `firmware` directory. |
| 43 | +The stable version (default) is determined based on the most recent published release, |
| 44 | +other optionse are `--version preview` and `--version x.y.z` to download the latest preview or version x.y.z respectively. |
| 45 | + |
| 46 | +The directory structure will be something like this: |
| 47 | +``` |
| 48 | +firmware |
| 49 | +| firmware.jsonl |
| 50 | ++---esp8266 |
| 51 | +| ESP8266_GENERIC-FLASH_1M-v1.22.2.bin |
| 52 | +| ESP8266_GENERIC-FLASH_512K-v1.22.2.bin |
| 53 | +| ESP8266_GENERIC-OTA-v1.22.2.bin |
| 54 | +| ESP8266_GENERIC-v1.22.2.bin |
| 55 | +\---samd |
| 56 | + SEEED_WIO_TERMINAL-v1.22.2.uf2 |
| 57 | +``` |
| 58 | +You can then flash the firmware to the board using the following command: `mpflash flash` |
| 59 | +This will (try to) autodetect the connected boards, and determine the correct firmware to flash to each board. |
| 60 | + |
| 61 | +```bash |
| 62 | +> mpflash flash |
| 63 | +22:15:55 | ℹ️ - Using latest stable version: v1.22.2 |
| 64 | + Connected boards |
| 65 | +┏━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━┓ |
| 66 | +┃ Serial ┃ Family ┃ Port ┃ Board ┃ CPU ┃ Version ┃ build ┃ |
| 67 | +┡━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━┩ |
| 68 | +│ COM11 │ micropython │ rp2 │ RPI_PICO_W │ RP2040 │ 1.20.0 │ │ |
| 69 | +│ COM12 │ micropython │ esp8266 │ ESP8266_GENERIC │ ESP8266 │ 1.22.2 │ │ |
| 70 | +│ COM18 │ micropython │ rp2 │ RPI_PICO_W │ RP2040 │ 1.23.0-preview │ 155 │ |
| 71 | +│ COM3 │ micropython │ samd │ SEEED_WIO_TERMINAL │ SAMD51P19A │ 1.23.0-preview │ 155 │ |
| 72 | +│ COM5 │ micropython │ stm32 │ PYBV11 │ STM32F405RG │ 1.23.0-preview │ 166 │ |
| 73 | +│ COM8 │ micropython │ esp32 │ ESP32_GENERIC_S3 │ ESP32S3 │ 1.23.0-preview │ 155 │ |
| 74 | +└────────┴─────────────┴─────────┴────────────────────┴─────────────┴────────────────┴───────┘ |
| 75 | +22:15:58 | ℹ️ - Found v1.22.2 firmware rp2\RPI_PICO_W-v1.22.2.uf2 for RPI_PICO_W on COM11. |
| 76 | +22:15:58 | ℹ️ - Found v1.22.2 firmware esp8266\ESP8266_GENERIC-v1.22.2.bin for ESP8266_GENERIC on COM12. |
| 77 | +22:15:58 | ℹ️ - Found v1.22.2 firmware rp2\RPI_PICO_W-v1.22.2.uf2 for RPI_PICO_W on COM18. |
| 78 | +22:15:58 | ℹ️ - Found v1.22.2 firmware samd\SEEED_WIO_TERMINAL-v1.22.2.uf2 for SEEED_WIO_TERMINAL on COM3. |
| 79 | +22:15:58 | ⚠️ - Trying to find a firmware for the board PYBV11 |
| 80 | +22:15:58 | ❌ - No v1.22.2 firmware found for PYBV11 on COM5. |
| 81 | +22:15:58 | ⚠️ - Trying to find a firmware for the board ESP32-GENERIC-S3 |
| 82 | +22:15:58 | ❌ - No v1.22.2 firmware found for ESP32_GENERIC_S3 on COM8. |
| 83 | +22:15:58 | ℹ️ - Updating RPI_PICO_W on COM11 to 1.22.2 |
| 84 | +22:15:58 | ℹ️ - Erasing not yet implemented for UF2 flashing. |
| 85 | +22:15:58 | ℹ️ - Entering UF2 bootloader on RPI_PICO_W on COM11 |
| 86 | +22:15:58 | ℹ️ - Waiting for mcu to mount as a drive : 10 seconds left |
| 87 | +22:15:59 | ℹ️ - Waiting for mcu to mount as a drive : 9 seconds left |
| 88 | +22:16:00 | ℹ️ - Board is in bootloader mode |
| 89 | +22:16:00 | ℹ️ - Copying firmware\rp2\RPI_PICO_W-v1.22.2.uf2 to F: |
| 90 | +22:16:13 | ✅ - Done copying, resetting the board and wait for it to restart |
| 91 | +22:16:23 | ℹ️ - Updating ESP8266_GENERIC on COM12 to 1.22.2 |
| 92 | +22:16:23 | ℹ️ - Flashing firmware\esp8266\ESP8266_GENERIC-v1.22.2.bin on ESP8266_GENERIC on COM12 |
| 93 | +22:16:23 | ℹ️ - Running esptool --chip ESP8266 --port COM12 erase_flash |
| 94 | +esptool.py v4.7.0 |
| 95 | +Serial port COM12 |
| 96 | +Connecting.... |
| 97 | +... |
| 98 | +Chip erase completed successfully in 6.5s |
| 99 | +Hard resetting via RTS pin... |
| 100 | +22:16:31 | ℹ️ - Running esptool --chip ESP8266 --port COM12 -b 460800 write_flash --flash_size=detect 0x0 firmware\esp8266\ESP8266_GENERIC-v1.22.2.bin |
| 101 | +esptool.py v4.7.0 |
| 102 | +Serial port COM12 |
| 103 | +Connecting.... |
| 104 | +... |
| 105 | +Leaving... |
| 106 | +Hard resetting via RTS pin... |
| 107 | +22:16:43 | ℹ️ - Done flashing, resetting the board and wait for it to restart |
| 108 | +22:16:49 | ✅ - Flashed 1.22.2 to ESP8266_GENERIC on COM12 done |
| 109 | +22:16:49 | ℹ️ - Updating RPI_PICO_W on COM18 to 1.22.2 |
| 110 | +22:16:49 | ℹ️ - Erasing not yet implemented for UF2 flashing. |
| 111 | +22:16:49 | ℹ️ - Entering UF2 bootloader on RPI_PICO_W on COM18 |
| 112 | +22:16:49 | ℹ️ - Waiting for mcu to mount as a drive : 10 seconds left |
| 113 | +22:16:50 | ℹ️ - Waiting for mcu to mount as a drive : 9 seconds left |
| 114 | +22:16:51 | ℹ️ - Board is in bootloader mode |
| 115 | +22:16:51 | ℹ️ - Copying firmware\rp2\RPI_PICO_W-v1.22.2.uf2 to F:[/bold] |
| 116 | +22:17:02 | ✅ - Done copying, resetting the board and wait for it to restart |
| 117 | +22:17:12 | ℹ️ - Updating SEEED_WIO_TERMINAL on COM3 to 1.22.2 |
| 118 | +22:17:12 | ℹ️ - Erasing not yet implemented for UF2 flashing. |
| 119 | +22:17:12 | ℹ️ - Entering UF2 bootloader on SEEED_WIO_TERMINAL on COM3 |
| 120 | +22:17:12 | ℹ️ - Waiting for mcu to mount as a drive : 10 seconds left |
| 121 | +22:17:13 | ℹ️ - Waiting for mcu to mount as a drive : 9 seconds left |
| 122 | +22:17:14 | ℹ️ - Board is in bootloader mode |
| 123 | +22:17:14 | ℹ️ - Copying firmware\samd\SEEED_WIO_TERMINAL-v1.22.2.uf2 to F:[/bold] |
| 124 | +22:17:17 | ✅ - Done copying, resetting the board and wait for it to restart |
| 125 | +22:17:27 | ℹ️ - Flashed 4 boards |
| 126 | + Connected boards after flashing |
| 127 | +┏━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━┓ |
| 128 | +┃ Serial ┃ Family ┃ Port ┃ Board ┃ CPU ┃ Version ┃ build ┃ |
| 129 | +┡━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━┩ |
| 130 | +│ COM11 │ micropython │ rp2 │ RPI_PICO_W │ RP2040 │ 1.22.2 │ │ |
| 131 | +│ COM12 │ micropython │ esp8266 │ ESP8266_GENERIC │ ESP8266 │ 1.22.2 │ │ |
| 132 | +│ COM18 │ micropython │ rp2 │ RPI_PICO_W │ RP2040 │ 1.22.2 │ │ |
| 133 | +│ COM3 │ micropython │ samd │ SEEED_WIO_TERMINAL │ SAMD51P19A │ 1.22.2 │ │ |
| 134 | +│ COM5 │ micropython │ stm32 │ PYBV11 │ STM32F405RG │ 1.23.0-preview │ 166 │ |
| 135 | +│ COM8 │ micropython │ esp32 │ ESP32_GENERIC_S3 │ ESP32S3 │ 1.23.0-preview │ 155 │ |
| 136 | +└────────┴─────────────┴─────────┴────────────────────┴─────────────┴────────────────┴───────┘ |
| 137 | +``` |
| 138 | +Note that if no matching firmware can be found for a board, it will be skipped. |
| 139 | +(For example, the PYBV11 and ESP32_GENERIC_S3 boards in the example above.) |
| 140 | + |
| 141 | +## Issues and bug reports |
| 142 | +mpflash is currently co-located in the [micropython-stubber](https://github.com/Josverl/micropython-stubber) repository. |
| 143 | +Please report any issues or bugs in the [issue tracker](https://github.com/Josverl/micropython-stubber/issues) with '[mpflash]' in the subject. |
| 144 | + |
| 145 | +## License |
| 146 | +mpflash is licensed under the MIT license. See the LICENSE file for more details. |
0 commit comments