How to configure the Marlin Firmware

This "How to" explains the configuration of the Marlin firmware for SMuFF

IMPORTANT:

If you haven't updated your Marlin firmware to version 2.0.x yet, this is the right moment to do so before you start modifying the Marlin source code.

The method I'm describing here targets the usage of the SMuFF in conjunction with my OctoPrint plugin, as described here. From Marlin version 2.0.8.x on, the MMU2 mode supports the SMuFF as well but in this case, the SMuFF needs to be configured for PMMU (Prusa MMU2 Emulation Mode) which acts differently, as you'll see in the pictures below. 

SMuFF Mode using OctoPrint

Prusa MMU2 Emulation Mode

In order to make the SMuFF play along nicely with Marlin, you have to modify a few settings in your printers firmware, recompile and flash it to your printer.
Notice: The easiest way to find all those definitions in VS-Code is by utilizing the Ctrl+Shift+F hotkey (global search) and entering the name of the definition you're looking for.

First of all, you need to tell Marlin you're now having a multi extruder by defining the number of tools used. Set this to the number of tools on your SMuFF but notice that Marlin supports not more then 12 extruders in the latest version (this might change in future releases).

Also, turn on the SINGLENOZZLE feature, since this is the mode the SMuFF is running in.

Next, you have to set up fake steppers to satisfy the Marlin sanity check. 

Do so by duplicating the Ex_STEP_PIN, Ex_DIR_PIN and Ex_ENABLE_PIN in your printers Configuration.h or your controllers Pins.h for each extruder defined in the first step and set them all to the same pin definitions for the first extruder as shown in the picture. 

Next, comment out PREVENT_LENGTHY_EXTRUDE
and redefine the EXTRUDE_MAXLENGTH. Set this value to at least twice the length of your bowden tube going from SMuFF to your printers hotend.

You may leave PREVENT_LENGTHY_EXTRUDE as it is but I've discovered issues, since it didn't work out very well for negative extrusions (a.k.a. retractions).  

Now set option DISABLE_E to false and comment out the DISABLE_INACTIVE_EXTRUDER as well. Both settings do not work well on a shared nozzle/extruder.

Do the same in Configuration_adv.h, because this can interfere with the tool changing operation as well. We don't want the extruder being turned off while printing.

Because the SMuFF became your main extruder now, you also have to adjust the E-Steps of your printer. 

The SMuFF has a geared drive with a gear ratio of 3:1. Therefore, the E-Steps should be in the ballpark of 402-410.
Set it to 410 initially and determine the exact value afterwards by using the well known calibration procedure. Set the exact value utilizing the M92 E GCode command and don't forget to store the new value with M500.

In addition, you may want to enable extra fan speeds in Marlin as well, since this will enable you to modify the part cooling while a tool change is in process. To do so, un-comment the EXTRA_FAN_SPEED option and you'll be able to switch between two fan speeds using M106 T2 / M106 T1 (in OctoPrint tool change GCode scripts for example). 

Finally, enable the option to store/restore positions by the G60/G61 GCodes and set this to 2 (at least), since this feature is being used in the after-/beforeToolChange scripts of OctoPrint. 

Now it's time to compile the Marlin firmware and flash the binary onto the controller of your 3D printer.