Skip to content

About

Windows CLI tools for the Artillery Hornet (Ruby STM32 board): back up and restore Marlin settings, back up the full flash, and update firmware over USB DFU.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Artillery Ruby Tools

Small Windows-friendly CLI tools for backing up and restoring Marlin settings and updating the firmware of STM32 printer boards over USB (DFU).

The neighboring Marlin checkout is configured for an Artillery Hornet with an Artillery Ruby board, Artillery_Ruby PlatformIO environment, 250000 baud and EEPROM settings. These are defaults and context, not a substitute for checking the connected printer and firmware before use.

Prerequisites

What Needed for Notes
Windows with Python 3.9 or newer everything Tested with Python 3.12. pyserial is installed by the setup below.
Printer connected by USB and switched on everything Idle, not printing. Close Pronterface, slicers and other programs that use the printer's port.
Marlin with EEPROM_SETTINGS saving settings (--save, M500) Without it, restored settings last only until the next power-off.
PlatformIO (recommended) building the firmware; flashing with its dfu-util Found on PATH or in %USERPROFILE%\.platformio. If dfu-util is missing, install it with pio pkg install -g --tool platformio/tool-dfuutil.
STM32CubeProgrammer flashing, if PlatformIO is not installed Cannot build: an existing build is flashed. Found on PATH or in its default install folder.
WinUSB driver for the board in DFU mode flashing, flash backups Installed by STM32CubeProgrammer. With only PlatformIO, install it once with Zadig for "STM32 BOOTLOADER" while the board is in DFU mode.
A board that M997 puts into DFU mode update-firmware, backup-flash, restore-flash True for the Artillery Ruby (Marlin's MARLIN_ARTILLERY_RUBY variant). For recovery without a working firmware: the board's BOOT0 jumper.

Settings commands (ports, backup-settings, restore-settings, versions) only need the first three rows. To choose a flashing tool, pass --programmer with the path of dfu-util.exe or STM32_Programmer_CLI.exe.

Folder layout

PlatformIO\Marlin\                     <- search folder for firmware
├── ArtilleryRubyTools\                <- this project
│   ├── update_printer.py              <- one-step update script
│   ├── src\ruby_tools\                <- ruby-tools package
│   ├── tests\
│   ├── backups\                       <- created on first use
│   │   ├── settings-<time>.gcode      <- settings backups (M503)
│   │   └── flash-<time>.bin           <- complete flash backups
│   └── .venv\                         <- created by the setup below
├── Marlin-2.1.2.9\                    <- a Marlin source folder (any name)
│   ├── platformio.ini                 <- with ini\*.ini: defines [env:Artillery_Ruby]
│   ├── ini\*.ini
│   ├── Marlin\Configuration.h
│   ├── Marlin\Configuration_adv.h
│   └── .pio\build\Artillery_Ruby\firmware.elf   <- build output, flashed
├── Marlin-2.1.3\                      <- more source folders: you choose
└── MarlinBuilds\                      <- optional: prebuilt firmware
    └── builds\Artillery\Hornet\
        └── Artillery_Ruby\            <- PlatformIO environment
            ├── firmware.zip           <- contains firmware.bin
            └── firmware.bin.sha256.txt
  • Marlin sources are found in the folder that contains this project. A folder counts if it has platformio.ini, Marlin\Configuration.h and the PlatformIO environment; its name does not matter. Elsewhere, pass --marlin-dir (update_printer.py) or --search-dir (versions).
  • Prebuilt firmware comes from a clone of MarlinBuilds in the same folder: git clone https://github.com/MarlinFirmware/MarlinBuilds.git. A folder counts if it has a builds\ folder; prebuilt firmware is found at builds\<vendor>\<model>\...\<environment>\firmware.zip. Update it with git pull. These builds use Marlin's example configuration for the printer, not your own configuration.
  • Backups: update_printer.py always writes to ArtilleryRubyTools\backups\. ruby-tools uses backups\ in the current folder, so run it from ArtilleryRubyTools, or pass --backup-dir / --output.
  • From a Marlin source, firmware.elf is flashed. Prebuilt firmware is flashed from its firmware.zip.

Setup

From the ArtilleryRubyTools folder in PowerShell:

py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e .

ruby-tools is then available while the .venv is active. update_printer.py also works without activating it: started with any Python 3, it restarts itself with the .venv Python.

Serial port

All commands find the printer by themselves: each USB serial port is opened and asked for M115, and the one that answers as Marlin is used. If no port or several ports answer, the ports are listed and you are asked to pick one, by number or name. A port another program holds open (Pronterface, a slicer) is shown as "in use". To skip the search, pass --port COM5.

ruby-tools ports

lists all serial ports and which of them answer as a Marlin printer.

Back up settings

Ask Marlin to report its settings with M503:

ruby-tools backup-settings

The backup is written under backups\ as a .gcode file. Choose another location with --output. The saved file contains only recognized setting commands from the M503 response and can be inspected before restoring.

Restore settings

ruby-tools restore-settings --input .\backups\settings-YYYYMMDD-HHMMSS.gcode

Restore requires an interactive yes confirmation unless --yes is supplied. Only the setting commands supported by this tool are sent; motion, heater, and other unrecognized G-code is rejected. If the printer ignores a setting, the restore stops before saving anything. The exception is input shaping (M593): if the connected firmware was built without it, those lines are skipped with a warning and the rest is restored. By default, settings are applied to RAM only. Add --save to send M500 after all settings have been accepted by the printer and persist them to EEPROM.

Keep the printer idle while using the serial connection. Close slicers and other programs that may already be using the selected port. Verify that a backup belongs to the connected printer and firmware before restoring it.

Update firmware

Marlin's M997 restarts the Artillery Ruby board into the STM32 chip's built-in DFU bootloader. dfu-util or STM32CubeProgrammer then writes the firmware over USB. The DFU bootloader is in read-only system memory, so a failed write can always be repeated.

One step: update_printer.py

python update_printer.py

The script checks, before anything is changed:

  • ruby-tools and a flashing tool are installed: dfu-util from PlatformIO, otherwise STM32CubeProgrammer.
  • For a Marlin source: firmware.elf exists and is newer than Configuration.h and Configuration_adv.h. If not, it is built with PlatformIO; without PlatformIO, the script stops. --build always builds.
  • For prebuilt firmware: firmware.zip contains one firmware.bin whose SHA-256 checksum matches firmware.bin.sha256.txt.
  • The serial port exists if --port is given.

Then it runs ruby-tools update-firmware, which stops at the first failed check:

  1. Checks the firmware file (.elf, .bin or .zip): starts at 0x08000000, fits in flash, valid start-up code, contains a Marlin version and machine type.
  2. Checks that no board is already in DFU mode, the printer answers M115, reports the same machine type as the firmware, and is not printing (M27).
  3. Backs up the settings (M503) to backups\settings-<time>.gcode.
  4. Asks for yes (skip with --yes).
  5. Restarts the board into DFU mode (M997) and backs up the complete flash to backups\flash-<time>.bin. If this fails, the old firmware is started again.
  6. Writes the firmware, reads it back and compares it. If this fails, the board stays in DFU mode and the error says how to write the backup back.
  7. Starts the firmware and checks that M115 reports exactly the new build.
  8. Restores the settings, saves them with M500, reloads them with M501 and checks them.

The script first asks the printer for its machine type (e.g. Hornet), then lists the firmware to choose from (see Folder layout):

  • Marlin sources with the PlatformIO environment ([env:Artillery_Ruby]), newest configuration first; built if needed.
  • Prebuilt firmware from MarlinBuilds for that environment and for the printer's machine type. If the printer does not answer, prebuilt firmware of all machine types is listed; the update still refuses firmware for another machine type.

With one choice, it is used. With several, you choose; Enter takes the first. --marlin-dir or --firmware choose directly:

python update_printer.py --marlin-dir ..\Marlin-2.1.2.9
python update_printer.py --firmware ..\MarlinBuilds\builds\Artillery\Hornet\Artillery_Ruby\firmware.zip
Printer on COM3: Hornet
Firmware for Hornet with the environment 'Artillery_Ruby':
  1) Marlin-2.1.2.9 - source, Marlin 2.1.2.9, configuration changed 2026-11-01 14:02
  2) Marlin-2.1.2.5 - source, Marlin bugfix-2.1.x, configuration changed 2024-12-27 16:49
  3) MarlinBuilds: Artillery/Hornet - prebuilt, Marlin 2.1.2.8 (Jun 25 2026 00:25:43), machine Hornet
Enter the number of the firmware to flash [1]:

Script options: --port (default: detect the printer), --marlin-dir or --firmware (default: choose as above), --environment (default Artillery_Ruby), --programmer, --build (Marlin sources only), and --restore-settings:

  • auto (default): restore the settings backup from step 3.
  • none: keep the settings the new firmware starts with.
  • a file: restore that backup, e.g. one where you removed lines whose new firmware defaults you want to keep.

The script runs with any Python 3: if ruby-tools cannot be imported, it restarts itself with the project's .venv Python.

Firmware files and the settings sector:

  • .elf (PlatformIO build): carries its own addresses and only the parts of the firmware, so the emulated EEPROM sector (0x08004000) with the stored settings is not touched.
  • .bin (PlatformIO build) and .zip (MarlinBuilds): a raw image from 0x08000000 that also covers the settings sector, filled with 0x00 or 0xFF. The tools leave out 16 KB blocks in the first 64 KB that contain only such fill bytes, so the settings sector is not erased either.

Prebuilt firmware is built with Marlin's example configuration. Features you enabled in your own build (e.g. input shaping, the input shaping menu, leveling after G28) may be missing; restoring settings skips input shaping values if the firmware has no input shaping.

A firmware with a different settings layout starts with default settings even though the sector is not erased. That is why settings are restored by default.

dfu-util has no verify step and erases a flash sector before its first write in each run. The tools therefore write parts of the .elf that share a sector in one run, and read every written range back to compare it.

Available firmware

ruby-tools versions --printer

lists the firmware that can be flashed:

  • Marlin sources next to this project with the PlatformIO environment, newest configuration first: Marlin version, configuration date, and the build in .pio\build\<environment>\firmware.elf with its version, or why it is missing or outdated.
  • Prebuilt firmware from MarlinBuilds for the environment, with version, machine type and path; damaged downloads (checksum mismatch) are marked.
  • Flash backups in backups\ with the firmware they contain; they can be written back with restore-flash.

--printer (or --port) also asks the printer which firmware it runs and marks the matching build and backups, and the prebuilt firmware for its machine type. Other options: --environment, --search-dir (default: the folder that contains this project) and --backup-dir.

Printer on COM3: Hornet, Marlin 2.1.2.9 (Nov  1 2026 14:03:38)

Marlin sources in C:\...\PlatformIO\Marlin (environment Artillery_Ruby):
  Marlin-2.1.2.9: Marlin 2.1.2.9, configuration changed 2026-11-01 14:02
      build: Marlin 2.1.2.9 (Nov  1 2026 14:03:38), up to date  <- on the printer
  Marlin-2.1.2.5: Marlin bugfix-2.1.x, configuration changed 2024-12-27 16:49
      build: not built

Prebuilt firmware in C:\...\PlatformIO\Marlin (environment Artillery_Ruby):
  MarlinBuilds: Artillery/Genius Pro: Marlin 2.1.2.8 (Jun 25 2026 00:26:45), machine Genius Pro
      C:\...\MarlinBuilds\builds\Artillery\Genius Pro\Artillery_Ruby\firmware.zip
  MarlinBuilds: Artillery/Hornet: Marlin 2.1.2.8 (Jun 25 2026 00:25:43), machine Hornet  <- for this printer
      C:\...\MarlinBuilds\builds\Artillery\Hornet\Artillery_Ruby\firmware.zip
  MarlinBuilds: Artillery/Sidewinder X2: Marlin 2.1.2.8 (Jun 25 2026 00:26:25), machine Sidewinder X2
      C:\...\MarlinBuilds\builds\Artillery\Sidewinder X2\Artillery_Ruby\firmware.zip

Flash backups in C:\...\ArtilleryRubyTools\backups (restore with restore-flash):
  flash-20261101-155254.bin: Marlin 2.1.2.9 (Nov  1 2026 14:03:38)  <- on the printer
  factory-flash-2026-11-01.bin: Marlin bugfix-2.1.x (Dec 29 2024 19:03:52)

Individual commands

ruby-tools update-firmware `
  --firmware ..\Marlin-<version>\.pio\build\Artillery_Ruby\firmware.elf `
  --restore-settings
ruby-tools update-firmware `
  --firmware ..\MarlinBuilds\builds\Artillery\Hornet\Artillery_Ruby\firmware.zip `
  --restore-settings
ruby-tools backup-flash
ruby-tools restore-flash --input .\backups\flash-YYYYMMDD-HHMMSS.bin
  • --restore-settings without a file restores the backup made at the start; with a file, that backup. Leave it out to keep the new firmware's settings.
  • backup-flash saves the complete flash and starts the unchanged firmware again.
  • restore-flash writes a complete flash backup back, e.g. to return to the previous firmware. If the board is already in DFU mode, no serial port is needed; otherwise the printer is found as usual.
  • After flashing, update-firmware also finds the printer if Windows gave it a new COM port.

Recovery

If the board does not start after a failed update, it cannot be switched into DFU mode with M997. Run the same update again if it is still in DFU mode (dfu-util -l or STM32_Programmer_CLI -l usb lists it). Otherwise, put it into DFU mode with the board's BOOT0 jumper, run ruby-tools restore-flash --input <flash backup>, then remove the jumper.

Development and tests

The tests use Python's standard unittest runner:

python -m unittest discover -s tests -v

Code checks with flake8 and pylint, installed with the dev extra:

python -m pip install -e ".[dev]"
python -m flake8
python -m pylint src/ruby_tools tests update_printer.py

Both use lines up to 100 characters. flake8 is configured in .flake8 (it cannot read pyproject.toml), pylint in pyproject.toml. flake8 ignores E203 (spaces around : in slices, as PEP 8 allows for complex slices). pylint asks for docstrings only on functions and classes longer than 10 lines; the test files switch off messages that do not apply to tests in their header comment.

All files use LF line endings; .gitattributes keeps it that way.

About

Windows CLI tools for the Artillery Hornet (Ruby STM32 board): back up and restore Marlin settings, back up the full flash, and update firmware over USB DFU.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages