Work in progress ~ This page is currently being updated frequently. Please submit feedback and ideas to @danielcrosslink on Twitter or leave a comment below. Highly appreciated.
This is a list of optional features or candidates to enable/disable to free up memory in Marlin 2.0 for 8Bit AVR boards. Sometimes each byte can make a difference whether you may be able to build the firmware or not.
In general, the firmware can be shrinked by a good amount (~5%) by just adding some compiler directives in your platformio.ini file to start with as in this article. Then you can do further optimizations as described here below. Newer versions of Marlin firmware have evironment settings called "melzi_optimized", which contain already the above mentioned optimizations so you don't have to make them yourself.
Each line shows how much memory is needed to compile the feature. Actual byte sizes may change with newer versions of Marlin or newer compilers so take them as approximations.
Current investigations show that the minimum size of Marlin 2.0 on an 8Bit AVR like on the Ender 3 (ATMega1284p based CPU) is around 119408 bytes from 130048 bytes of maximum available space (if you keep SDSUPPORT enabled). This is true if the optiboot bootloader is installed. So you will normally have 11000 bytes for additional features (see detailed list below).
You may use up to 131072 bytes of program memory (resulting in 12024 bytes for additional features) if you don't use a bootloader but upload your firmware using a programmer device like the TinyUSBISP or the USPASP directly. Also an Arduino UNO used as an ISP programmer will do the same.
So choose wisely, which features you like to enable - or switch to a processor/architecture that offers more available program memory (more references to alternatives to be added soon).
Let's assume you like to enable MESH_BED_LEVELING with LCD_BED_LEVELING and RESTORE_LEVELING_AFTER_G28 on the Ender 3 for manual mesh bed leveling:
|Ender 3 Initial firmware size (default config)||124398|
|Available program memory||5650|
|MESH_BED_LEVELING required memory||7738|
|LCD_BED_LEVELING required memory||1652|
|RESTORE_LEVELING_AFTER_G28 required memory||16|
|Sum of required additional memory||3756|
|Reclaimed memory from disabling ARC_SUPPORT|
|Reclaimed memory from disabling SHOW_CUSTOM_BOOTSCREEN (in Configuration.h)||764|
|Final memory usage||129632|
Compiling Marlin 2.0 firmware for 8Bit mainboards with only 128KB program memory can be a challenging task especially if you like all the good features of Marlin to be available. Especially if you like to use auto bed leveling probes, you will have to compromise on using other features like the SD-Card support.
You can work around missing SD-Card support for example by using Octoprint on a Raspberry PI connected to your printer via USB. This also has some advantages like being able to pimp your printer with even more exciting features like a Filament runout sensor and a camera to record timelapses.
All in all, the amount of memory used by Marlin 2.0 has increased between 1.1.9 and 2.0. We have another Anet A8 with BLTouch sensor, Auto bed leveling and a full graphical display running version 1.1.9 of Marlin and still have SD-Card support enabled. This is barely possible with version 2.0 by turning off some other features but it's a close call.
List of features in Configuration_adv.h and their memory consumption if ENABLED. Plus sign (+) means, enabling the feature takes MORE memory. Minus (-) means, enabling this feature REDUCES memory usage.
|Line #||Feature name|| Size compiled |
|292||AUTOTEMP||1470||Disable to save memory but print quality may suffer when printing faster.|
|1011||POWER_LOSS_RECOVERY||+ 3010||Needs SDSUPPORT feature|
|1116||SDCARD_READONLY||-2000||Readonly support for SD card. Disables capabilites to write to SD card, so gcode uploading and Power loss recovery won't work.|
|1068||SCROLL_LONG_FILENAMES||+ 202||Disable if you can live with long filenames not scrolling on the display|
|1415||LIN_ADVANCE||+ 3262||Use for better corner quality, needs calibration (see Marlin docs for more infos on Linear Advance).|
|1478||DISABLE_M503||-1500||Disables M503 command, which reports current SRAM values. If you have your printer tuned in and need more memory, disable this.|
|1479||EEPROM_CHITCHAT||638||Disable to save memory. You only need this to see EEPROM messages when connected to serial console.|
|1491||ARC_SUPPORT||+ 3410||Not used by most slicers, disable to save memory|
|2766||NO_VOLUMETRICS||- 612||Enable if you do not intent to use volumetric extrusion features|
|3099||NO_WORKSPACE_OFFSETS||-1566||Remove M428, G92 reverts back to Marlin 1.0 behaviour|
List of feature switches in Configuration.h and their memory consumption if ENABLED. Plus sign (+) means, enabling the feature takes MORE memory. Minus (-) means, enabling this feature REDUCES memory usage.
|Line #||Feature name|| Size compiled|
|74||STRING_CONFIG_H_AUTHOR||+ 112||Can be disabled|
|89||SHOW_BOOTSCREEN||+ 630||Can be disabled|
|92||SHOW_CUSTOM_BOOTSCREEN||+ 764||Can be disabled|
|95||CUSTOM_STATUS_SCREEN_IMAGE||+ 87||Can be disabled|
|1177||AUTO_BED_LEVELING_BILINEAR with FIX_MOUNTED_PROBE (Capacitive, Inductive probes...)||+ 14408||The only way to enable this seems by disabling SDSUPPORT|
|1177||AUTO_BED_LEVELING_BILINEAR with BLTOUCH sensor||+ 15758||The only way to enable this seems by disabling SDSUPPORT|
|1180||MESH_BED_LEVELING||+ 7738||Enable for manual mesh bed leveling feature, LCD_BED_LEVELING is another optional feature if you want LCD menu for setup|
|1186||RESTORE_LEVELING_AFTER_G28||+ 16||Convenience feature, otherwise use M420 S1 after G28 to restore mesh before print (see Marlin docs for more Infos on M420 command).|
|1284||LCD_BED_LEVELING||+ 1652||Convenience for mesh bed leveling with the LCD screen. Use G29 commands otherwise. (see Marlin docs for G29)|
|1292||LEVEL_BED_CORNERS||+ 636||Useful if you like to keep manual bed leveling but do it without moving the nozzle to the corners manually.|
|1632||SDSUPPORT||+ 17492||If you don't need to print from SD card, disable or if you don't need power loss recovery or uploading gcode files to the sd card, use SDCARD_READONLY to get at least 2000 bytes back. You can use Pronterface, Octoprint or other software to print over USB.|
|1688||SLIM_LCD_MENUS||- 5552||Enable to slim the LCD menus to save memory|