Marlin Configuration.h: the settings you will actually change, and how to test them safely
By Sina Esfahani, OmniTechs · Published 30 November 2026
Marlin keeps its settings in two text files that you edit before you build the firmware. Configuration.h holds the hardware: board, drivers, motor directions, endstops, bed size and temperatures. Configuration_adv.h holds the extras: the hotend fan pin, a second Z motor, custom menus, EMERGENCY_PARSER and the buffers. A line that starts with #define is on; a line that starts with // is off.
After an upgrade you change only a handful of these lines. Start from the example configuration for your printer and board, change one thing at a time, and test with small moves and a hand near the power switch before you print.
Change it in this order:
Save your current settings: send M503 and keep the text. It lists your steps, PID values and offsets.
Download the example configuration for your printer and exact board, from the branch that matches your Marlin version (release-2.1.3 for Marlin 2.1.3).
Find each option by searching both files for its exact name, and read the comment above it.
Change one option, build and flash, then send M502 and M500 so the new defaults replace the old stored values.
Test cold: M119 for the endstops, a 10 mm jog with G91 and G1 X10, then G28 X, G28 Y and G28 Z one at a time.
Leave THERMAL_PROTECTION_HOTENDS, THERMAL_PROTECTION_BED and THERMAL_PROTECTION_CHAMBER enabled, whatever else you change.
What did you change? Find your options here
Upgrades and the Marlin options they touch
| What you changed | Options to check | First test |
|---|---|---|
| New board or drivers | MOTHERBOARD, X_DRIVER_TYPE to E0_DRIVER_TYPE, INVERT_X_DIR to INVERT_E0_DIR | Jog 10 mm per axis; M122 for TMC on UART or SPI |
| An axis runs the wrong way | INVERT_X_DIR, INVERT_Y_DIR, INVERT_Z_DIR, INVERT_E0_DIR | A positive jog moves away from the switch |
| Second Z motor | Z2_DRIVER_TYPE; INVERT_Z2_VS_Z_DIR, Z_MULTI_ENDSTOPS (adv) | Both lead screws lift on G1 Z5 |
| A dead driver socket | Pin definitions in the board's pins file | The motor moves from its new socket |
| New endstops | X_HOME_DIR, X_MIN_ENDSTOP_HIT_STATE | M119: open, then TRIGGERED by hand |
| Bigger bed or taller frame | X_BED_SIZE, Y_BED_SIZE, X_MIN_POS, X_MAX_POS, Z_MAX_POS | Slow moves to the far limits |
| Hotter hotend | HEATER_0_MAXTEMP | Heat in steps, then PID tune |
| Hotend fan on its own header | E0_AUTO_FAN_PIN (adv) | M104 S60: the fan starts at 50 °C |
| Heated chamber | TEMP_SENSOR_CHAMBER, HEATER_CHAMBER_PIN (adv) | M141 S40 while you watch |
| Your own menu items | CUSTOM_MENU_MAIN (adv) | Run the item with the printer idle |
| Stop and cancel react late | EMERGENCY_PARSER, BLOCK_BUFFER_SIZE (adv) | M108 ends a heating wait at once |
Find an option, and start from the right example
Search both files for the exact option name (Ctrl+F) and read the comment above it. The Settings reference on marlinfw.org lists every option with its default and requirements.
Start from the MarlinFirmware Configurations repository: config/examples, then the maker, the printer and the board. Pick the branch that matches your Marlin exactly, release-2.1.3 for Marlin 2.1.3, and copy both files over Marlin's own.
Option names change between versions. If a build stops on a name it no longer knows, the error message or Marlin's Obsolete Options list gives its replacement. Two you will meet: CUSTOM_USER_MENUS became CUSTOM_MENU_MAIN after 2.0.7.5, and X_MIN_ENDSTOP_INVERTING (false or true, 2.1.2 and older) became X_MIN_ENDSTOP_HIT_STATE (HIGH or LOW) in 2.1.3.
Some printers run the maker's own modified Marlin, with no upstream example. On the Creality Forum, Ender-3 V3 SE owners found no example, and one reported that a self-built Marlin lost contact with the stock screen. Creality published the SE source on GitHub in July 2024. Start from the maker's source when one exists; without it, stay on the maker's firmware.
Keep your changes in Git or a list. Ed's 3d Tech compares an example configuration in VS Code and Beyond Compare.
Drivers and motors: type, direction and spare sockets
Driver type and direction
Each driver socket has a *_DRIVER_TYPE line that tells Marlin which chip sits there, so it uses the right step timing. Use TMC2209 when the driver's UART wire is connected, and TMC2209_STANDALONE when it is jumpered for standalone; a standalone driver takes its current from its potentiometer. After switching to a UART or SPI type, send M122: "Error: All LOW" points to a wrong driver type or no communication (Marlin). Setting the current is covered in stepper motors and drivers.
The direction flags depend on the board, not only the printer:
One printer, four boards: Ender-3 examples for Marlin 2.1.3
| Board in the example | Driver type | INVERT_X_DIR | INVERT_Y_DIR | INVERT_Z_DIR | INVERT_E0_DIR |
|---|---|---|---|---|---|
| Creality V1 (Melzi) | A4988 | true | true | false | true |
| Creality V4.2.2 | A4988 | false | false | true | false |
| Creality V4.2.7 | TMC2208_STANDALONE | false | false | true | false |
| BigTreeTech SKR Mini E3 3.0 | TMC2209 | true | true | false | true |
Same frame, same motors, yet every flag flips between the V4.2.2 and the SKR Mini E3 3.0. After a board swap, take the flags from the new board's example, not from your old file. If one axis still runs backwards, change its INVERT_ line between true and false and rebuild, or turn that motor plug round with the printer switched off and unplugged. Marlin warns that a reversed axis can cause damage: test without belts if you can, with the carriage and bed in the middle. A motor that does not move at all is covered in motor not moving or turning the wrong way.
A second Z motor on a spare socket
Define Z2_DRIVER_TYPE in Configuration.h with the type of driver in the spare socket. Unless the board's pins file gives Z2 a socket of its own, Marlin assigns Z2 to the next free extruder socket; with EXTRUDERS set to 1 that is E1. Do not define an extra E driver for it: Marlin warns that enabling E2_DRIVER_TYPE for this can harm the machine. In Configuration_adv.h, enable INVERT_Z2_VS_Z_DIR if the second motor turns the other way. If each Z motor has its own endstop, enable Z_MULTI_ENDSTOPS: Z2_STOP_PIN sets its pin (X_MAX_PIN by default), M666 the offset between them and M500 saves it.
Test with G91, then G1 Z5. Both lead screws must lift the gantry together. If one side goes down, switch off at once and invert Z2.
A dead driver socket
Marlin has no option to move an axis to a spare socket. The answers on the 3D Printing Stack Exchange swap the pin definitions instead: on a RAMPS board, exchange the E0 and E1 lines in pins_RAMPS.h (or X and E1), rebuild and move the motor plug. With sensorless homing, swap the DIAG pins too. Switch the printer off and unplug it before you move a driver or a plug.
Endstops, bed size and travel limits
X_HOME_DIR says where the switch sits: -1 at the low end, 1 at the high end. X_MIN_ENDSTOP_HIT_STATE says whether a pressed switch reads HIGH or LOW; if M119 shows TRIGGERED while the switch is free, flip it and rebuild. Homing faults have their own guide: homing failed.
X_BED_SIZE and Y_BED_SIZE are the printable area, with 0,0 at the front-left corner. X_MIN_POS, X_MAX_POS and Z_MAX_POS are how far the nozzle may travel after homing. If the carriage can move past the bed edge, a negative minimum keeps the whole bed reachable; for a taller frame, set Z_MAX_POS to the highest point the nozzle really reaches. Keep MIN_SOFTWARE_ENDSTOPS and MAX_SOFTWARE_ENDSTOPS enabled: they clip every move to those limits, and M211 reports their state.
To check new limits, home, then move slowly to each far edge, for example G1 X235 F1500 on a 235 mm bed. The nozzle should stop at the edge without grinding. Where X0 Y0 lands is covered in print not centred.
Hotter hotend, hotend fan and heated chamber
Maximum temperature. Marlin limits every hotend target to HEATER_0_MAXTEMP minus HOTEND_OVERSHOOT (15 °C). With the default maximum of 275 °C, the highest target you can set is 260 °C. To print at 300 °C, set HEATER_0_MAXTEMP to 315 (300 + 15), but only if the heater block, thermistor and heat break are rated for it and the thermistor table goes that high (Marlin). A new thermistor type also needs its number in TEMP_SENSOR_0. Then tune the heater: PID tuning. Never weaken the thermal protection to get there; the thermal runaway guide explains what to check instead.
Hotend fan. The stock Configuration_adv.h sets E0_AUTO_FAN_PIN to -1, which means none. Give it the pin your hotend fan is plugged into, by its name in the board's pins file; on a board with a second fan header, FAN1_PIN is the common case. That header then stops being a part-cooling fan. Never use the part-cooling fan pin: the slicer turns that fan off for the first layers, the heat sink gets no air, the filament softens too high up and the extruder jams (Marlin). Leave EXTRUDER_AUTO_FAN_TEMPERATURE at 50 °C unless your hotend's maker says otherwise. Test it cold: after M104 S60 the fan starts within a few seconds of the hotend passing 50 °C, and after M104 S0 it runs until the hotend drops below 50 °C. Other fans are in 3D printer fans.
Heated chamber. Set TEMP_SENSOR_CHAMBER in Configuration.h to the number of the chamber sensor (0 means none), and HEATER_CHAMBER_PIN in Configuration_adv.h to the output that switches the heater; Marlin marks that pin as required. CHAMBER_MAXTEMP is 60 °C by default. THERMAL_PROTECTION_CHAMBER stays on: it halts the printer if the chamber stays more than 2 °C below target for 20 s. Set a target with M141 S40, or wait for it with M191; CHAMBER_AUTO_FAN_PIN switches a vent fan on at 30 °C. If the heater switches mains through a relay, leave that wiring to a qualified electrician, always unplug first, and watch the first heat-ups from start to finish.
Your own menu items: CUSTOM_MENU_MAIN
In Configuration_adv.h, remove the // in front of #define CUSTOM_MENU_MAIN. Each item is a pair: MAIN_MENU_ITEM_1_DESC is the label and MAIN_MENU_ITEM_1_GCODE the commands, separated by \n. Marlin allows up to 25 items; how many show depends on the display.
Worked example. The file already holds a commented-out fifth item. Uncomment MAIN_MENU_ITEM_5_DESC "Home & Info" and MAIN_MENU_ITEM_5_GCODE "G28\nM503", rebuild, and the menu gains an entry that homes the printer and reports its settings.
Leave CUSTOM_MENU_MAIN_ONLY_IDLE on, as it is by default, so the menu only appears while the printer is idle: an item runs exactly what you wrote, and a G28 mid-print would ruin the print. MAIN_MENU_ITEM_1_CONFIRM adds a confirmation step. PREHEAT_1_LABEL and its siblings give up to 10 preheat presets, and LCD_ENDSTOP_TEST adds an endstop test to the Debug Menu.
Chris Riley builds custom menus for tool changes; the link starts at his custom menus chapter.
EMERGENCY_PARSER and the buffers: when stop reacts late
A command from your host normally waits its turn, so M112 may wait for a free slot before it shuts the printer down. With EMERGENCY_PARSER enabled in Configuration_adv.h, Marlin catches M108, M112, M410 and M876 the moment they arrive over the serial or USB line. It does not work on boards with AT90USB processors. M108 needs it to break out of a heating wait (M109, M190, M191). M112 turns off heaters and steppers and needs a reset; Marlin stresses it is not a safety-rated emergency stop, so keep the power switch within reach.
Marlin has two queues. BUFSIZE is the number of command lines waiting, 4 by default, each up to MAX_CMD_SIZE (96 characters). BLOCK_BUFFER_SIZE is the number of planned moves, 16 by default and always a power of two. Leave both alone unless you see a symptom:
The printer keeps moving after you cancel from the host: those are queued moves. A smaller BLOCK_BUFFER_SIZE shortens the run-on, but EMERGENCY_PARSER with M410 or M112 is the direct fix.
RX_BUFFER_MONITOR reports a receive buffer overflow: Marlin's advice is to increase RX_BUFFER_SIZE.
Test every change safely
Before flashing, save the output of M503.
After flashing, send M502, then M500. Otherwise the old values stored in the printer's memory (EEPROM) stay in force (Marlin). M502 also resets your tuned steps, PID values and offsets: re-enter them from your list, send M500, and check with M503.
After a direction or driver change, take the belts off if you can and move the carriage and bed to the middle.
Send M119: each free switch reads open, each switch you hold reads TRIGGERED.
Send G91, then G1 X10 (and Y, Z): a positive move goes away from the switch. Send G90 afterwards.
Home one axis at a time, G28 X, G28 Y, G28 Z, with a hand near the power switch (Marlin).
Heat up while you watch.
If a step fails, undo the one change you made and rebuild. Commands such as M503 and G91 are explained in G-code commands you will edit.
When to stop
The unmodified example will not build: fix that first, then add your changes back one by one.
A driver or socket burnt out: the pin swap is a stopgap, not a repair. Replace the board.
Your printer runs the maker's own firmware and no source is published: stay on it.
An error tempts you to switch off thermal protection: do not. Find the physical cause.
Next step and related guides
Building and flashing, with the backup and restore routine, is in Marlin vs Klipper vs stock firmware. If a part for the upgrade, such as a fan duct or a bracket, is easier to order than to print while the printer is apart, the 3D printing service prints PLA and PETG parts from your file.

