# sphawes/marlin architecture

> Architecture diagram of the GitHub repository sphawes/marlin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sphawes/marlin
- Repository: https://github.com/sphawes/marlin

## Overview

Marlin is configurable 3D-printer firmware supporting a broad range of microcontroller platforms and Linux-native execution. The user-facing workflow is a host sending commands over a printer interface; firmware interprets commands, plans motion and controls printer hardware, while thermal control and media-based printing support the job. Configuration and the hardware abstraction layer adapt shared firmware behavior to boards and peripherals. The tree and excerpts establish these components, but do not expose the main command-dispatch path, so workflow links that lack direct evidence are marked unverified.

Main entry points: [`Marlin/src/MarlinCore.cpp`](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/MarlinCore.cpp) (Firmware core), [`Marlin/src/HAL/HAL.h`](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/HAL.h) (Hardware abstraction), [`Marlin/src/inc/MarlinConfigPre.h`](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/inc/MarlinConfigPre.h) (Config selection), [`Marlin/src/feature/controllerfan.cpp`](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/feature/controllerfan.cpp) (Controller fan)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Configuration"]
  node_config["Printer settings<br/>[Configuration.h]"]
  node_advanced_config["Advanced settings"]
  node_config_pre["Config selection<br/>[MarlinConfigPre.h]"]
  node_config_runtime["Runtime config<br/>[MarlinConfig.h]"]
end

subgraph group_runtime["Firmware runtime"]
  node_firmware["Firmware core<br/>[MarlinCore.cpp]"]
  node_gcode["G-code parser<br/>[parser.h]"]
end

subgraph group_printer_control["Printer control"]
  node_planner["Motion planner<br/>[planner.h]"]
  node_stepper["Stepper control<br/>[stepper.h]"]
  node_temperature["Thermal control<br/>[temperature.h]"]
  node_bed_leveling["Bed leveling<br/>[bedlevel.cpp]"]
  node_controller_fan["Controller fan<br/>[controllerfan.cpp]"]
end

subgraph group_media_ui["Media and interfaces"]
  node_media["Media reader<br/>[cardreader.h]"]
  node_usb_storage["USB mass storage<br/>[masstorage.cpp]"]
  node_display["Printer display"]
end

subgraph group_platform["Hardware platforms"]
  node_hal["Hardware abstraction<br/>[HAL.h]"]
  node_avr_hal["AVR platform<br/>[HAL.cpp]"]
  node_stm32_hal["STM32 platform<br/>[HAL.cpp]"]
  node_esp32_hal["ESP32 platform<br/>[HAL.cpp]"]
  node_linux_hal["Linux platform<br/>[HAL.cpp]"]
end

node_host(("Host"))

node_host -.->|"sends commands"| node_firmware
node_config_pre -->|"includes settings"| node_config
node_config_pre -->|"includes settings"| node_advanced_config
node_config_runtime -->|"includes prefix"| node_config_pre
node_firmware -.->|"dispatches commands"| node_gcode
node_gcode -.->|"requests motion"| node_planner
node_planner -.->|"queues steps"| node_stepper
node_firmware -.->|"manages heating"| node_temperature
node_firmware -.->|"applies leveling"| node_bed_leveling
node_controller_fan -->|"reads axis state"| node_stepper
node_controller_fan -->|"reads thermal state"| node_temperature
node_media -.->|"uses USB storage"| node_usb_storage
node_firmware -.->|"reads print files"| node_media
node_host -.->|"uses controls"| node_display
node_firmware -.->|"uses platform services"| node_hal
node_hal -.->|"selects platform"| node_avr_hal
node_hal -.->|"selects platform"| node_stm32_hal
node_hal -.->|"selects platform"| node_esp32_hal
node_hal -.->|"selects platform"| node_linux_hal

click node_config "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/Configuration.h"
click node_advanced_config "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/Configuration_adv.h"
click node_config_pre "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/inc/MarlinConfigPre.h"
click node_config_runtime "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/inc/MarlinConfig.h"
click node_firmware "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/MarlinCore.cpp"
click node_gcode "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/gcode/parser.h"
click node_planner "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/module/planner.h"
click node_stepper "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/module/stepper.h"
click node_temperature "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/module/temperature.h"
click node_bed_leveling "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/feature/bedlevel/bedlevel.cpp"
click node_controller_fan "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/feature/controllerfan.cpp"
click node_media "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/sd/cardreader.h"
click node_usb_storage "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/sd/usb_flashdrive/lib-uhs2/masstorage.cpp"
click node_display "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp"
click node_hal "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/HAL.h"
click node_avr_hal "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/AVR/HAL.cpp"
click node_stm32_hal "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/STM32/HAL.cpp"
click node_esp32_hal "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/ESP32/HAL.cpp"
click node_linux_hal "https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/LINUX/HAL.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_advanced_config,node_config_pre,node_config_runtime toneBlue
class node_firmware,node_gcode toneAmber
class node_planner,node_stepper,node_temperature,node_bed_leveling,node_controller_fan toneMint
class node_media,node_usb_storage,node_display toneRose
class node_hal,node_avr_hal,node_stm32_hal,node_esp32_hal,node_linux_hal,node_host toneIndigo
```

## Components

### Configuration

- [Printer settings](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/Configuration.h): `Marlin/Configuration.h`
- [Advanced settings](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/Configuration_adv.h): `Marlin/Configuration_adv.h`
- [Config selection](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/inc/MarlinConfigPre.h): `Marlin/src/inc/MarlinConfigPre.h`
- [Runtime config](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/inc/MarlinConfig.h): `Marlin/src/inc/MarlinConfig.h`

### Firmware runtime

- [Firmware core](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/MarlinCore.cpp): `Marlin/src/MarlinCore.cpp`
- [G-code parser](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/gcode/parser.h): `Marlin/src/gcode/parser.h`

### Printer control

- [Motion planner](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/module/planner.h): `Marlin/src/module/planner.h`
- [Stepper control](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/module/stepper.h): `Marlin/src/module/stepper.h`
- [Thermal control](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/module/temperature.h): `Marlin/src/module/temperature.h`
- [Bed leveling](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/feature/bedlevel/bedlevel.cpp): `Marlin/src/feature/bedlevel/bedlevel.cpp`
- [Controller fan](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/feature/controllerfan.cpp): `Marlin/src/feature/controllerfan.cpp`

### Media and interfaces

- [Media reader](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/sd/cardreader.h): `Marlin/src/sd/cardreader.h`
- [USB mass storage](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/sd/usb_flashdrive/lib-uhs2/masstorage.cpp): `Marlin/src/sd/usb_flashdrive/lib-uhs2/masstorage.cpp`
- [Printer display](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp): `Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp`

### Hardware platforms

- [Hardware abstraction](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/HAL.h): `Marlin/src/HAL/HAL.h`
- [AVR platform](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/AVR/HAL.cpp): `Marlin/src/HAL/AVR/HAL.cpp`
- [STM32 platform](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/STM32/HAL.cpp): `Marlin/src/HAL/STM32/HAL.cpp`
- [ESP32 platform](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/ESP32/HAL.cpp): `Marlin/src/HAL/ESP32/HAL.cpp`
- [Linux platform](https://github.com/sphawes/marlin/blob/2.0.x/Marlin/src/HAL/LINUX/HAL.cpp): `Marlin/src/HAL/LINUX/HAL.cpp`

### Other components

- **Host**

## Connections

- Host → Firmware core: sends commands
- Config selection → Printer settings: includes settings (evidence: `Marlin/src/inc/MarlinConfigPre.h`)
- Config selection → Advanced settings: includes settings (evidence: `Marlin/src/inc/MarlinConfigPre.h`)
- Runtime config → Config selection: includes prefix (evidence: `Marlin/src/inc/MarlinConfig.h`)
- Firmware core → G-code parser: dispatches commands
- G-code parser → Motion planner: requests motion
- Motion planner → Stepper control: queues steps (evidence: `Marlin/src/module/stepper.h`)
- Firmware core → Thermal control: manages heating
- Firmware core → Bed leveling: applies leveling
- Controller fan → Stepper control: reads axis state (evidence: `Marlin/src/feature/controllerfan.cpp`)
- Controller fan → Thermal control: reads thermal state (evidence: `Marlin/src/feature/controllerfan.cpp`)
- Media reader → USB mass storage: uses USB storage
- Firmware core → Media reader: reads print files
- Host → Printer display: uses controls
- Firmware core → Hardware abstraction: uses platform services
- Hardware abstraction → AVR platform: selects platform
- Hardware abstraction → STM32 platform: selects platform
- Hardware abstraction → ESP32 platform: selects platform
- Hardware abstraction → Linux platform: selects platform
