# Updating and Flashing the the Toolhead MCU

*By Einlander*   
  
The Qidi 3 series toolhead is based on the Makerbase THR36 and THR42 toolheads ([https://github.com/makerbase-mks/MKS-THR36-THR42-UTC](https://github.com/makerbase-mks/MKS-THR36-THR42-UTC)). Flashing the qidi toolhead is a similar experience. They both use a Raspberry Pi 2040 MCU and can/are controlled by USB. The major difference is the Qidi toolhead runs 24v over the USB lines. The Qidi printers run a version of Armbian Linux running Debian Buster.

# The Process.

Here, we will break down the main steps to update and flash toolhead:

1. Compile the Klipper firmware.
2. Set the toolhead to DFU mode
3. Upload the firmware

# Assumptions and Prerequisites

Wherever possible, we will proceed using the easiest method. Tough updating and flashing the toolhead can be done completely in Linux, we will assume that a Windows PC will be used. Software that will be used is any SSH client (I think Windows 10 has one built-in). I will assume that you know how to acquire, setup and use ssh.

> <span style="color: rgb(224, 62, 45);">MAKE SURE TO REMOVE ALL USB DRIVES AND MEMORY CARDS!</span>
> 
> <span style="color: rgb(224, 62, 45);">They may conflict or make this guide difficult to follow or complete.</span>

# Compiling Klipper firmware:

## Connect to printer

First we need to log into the printer using ssh as the user mks. You connect by directly connecting to your printer by using it's IP address.

The address format is :

```
mks@your.ip.address.here
```

The default password is

```
makerbase
```

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/1iTCJV5Vae5I9rPX-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/1iTCJV5Vae5I9rPX-image.png)

## Set the time

Before we do anything else, we need to set the time.

> <span style="color: rgb(241, 196, 15);">Failing to do this step may cause the update process to fail or become more difficult.</span>

The command to set the date is

```bash
sudo date -s 'YYYY-MM-DD HH:MM:SS'
```

the password is: makerbase

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/sXWdTRoQMgGpPeV1-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/sXWdTRoQMgGpPeV1-image.png)

You can also try this command to try to set it automatically.

```bash
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
```

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/ybeu3YAi3Eg0nelO-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/ybeu3YAi3Eg0nelO-image.png)

## Kiauh

Now, we are at one of the main parts of updating and flashing the toolhead. For this, we will use [KIAUH](https://github.com/dw-0/kiauh) the Klipper Installer and Update Helper. In our case, it is already installed on the printer. To run it, we must first type this command:

```
 ~/kiauh/kiauh.sh
```

> This command will only work when logged in as mks. It will warn you if you use it as root.

KIAUH will ask you if you want to update, type:

```
Y
```

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/HoubqyhcLIZHVAc9-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/HoubqyhcLIZHVAc9-image.png)

After it updates, we need to delete some folders.

> This assumes you have never gone through this tutorial before. Qidi has customized some of the files, and KIAUH will fail when it finds them. You shouldn't need to do this in future updates. For our purposes, we will delete the directories.

```
sudo rm -r ~/klipper/
sudo rm -r ~/moonraker/
```

Start KIAUH again by typing:

```
~/kiauh/kiauh.sh
```

You should have arrived at the Main Menu screen:

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/L7o255Yh409Ky56p-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/L7o255Yh409Ky56p-image.png)

First, we type 3 to get the Remove Menu.

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/6OMvPH1AZRzdBXC2-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/6OMvPH1AZRzdBXC2-image.png)

Then we remove 1 Klipper , 2 Moonraker, and 3 Fluidd.

When it returns to the Remove Menu, we will Type B to return to the main menu.

Type 1 for the installation menu

Type 1 to install Klipper.

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/Pz03RR3oW8m7S5cQ-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/Pz03RR3oW8m7S5cQ-image.png)

Type 1 to use Python 3.x

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/RG79zmXk4bMzZxs2-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/RG79zmXk4bMzZxs2-image.png)

Type 1 to run one instance of Klipper

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/bjaHqx6CysF9az7X-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/bjaHqx6CysF9az7X-image.png)

Wait for it to install.

When KIAUH returns to the Installation menu, Type 2 to install Moonraker and wait for the install. Then install 4 Fluidd, answering yes to the questions it asks.

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/6k2KwIMV8mcVROtv-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/6k2KwIMV8mcVROtv-image.png)

Type B to return to the main menu and 2 to go to the Upgrade Menu.

Type 4 to upgrade Fluidd, then return to the main menu.

Type 4 to go to the Advanced Menu.

In the Advanced Menu, we just want to build the firmware. Select: 2

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/M5zVrFOvA9DLwz9A-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/M5zVrFOvA9DLwz9A-image.png)

## MCU Settings

The next screen you will see is the Klipper Firmware Configuration screen. Here, we will need to change the settings to match our toolhead mcu. Press space or enter to select items.

Select: Enable extra low-level configuration options

Select: Micro-controller Architecture (Raspberry Pi RP2040)

Then, leave everything else alone.

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/twOx8KWvJdDA4EpW-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/twOx8KWvJdDA4EpW-image.png)

Press Q, then Y to save. The firmware will be built, and it will return us to the Advanced Menu.

Now, we want to quit KIAHU. Press B to return to the Main Menu and Q to quit.

# Setting the toolhead to DFU mode

Setting the toolhead to DFU mode requires you to remove the back cover of the toolhead.  
On the bottom left, there are two buttons labeled BOOT and RESET.

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/asooRIZ6sCTCUZDj-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/asooRIZ6sCTCUZDj-image.png)

The easiest way to put it into DFU mode is to press and hold the BOOT button, press and release the RESET button, and then release the BOOT button.

> <span style="color: rgb(241, 196, 15);">You have to press the reset button while still holding the boot button.</span>

To check if your toolhead is in DFU mode, type:

```
lsusb
lsblk
```

> <span style="color: rgb(53, 152, 219);">If you see an OpenMoko, Inc. device, it is not in DFU mode.</span>

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/FVQY3Q0UImt9L5pG-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/FVQY3Q0UImt9L5pG-image.png)

> <span style="color: rgb(45, 194, 107);">If you do not see an OpenMoko, Inc. device AND a sda disk with a MOUNTPOINT of /home/mks/gcode\_files/sda1 the toolhead is in DFU mode.</span>
> 
> <span style="color: rgb(45, 194, 107);">The disk name may also be named sda, sdb, sdc, etc.</span>

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/nj5kubnv5WG3aFR2-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/nj5kubnv5WG3aFR2-image.png)

# Uploading the Firmware

Now that the toolhead is in DFU mode, it will show up as a USB drive to the printer. Luckily QIDI decided to auto-mount USB drives for us.

To upload the firmware, we simply need to copy the compiled Klipper firmware file to the toolhead.

To do that type:

```bash
cp ~/klipper/out/klipper.uf2 ~/gcode_files/sda1/
```

As soon as the file is copied, the toolhead will no longer be in DFU mode and it will disconnect the drive.

# Finishing Up

## Completing Moonraker Update

Turn the printer off and on. Then, connect to the web interface. In the console, you may see Moonraker prompting you to go to a specific IP address to complete the update.

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/Cxe92aIJ0pubwYqD-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/Cxe92aIJ0pubwYqD-image.png)

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/qnPwfgi6foO3q5m6-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/qnPwfgi6foO3q5m6-image.png)

Type your mks user password and close the window.

[![image.png](https://openqidi.com/uploads/images/gallery/2024-01/scaled-1680-/xzwABfL8tATfr9QD-image.png)](https://openqidi.com/uploads/images/gallery/2024-01/xzwABfL8tATfr9QD-image.png)

## Restoring Settings

The new version of Klipper and Moonraker keep their save settings in a different location. We will copy them there.

```
cp -r ~/klipper_config/* ~/printer_data/config
```

## Connecting Klippy

The location of the klippy\_uds\_address has changed. If it tells you "klippy not connected" this may help repair it. From the web interface, edit moonraker.conf to change it to this:

```klipper-config
klippy_uds_address: ~/printer_data/comms/klippy.sock
```

## Restoring Qidi Gcode functionality

QIDI added a feature that automatically mounted USB drives which is nice. But in their infinite wisdom, they decided to hard-code the location in their client. So, updating Klipper and Moonraker breaks it. There are 2 methods to fix it.

Patch it:

```
sed -i 's/printer_data/gcodes/gcode_files/g' ~/printer_data/systemd/moonraker.env
```

> <span style="color: rgb(53, 152, 219);">This method will keep the functionality and directories as it was, but may break in a future update.</span>

Create a Symlink:

To fix it, a folder needs to be deleted and the old folder symlinked into its place, and the config changed. This method should last longer.

```
rm -r /home/mks/printer_data/gcodes/
```

```
ln -s /home/mks/gcode_files /home/mks/printer_data/gcodes
```

```
sed -i 's:~/gcode_files:~/printer_data/gcodes:g' ~/printer_data/config/printer.cfg
```

## Updating the printer.cfg

Some commands in printer.cfg have been changed. To update them, run:

```klipper-config
sed -i 's:printer.probe\["x_offset"\]:printer.configfile.settings.probe.x_offset:g' ~/printer_data/config/printer.cfg
```

```bash
sed -i 's:printer.probe["y_offset"]:printer.configfile.settings.probe.y_offset:g' ~/printer_data/config/printer.cfg
```

# Precautions and incompatibilities

The versions of Klipper, Moonraker, and Fluidd installed will be updated. Avoid using the Qidi updates, it will overwrite the updated installation and the versions may be incompatible.

> <span style="color: rgb(224, 62, 45);">There is an issue with saving the z offset if you run the official/mainline version of Klipper. The software Qidi runs on the machine saves it's own copy of the zoffset. It interferes with klipper by adding it's copy of the zoffset to klippers zoffset resulting in either printing in the air, or grinding into your print bed.</span>