This page gives RepRapFirmware’s M-codes for jobs, files, macros and
saved settings, and those below M104 for spindle, laser, motors, pins
and power, from the Duet3D G-code dictionary as read on 3 December 2026. Line rules
and moves are on RepRapFirmware
syntax and motion. Version numbers are RepRapFirmware (RRF) versions.
M0, M1 and M2: stop
None needs a parameter. From 3.5 the three end the job in the same way
(M2 exists from 3.5.0), after finishing the buffered moves:
Where M0 comes from | Effect (3.5 and later) |
|---|---|
| The job file | The job ends and stop.g runs if present. From 3.5.0 stop.g also runs when a file simply finishes |
Another input, job paused (M25) or, from 3.7.1, held (M25.1) | The job is cancelled and cancel.g runs, or stop.g if there is no cancel.g, homed or not |
| Another input, job neither paused nor held | Nothing happens; the reply asks for the print to be paused first |
If neither file exists all heaters are turned off. The motors stay on until the
normal idle timeout, then drop to the idle current of M906 I.
| 3.4 and earlier | Effect |
|---|---|
M0 | Finishes the moves; runs cancel.g if the axes are homed and the print is paused, otherwise stop.g; idles all motors; turns heaters off if the file is missing. Before 3.4, H1 keeps the heaters on |
M1 | Finishes the moves, runs sleep.g if present and sets the motors to idle current. Heaters go off if sleep.g is missing (3.4), or always unless H1 is given (3.3 and earlier) |
With Marlin emulation, M1 from a serial port or Telnet acts as
M25; otherwise sleep.g runs before all heaters and
drives are turned off. A later G or M code wakes the
machine.
M3, M4 and M5: spindle and laser
These exist in CNC mode from 1.20, in laser mode (M3 and
M5) from 2.01, and in FFF mode from 3.5.
| Code | Parameters | Effect with a spindle |
|---|---|---|
M3 | S RPM, P spindle number | Run clockwise. Without parameters, the current tool’s spindle at the tool’s speed; S also sets that speed. An error if there is no P and no active tool with a spindle |
M4 | S, P (P in CNC mode only) | As M3, counterclockwise |
M5 | none | Stop the current tool’s spindle, or all spindles if there is no active tool or it has none |
FFF mode drives a spindle defined beforehand as CNC mode does, and has no laser.
In laser mode S is the power, 0 to 255, on a scale that depends on
M452 R:
- From 3.x with non-sticky power (
M452 S0, where eachG1needs its ownS, default 0),M3andM5are redundant. - With sticky power (
M452 S1),M3 S255sets the power for laterG1moves untilM3 S0,M5or, from 3.5,G1 S0.M3alone does not fire the laser, andM3withoutSis an error. - In 2.01 to 2.05.1,
M3 Ssets the power beforeG1moves.
For raster engraving the power on G1 is preferable: the queue for
M-commands holds 8 entries against 20 moves, so repeated
M3 may stutter.
M17, M18 and M84: motors
| Code | Parameters | Effect |
|---|---|---|
M17 (3.3 and later) | X Y Z U V W and further axes as flags, E or Ea:b extruder drives, S idle timeout in seconds (3.5 and later) | Enable the named motors, or all without parameters. S without axes or extruders enables none. Used for example before stealthChop tuning, followed by G4 P100 |
M18 | the same | Disable the named motors, or all without parameters; S alone disables none. Axes whose motors are disabled are no longer homed |
M84 (deprecated from 3.6) | S idle timeout in seconds, axis letters, E | As M18, or set the idle timeout. S0 is not valid; to keep full holding, set M906 I100. Use M18 and M906 T instead |
M20: list files
| Parameter | Meaning |
|---|---|
S | Reply style: 0 text (default), 2 JSON, 3 JSON with details |
P"path" | Folder, by default 0:/gcodes |
R | Number of entries to skip, default 0 (S2 and S3) |
C | Most entries to return (S2 and S3, from 3.6.0) |
Long file names are returned. With Marlin compatibility the text list stands
between Begin file list and End file list; without
emulation it follows GCode files: as quoted names separated by
commas. The S2 reply has dir, first (the
number skipped), files (names, a directory marked with a leading
asterisk), next (the number to skip for the next block, zero when
done) and err. In S3 each entry of files
has type, name, size and
date.
M20 S2 P"/gcodes"
{"dir":"/gcodes","first":0,"files":["Hinged_Box.gcode","*Calibration pieces"],"next":0,"err":0}
M21 and M22: mount and release
| Code | Standalone | With a single board computer (SBC, 3.4 and later) |
|---|---|---|
M21 | Initialise SD card P (default 0). A card present at power on is initialised anyway | Mount: P device or remote endpoint, S local directory (optional if the device is in /etc/fstab), T mount type, O mount options |
M22 | Release SD card P (default 0); advisable before removing it | Unmount P |
The SBC forms need the DuetPiManagementPlugin and belong in
dsf-config.g, not config.g.
M21 P"192.168.1.222:3D" S"0:/gcodes/remote" T"nfs"
M23, M24, M26 and M32: select, start and position
M23 file selects a file for printing (long and 8.3
names; a full path of at most 120 characters). M32 file
selects and starts it. M24 starts the selected file or resumes a
paused print, running resume.g first; to restart a file from the
beginning, select it again.
M24 P0(3.3 and later) resumes withoutresume.g.- From 3.7.1
M24also releases a feed hold: it first returns to the held position if axes were jogged, and does not runresume.g. A job paused before the hold stays paused until a secondM24. It is rejected while a feed hold input (M581 K3) is still active. resume.gdoes not run if an axis is not homed. If axes were homed at the pause and no longer are, resuming cancels the print, unlessM564allows moves without homing, in which case it resumes withoutresume.g.
M26 sets the position in the selected file, as used after a power
failure:
| Parameter | Meaning |
|---|---|
S | Byte offset from the start of the file, at the start of a command |
P | Optional share of the first move to skip, default 0.0, below 1.0 |
C | Optional (3.7 and later, laser and CNC modes): the G0 to G3 (0 to 3) in effect there, for files whose lines omit the command; resurrect.g records it |
X Y Z | Optional: start coordinates when the command there is G2 or G3 and P is not zero |
M25, M226 and M25.1: pause and feed hold
M25 pauses the job from another source (console, panel, macro);
M226 is the one to put in the job file, since it first completes all
earlier commands of its input. Both run pause.g;
M226 P0 pauses without it. M600 is the pause for a
filament change.
- Up to 3.6,
M25stops after a queued move at which the jerk limits allow stopping without deceleration; failing that it completes the queue and any segmented move in progress. - From 3.7 it completes the executing and committed moves, then if needed turns
queued moves into decelerating ones, discards the rest and reads them again on
resume. With third-order motion control the whole queue is completed. Move
segmentation (
M669 S) makes the pause quicker. - A pause asked for during a macro waits for the macro to end. With an axis not
homed the machine pauses but
pause.gdoes not run.M25is rejected during a feed hold.
M25.1 (3.7.1 and later) is a feed hold: it stops all motion,
including moves from macros and consoles, runs no macro file, leaves heaters,
spindles and fans alone and sets the status to held.
M24 carries on. M25.1 S1 discards the queue and aborts
the job and all macros, turning all heaters off without stop.g or
cancel.g; motors stay on and axes stay homed, except any being
homed.
- A
G1 H1homing move stops at once andM24completes it; probing moves (G30,G38,G1 H3andH4) finish first. - It is not allowed in the job file, is ignored in simulation, and can also be
raised by an input (
M581 K). Over USB, HTTP and Telnet it and the releasingM24act as soon as received. - During a hold,
G0andG1from another input jog the machine (not arcs, homing, probing or extrusion, and not with third-order motion control);M24moves back first, with statusresuming. Moves from macros wait. The input used must not be the one running the held macro. - Unless the job is paused, the held position is saved in restore point 1.
M27 to M30, M559, M560 and M470 to M472: status and files
| Code | Parameters | Effect |
|---|---|---|
M27 | none | Reply SD printing byte done/size, or Not SD printing. |
M28 | file name | Write all following lines from the same input to the file, until M29; without a path, in /gcodes. Reply Writing to file: name or an error |
M29 | none | Close the file; with Marlin emulation the reply is Done saving file. |
M30 | file name, quoted or not | Delete the file |
M559 | P"file", S size in bytes, C CRC-32 | Upload any file, binary allowed, over USB or serial; without a path, to /sys |
M560 | the same | As M559, to /www |
M470 (2.03 and later) | P"name" | Create a directory, by default on the first card |
M471 (2.03 and later) | S"old", T"new", D1 | Rename or move, across directories but not between cards; D1 replaces an existing target |
M472 (3.5 and later) | P"name", R | Delete a file or directory; R1 deletes recursively (default 0) |
For uploads with M559 or M560, the sender waits for
Writing to file: and then sends the content: exactly S
bytes, or, if S is absent or zero, the content followed by
<!-- **EoF** -->, which the file itself then cannot contain.
C is decimal or hexadecimal in braces
(C{0x9abcdef0}; without braces it reads as zero); absent or zero,
nothing is checked. A mismatch replies CRC32 checksum doesn't match
and keeps the file as received. The final reply is empty, or
Done saving file. in Marlin emulation. From 3.2 the name must be
given and quoted; in 3.1 and earlier it defaulted to config.g (for
M560, reprap.htm).
- From 3.6.5 and 3.7.1, closing the USB port during an
M28orM559upload aborts it and deletes the partial file. Earlier, later commands went into the file. Duet 2 WiFi, Ethernet and Maestro do not detect the closed port duringM559. - With an SBC,
M28to a serial port of the main board works only from 3.6.5 and 3.7.1.M559works to such a port; through the SBC software only on code stream connections of version 3.7.1 and later, where a CRC mismatch keeps the previous file.
M36, M38 and M39: file and card information
M36 "file", or M36 for the job being printed, returns
JSON. err is zero on success and size (bytes) is then
always present; the rest depends on what is found in the file, in any order:
| Field | Content |
|---|---|
fileName | The file (before 3.4 not given when a file was named) |
lastModified | Date and time |
height, layerHeight | mm |
numLayers | Number of layers (3.4 and later) |
printTime, simulatedTime | Seconds: the slicer’s estimate and the simulated time |
filament | Array of lengths in mm, one per spool |
generatedBy | Slicer |
thumbnails | (3.4 and later) array of width, height, format (png, qoi or jpeg), offset, size; empty if none |
customInfo | (3.6 and later) values from ;customInfo comments |
printDuration | Without a file name: seconds the job has run |
| Code | Parameters | Reply |
|---|---|---|
M36.1 | P"file", S byte offset | JSON thumbnail with fileName, offset, data (base64, whole or part), next (offset of the rest, or zero) and err. Start at the offset from M36 |
M36.2 (3.6.1 and later) | P"file", S byte offset, 0 at first | JSON fragment with the same fields, data being height map text with line breaks written \n |
M38 file (3.6 and later) | CRC-32 of the file in hexadecimal, or Cannot open file: and the name. Up to 3.5.1 it gave SHA-1; that was removed in 3.5.2 | |
M39 (1.21 and later) | P slot (default 0), S0 text, S2 JSON | Card capacity, partition size (3.4 and later in JSON), free space, speed and cluster size; JSON object SDinfo in bytes and bytes per second |
M37 and M73: simulation and progress
M37 simulates, computing the job time under the configured speeds
and accelerations without acting on the commands.
| Form | Effect |
|---|---|
M37 P"file" | Simulate the file and report the time; F1 (default) stores it in the file, F0 does not |
M37 Sn | Enter mode n: 1 debug, 2 normal, 3 partial; the time is computed in modes 1 and 2 |
M37 S0 | Leave simulation and print the total time |
M37 | Print the time so far, or of the ended simulation |
M73, written by some slicers, takes R minutes remaining
and, from 3.6.0, C minutes until the user is needed.
P, the percentage done, is not used.
M42, M80 and M81: pins and power
M42 Pport Svalue sets a general
output. S is 0.0 to 1.0, or above 1 up to 255. From 3.x
P is a port created with M950 (none exists by default),
where the PWM frequency (Q) and inversion (! before the
pin name in C) are set too. In 2.x P is a logical pin
number, with optional F frequency and I1 to
invert.
M950 P0 C"out3" Q500 ; port 0 on pin out3, 500 Hz
M42 P0 S0.5 ; 50% PWM
| Code | Parameters | Effect |
|---|---|---|
M80 | C"pin" (3.4.0 and later; ! inverts) | Turn the power supply on, cancelling a deferred power off |
M81 | C"pin" (3.4.0 and later), S0 now (default) or S1 when all thermostatic fans are off (1.20 and later), D delay in seconds (3.5 and later) | Turn the supply off once the move queue is empty. With D and S1, whichever is later |
From 3.4 both report an error unless a power pin has been assigned with
C, normally in config.g.
M81 C"pson" only assigns the pin; M80 C"pson" assigns it
and turns the power on.
M82, M83 and M92: extrusion mode and steps
M82 reads E as absolute positions (the default),
M83 as relative lengths, which the documentation strongly
recommends, above all with several tools. Each input channel keeps its own
setting, taken from the end of config.g; a macro restores it on
exit, a job file does not.
In absolute mode one virtual extruder position, shown as E by
M114 and as move.virtualEPos, serves all tools; it is
set by G92 E and reset when a print starts. After a tool change it
can therefore turn the next move into a retraction unless
G92 E0 is used or the value is saved per tool.
M92 sets steps per mm: X Y Z U V W, E
(colon separated for several drives) and S (2.03 and later), the
microstepping the values refer to, by default that of M350. Without
parameters it reports. Values return to config.g’s at power on; all
motors of one axis share one value; further axes must first be created with
M584.
M98 and M99: macros
| Code | Parameters | Effect |
|---|---|---|
M98 | P"file", further letters passed to the macro (3.3 and later) | Run a macro file; relative paths start at /sys, 0:/ and 1:/ name the cards. Quotes are required from 3.x |
M98 Rn (3.4 and later) | inside a macro, without P | R1: the rest of the macro may be paused, and it restarts from the beginning on resume; R0 (default) it may not. Not for system macros such as tool change, homing, pause.g or resume.g |
M99 | none | Return from the macro; not needed at the end of a file |
Macros nest. From 3.4.0 the stack depth is 10, counting M120 and
daemon.g; open files are also limited, to 20 on Duet 3 and 10 on
Duet 2.
M101 to M103: Simplify3D retraction
Accepted for files made with Simplify3D’s option to generate these codes:
M101 unretracts as G11, M103 retracts as
G10 without parameters, and M102 is ignored.
M486: object cancellation
Supported from 3.1. Objects are numbered from 0.
| Form | Effect |
|---|---|
M486 Tn | Number of objects (otherwise counted) |
M486 Si A"name" | Object i starts here, optionally named once; S-1 marks purge towers and other parts that are not objects |
M486 Pi, Ui | Cancel, restore object i |
M486 C | Cancel the current object |
M486 | List the objects |
For a cancelled object the X, Y and Z movement of G0 to
G3 and G5 is skipped, while F and the
E position are still tracked, without extrusion. Object label
comments in the file, such as PrusaSlicer’s, make M486 S
unnecessary: objects are then numbered in order of first appearance.
M409 returns the list from the object model.
M500 to M505.1: saved settings and folders
| Code | Effect |
|---|---|
M500 (1.17 and later) | Write sys/config-override.g: M665 and M666 calibration (linear delta, rotary delta, Hangprinter), M307 heater models, M208 limits found by probing or endstops, G10 workplace offsets and probed tool offsets. P31 adds the probe values of G31, P10 all tool offsets, P10:31 both, P68 the rotation (3.6.1 and later) |
M501 | Load that file; put it near the end of config.g, without which M500 saves but warns |
M502 | Run config.g ignoring M501. The override file is kept; M502 then M500 discards saved changes for good |
M503 | Reply with the settings in sys/config.g as commands; may be truncated and leaves out the override file |
M505 P"folder" | Take system files from this folder instead of /sys (relative to the current one); an error if missing. Without P, report it |
M505.1 P"folder" | Change the web server root, by default 0:/www; without P, report it. Marked temporary, for development |
M929: event log
M929 P"file" S1 starts logging events to the card, appending if the
file exists; P is optional and S0 stops. From 3.2.0
S1, S2 and S3 choose the levels
WARN, INFO (adds G10, M117,
M291, M292) and DEBUG (everything). Do not
rename or delete the file while logging.
Sources
- G-code dictionary – Duet3D’s documentation of RepRapFirmware’s commands, published under a Creative Commons attribution share-alike licence; this page is written in our own words