Skip to content

Replacing fly flash

fly-flash is bloat that does nothing but switch the GPIO pins BOOT1 (PD2) and RST (PD2) to put the Gemini MCU into HID-flash mode.

Here are 4 ways to flash klipper to the Gemini MCU:

1. Use make flash

The easiest way is possible only if a sufficiently recent klipper version is already running on the MCU. In that case, make flash FLASH_DEVICE=/dev/serial/by-id/... will reset the MCU into the DFU bootloader, flash klipper and then reset it back into klipper. Find the FLASH_DEVICE by following Identifying the Gemini MCU.

2. Booting into the STM32 Bootloader (DFU)

Just like make flash, you can boot the DFU bootloader by adding the BOOT0 jumper (BT0, red) and the BOOT1 jumper to GND, followed by pressing RESET1. The board will now be in DFU mode ("STM32 Bootloader").

You can now use make flash FLASH_DEVICE=0483:df11 to flash klipper to the MCU.

3. Jump BOOT1 to 3.3V and reset the board (RESET1)

Straight forward if you have physical access to the device. Connect BOOT1 to 3.3V and press the RESET1 button (bottom right, not the one next to the USB-C UART port). The board will now be in HID-flash mode.

Info

Removing the jumper alltogether will have the PIN floating. This means the MCU might or might not boot into the application firmware or the HID bootloader. You should only remove the jumper if you're using any of the following scripts.

4. Remove the jumper for BOOT1 and use a script like fly-flash to switch the MCU to HID-flash mode

Remove the jumper connecting BT1 with GND before proceeding. If you have a newer kernel (like my armbian images) and there is no /sys/class/gpio/ directory, use the first script. Otherwise, you may use the second script.

Newer kernels (without /sys/class/gpio/)

Danger: Executing random scripts strangers give you

... is the best way to compromise your system. Whenever you see a curl -sSL ... | bash command on these sites, run it first without the | bash and inspect it.

Paste this into your terminal
curl -sSL https://reemo3dp.github.io/devices/Mellow-Fly-Gemini-V3/gpioset-fly-flash.sh | sudo bash
gpioset-fly-flash.sh
#!/bin/bash


set -euxo pipefail


CHIPSET="1c20800.pinctrl"
PD4="100"
PD2="98"
BOOT1="$PD2"
RST="$PD4"

echo "Remove all jumpers from the board, then press ENTER"
read

gpioset --mode=signal "$CHIPSET" "$BOOT1"=1 &
BOOT1_PID=$!

gpioset --mode=time --sec=1 "$CHIPSET" "$RST"=0
gpioset --mode=exit "$CHIPSET" "$RST"=1
sleep 1

lsusb

echo "MCU should now be in HID mode. Check lsusb for HID flash device and proceed in a different shell. Press ENTER to boot the MCU back into regular mode"
read

kill $BOOT1_PID

gpioset --mode=exit "$CHIPSET" "$BOOT1"=0

gpioset --mode=time --sec=1 "$CHIPSET" "$RST"=0
gpioset --mode=exit "$CHIPSET" "$RST"=1

sleep 1

lsusb

echo "MCU should now boot into regular mode. Check lsusb for regular device."
echo "Put the jumper back into place (GND+BOOT1), otherwise your MCU might boot into HID after a power-on"

Older kernels (with /sys/class/gpio)

Danger: Executing random scripts strangers give you

... is the best way to compromise your system. Whenever you see a curl -sSL ... | bash command on these sites, run it first without the | bash and inspect it.

Paste this into your terminal
curl -sSL https://reemo3dp.github.io/devices/Mellow-Fly-Gemini-V3/simple-fly-flash.sh | sudo bash
gpioset-fly-flash.sh
#!/bin/bash

set -euxo pipefail

# Adapted from https://cdn.mellow.klipper.cn/Utils/fly-flash/fly-flash
PD4="100"
PD2="98"

BOOT1="$PD2"
G_BOOT1="/sys/class/gpio/gpio${BOOT1}"
RST="$PD4"
G_RST="/sys/class/gpio/gpio${RST}"

echo "$RST" > /sys/class/gpio/export
echo "$BOOT1" > /sys/class/gpio/export

echo "out" > "$G_BOOT1/direction"
echo "out" > "$G_RST/direction"

echo "Press enter to reboot the Gemini MCU into the HID bootloader"
read
echo "1" > "$G_BOOT1/value"
sleep 1
echo "0" > "$G_RST/value"
sleep 1
echo "1" > "$G_RST/value"

echo "Proceed with flashing the gemini mcu using hid-flash from klipper"
echo "Press enter to reboot the Gemini into klipper again"
read
echo "0" > "$G_BOOT1/value"
sleep 1
echo "0" > "$G_RST/value"
sleep 1
echo "1" > "$G_RST/value"