RTOS & Firmware Stacks

Marlin 3D printer firmware testing in CI

Verify Marlin thermal-runaway shutdowns, endstop trips and stepper-timer ISRs against your real compiled ELF before shipping a release.

A broken thermal-runaway check or inverted endstop logic in Marlin is a fire hazard, yet compile-only CI checks only prove the code builds. Running the compiled Marlin ELF on an ATmega2560 or STM32F4 twin lets you feed G-code over UART, freeze a thermistor or MAX31855 thermocouple reading, and assert that Marlin triggers M112 / Kill within the configured window.

Both arduino-mega2560 (ATmega2560) and black-pill-f411ce / nucleo-f446re (STM32F4) board twins are available alongside the MAX31855 thermocouple twin.

Marlin CI safety test cases

Test caseInjected fault / stimulusExpected Marlin behavior
Thermal runawayFreeze MAX31855 / thermistor while heater PWM activeHeater disabled + "THERMAL RUNAWAY" kill message
Open thermocoupleSet MAX31855 OC fault bitImmediate MINTEMP / MAXTEMP halt
Endstop homingToggle endstop GPIO pin during G28Axis stops cleanly and sets home position
UART G-code parserSend M115 / G1 commands over serialValid firmware banner and ok responses

Local CLI workflow

Shell — build Marlin & test runaway
pio run -e mega2560
ct test run --json tests/marlin-safety.suite.yaml

Suite & fault configuration

tests/marlin-safety.suite.yaml
version: 1
board: arduino-mega2560
firmware: .pio/build/mega2560/firmware.elf
tests:
  - name: thermal-runaway-kill
    timeout_ms: 15000
    uart_tx:
      - at_ms: 500
        text: "M104 S200\n"
    faults:
      - at_ms: 1000
        part: max31855
        kind: frozen_reading
    expect:
      console_contains: "THERMAL RUNAWAY"
      exit_code: 0

CI pipeline integration

.github/workflows/marlin-ci.yml
name: Marlin Safety Twin CI
on: [push, pull_request]
jobs:
  marlin:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pio run -e mega2560
      - uses: circuittwin/action@v1
        with:
          suite: tests/marlin-safety.suite.yaml

Marlin thermal runaway and stepper CI

Inject unplugged-thermistor ADC voltages into compiled Marlin firmware and assert heater shutdown in under two seconds.

A missing thermal-runaway guard in a Marlin config edit is a fire hazard. Bench testing unplugged hotends by hand rarely happens on every pull request.

CircuitTwin runs the compiled ATmega2560 or STM32F4 Marlin ELF with deterministic NTC thermistor voltages on ADC0 and TMC2209 UART responses, verifying MINTEMP, MAXTEMP and heater MOSFET cut-off automatically.

Marlin safety scenarios

ScenarioStimulus / FaultRequired firmware output
Unplugged hotend NTCDrive ADC0 to 5.0 V (open circuit)Error:MINTEMP triggered and heater pin low
Shorted thermistorDrive ADC0 to 0.0 VError:MAXTEMP triggered immediately
Heater detachedCommand M104 S200 while holding ADC at 25 CThermal Runaway kill() within timeout
Shell - run Marlin thermal safety suite
ct test run --json --junit results/marlin.xml tests/marlin-thermal.suite.yaml
tests/marlin-thermal.suite.yaml
version: 1
board: arduino-mega2560
firmware: .pio/build/mega2560/firmware.elf
tests:
  - name: hotend-ntc-open-circuit-shutdown
    timeout_ms: 4000
    stimuli:
      - at_ms: 0
        target: mcu
        pin: ADC0
        voltage_v: 4.98
    expect:
      console_contains: "MINTEMP"
      exit_code: 0

Troubleshooting checklist

SymptomFix
No UART response to M115Verify SERIAL_PORT and BAUDRATE (115200 or 250000) in Configuration.h match the suite UART baud.
Thermal runaway test times out before killMatch suite timeout_ms to THERMAL_PROTECTION_PERIOD + heating hysteresis window.
MAX31855 reads 0 °C on SPIConfirm SPI Mode 0 and SCLK <= 5 MHz using the SPI Clock Divider Calculator.
SRAM exhaustion on ATmega2560Check avr-size output; disable optional LCD menus if testing headless motion/safety builds.
ADC voltage does not match expected temperatureUse the ADC Resolution & NTC Calculator to verify pull-up value (4.7 kOhm on RAMPS 1.4) and Beta curve.
Serial output unreadable at 250000 baudCheck AVR UBRR rounding at 16 MHz in the UART Baud Calculator (250000 baud is 0.0% error on 16 MHz AVR).

Frequently asked questions

QuestionAnswer
Can CircuitTwin test Marlin on both AVR Mega 2560 and 32-bit STM32 boards?Yes. CircuitTwin supports ATmega2560 (arduino-mega2560) and STM32F4/F1/H7 boards including Black Pill F411 and NUCLEO targets.

Related boards & component twins

More in RTOS & Firmware Stacks