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 case          | Injected fault / stimulus                            | Expected Marlin behavior                         |
| ------------------ | ---------------------------------------------------- | ------------------------------------------------ |
| Thermal runaway    | Freeze MAX31855 / thermistor while heater PWM active | Heater disabled + "THERMAL RUNAWAY" kill message |
| Open thermocouple  | Set MAX31855 OC fault bit                            | Immediate MINTEMP / MAXTEMP halt                 |
| Endstop homing     | Toggle endstop GPIO pin during G28                   | Axis stops cleanly and sets home position        |
| UART G-code parser | Send M115 / G1 commands over serial                  | Valid 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

| Scenario             | Stimulus / Fault                            | Required firmware output                   |
| -------------------- | ------------------------------------------- | ------------------------------------------ |
| Unplugged hotend NTC | Drive ADC0 to 5.0 V (open circuit)          | Error:MINTEMP triggered and heater pin low |
| Shorted thermistor   | Drive ADC0 to 0.0 V                         | Error:MAXTEMP triggered immediately        |
| Heater detached      | Command M104 S200 while holding ADC at 25 C | Thermal 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

| Symptom                                         | Fix                                                                                                      |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| No UART response to M115                        | Verify SERIAL\_PORT and BAUDRATE (115200 or 250000) in Configuration.h match the suite UART baud.        |
| Thermal runaway test times out before kill      | Match suite timeout\_ms to THERMAL\_PROTECTION\_PERIOD + heating hysteresis window.                      |
| MAX31855 reads 0 °C on SPI                      | Confirm SPI Mode 0 and SCLK <= 5 MHz using the SPI Clock Divider Calculator.                             |
| SRAM exhaustion on ATmega2560                   | Check avr-size output; disable optional LCD menus if testing headless motion/safety builds.              |
| ADC voltage does not match expected temperature | Use 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 baud         | Check AVR UBRR rounding at 16 MHz in the UART Baud Calculator (250000 baud is 0.0% error on 16 MHz AVR). |

## Frequently asked questions

| Question                                                                   | Answer                                                                                                                         |
| -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| 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

[Board: arduino-mega2560](https://circuittwin.ai/boards/arduino-mega2560) [Board: black-pill-f411ce](https://circuittwin.ai/boards/black-pill-f411ce) [Board: nucleo-f446re](https://circuittwin.ai/boards/nucleo-f446re) [Twin: MAX31855](https://circuittwin.ai/twins/max31855) [Twin: DS3231](https://circuittwin.ai/twins/ds3231) [Twin: TMC2209](https://circuittwin.ai/twins/tmc2209) [Twin: SSD1306](https://circuittwin.ai/twins/ssd1306) [Stimuli & fault injection](https://circuittwin.ai/docs/inputs) [ct CLI](https://circuittwin.ai/docs/cli) [Marlin firmware CI overview](https://circuittwin.ai/guides/marlin-firmware-testing-ci)

## More in RTOS & Firmware Stacks

[Zephyr RTOS CI without hardware benches](https://circuittwin.ai/guides/zephyr-rtos-ci-without-hardware) [FreeRTOS headless testing in CI](https://circuittwin.ai/guides/freertos-headless-testing) [ESP-IDF CI simulation for ESP32, S3 & C3](https://circuittwin.ai/guides/esp-idf-ci-simulation) [PX4 Pixhawk 6C simulation on real ARM ELF](https://circuittwin.ai/guides/px4-pixhawk-6c-simulation)

> ## Run this workflow on your own ELF
>
> Start free on CircuitTwin to run local board twins, fault matrices and CI checks with zero per-run credits.
>
> [Start now](https://app.circuittwin.ai/try) [Read the quickstart](https://circuittwin.ai/docs/quickstart) [Connect a coding agent](https://circuittwin.ai/docs/agents)
