Marlin 2.0 program memory usage by feature on AVR 8Bit boards

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).

Sample Calculation

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 memory5650
MESH_BED_LEVELING required memory7738
LCD_BED_LEVELING required memory1652
RESTORE_LEVELING_AFTER_G28 required memory16
Sum of required additional memory3756
Reclaimed memory from disabling ARC_SUPPORT
(in Configuration_adv.h)
Reclaimed memory from disabling SHOW_CUSTOM_BOOTSCREEN (in Configuration.h)764
Final memory usage129632


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
292AUTOTEMP1470Disable to save memory but print quality may suffer when printing faster.
1116SDCARD_READONLY-2000Readonly support for SD card. Disables capabilites to write to SD card, so gcode uploading and Power loss recovery won't work.
1068SCROLL_LONG_FILENAMES + 202Disable if you can live with long filenames not scrolling on the display
1415LIN_ADVANCE + 3262Use for better corner quality, needs calibration (see Marlin docs for more infos on Linear Advance).
1478DISABLE_M503-1500Disables M503 command, which reports current SRAM values. If you have your printer tuned in and need more memory, disable this.
1479EEPROM_CHITCHAT638Disable to save memory. You only need this to see EEPROM messages when connected to serial console.
1491ARC_SUPPORT+ 3410Not used by most slicers, disable to save memory
2766NO_VOLUMETRICS- 612Enable if you do not intent to use volumetric extrusion features
3099NO_WORKSPACE_OFFSETS-1566Remove 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
74STRING_CONFIG_H_AUTHOR + 112Can be disabled
89SHOW_BOOTSCREEN + 630Can be disabled
92SHOW_CUSTOM_BOOTSCREEN + 764Can be disabled
95CUSTOM_STATUS_SCREEN_IMAGE + 87Can be disabled
1177AUTO_BED_LEVELING_BILINEAR with FIX_MOUNTED_PROBE (Capacitive, Inductive probes...) + 14408The only way to enable this seems by disabling SDSUPPORT
1177AUTO_BED_LEVELING_BILINEAR with BLTOUCH sensor+ 15758The only way to enable this seems by disabling SDSUPPORT
1180MESH_BED_LEVELING + 7738Enable for manual mesh bed leveling feature, LCD_BED_LEVELING is another optional feature if you want LCD menu for setup
1186RESTORE_LEVELING_AFTER_G28 + 16Convenience feature, otherwise use M420 S1 after G28 to restore mesh before print (see Marlin docs for more Infos on M420 command).
1284LCD_BED_LEVELING + 1652Convenience for mesh bed leveling with the LCD screen. Use G29 commands otherwise. (see Marlin docs for G29)
1292LEVEL_BED_CORNERS+ 636Useful if you like to keep manual bed leveling but do it without moving the nozzle to the corners manually.
1632SDSUPPORT + 17492If 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.
1688SLIM_LCD_MENUS- 5552Enable to slim the LCD menus to save memory