MCU Testing & CI

AVR ATmega328P & ATmega2560 firmware CI

Test 8-bit AVR firmware without physical Arduino benches—backed by AVR CPU differential checks, passing ADC trigger oracle and Mega 2560 silicon capture.

8-bit AVR chips still ship in appliances, 3D printers, power controllers and industrial relays. Subtle bugs like missing volatile qualifiers on ISR flags, 16 MHz UART baud errors at 115200 bps (U2X=0 gives -3.55%), and TWI state-machine hangs show up immediately when you execute the compiled avr-gcc ELF.

CircuitTwin tracks arduino-uno, arduino-nano and arduino-mega2560 (including Mega 2560 L3 silicon capture). Note that Zephyr v3.7.0 has no AVR port, so Zephyr L1 boot rows appear explicitly as unsupported on the board dashboard.

AVR board twins

Board slugMCUKey evidence
arduino-unoATmega328P @ 16 MHzavr-adc-trigger-oracle PASS + AVR CPU diff
arduino-nanoATmega328P @ 16 MHzShared ATmega328P core & peripheral models
arduino-mega2560ATmega2560 @ 16 MHzL3 silicon capture (silicon-arduino-mega2560-2026-11-19)

Local CLI workflow

Shell — compile avr-gcc & run
avr-gcc -mmcu=atmega328p -DF_CPU=16000000UL -Os main.c -o build/uno.elf
ct run --json --board arduino-uno build/uno.elf

Suite & fault configuration

tests/avr-temp.suite.yaml
version: 1
board: arduino-uno
firmware: build/uno.elf
tests:
  - name: tmp117-readout
    timeout_ms: 1500
    expect:
      console_contains: "TEMP_25.00C"
      exit_code: 0
  - name: twi-nack-recovery
    faults:
      - at_ms: 30
        bus: TWI0
        kind: nack
        address: 0x48
        count: 2
    expect:
      console_contains: "TWI_RETRY_OK"

CI pipeline integration

.github/workflows/avr-ci.yml
name: AVR Firmware CI
on: [push, pull_request]
jobs:
  avr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: arduino-cli compile --fqbn arduino:avr:uno --output-dir build .
      - uses: circuittwin/action@v1
        with:
          board: arduino-uno
          firmware: build/sketch.ino.elf
          suite: tests/avr-temp.suite.yaml

Arduino Uno and Mega 2560 AVR firmware CI

Test real ATmega328P and ATmega2560 .elf sketches in GitHub Actions without flaky USB-serial runners.

AVR sketches suffer from 2 KB SRAM exhaustion, integer overflow in millis() math, and wrong Timer1 prescalers. None of those show up in C++ host mocks.

CircuitTwin runs the avr-gcc ELF generated by arduino-cli directly on our differential-checked AVR core with TWI, SPI, USART, ADC and internal EEPROM models.

AVR peripherals verified in CI

PeripheralBoard supportTypical bug caught
USART0..3Uno, Nano, Mega 2560Wrong UBRR baud divider or TX buffer overrun
TWI (I2C)Uno, Nano, Mega 2560Wire.endTransmission() hang on missing pull-up or NACK
10-bit ADCUno, Mega 2560Wrong ADMUX reference bit (AREF vs AVCC)
Internal EEPROMUno, Mega 2560Out-of-bounds write or missing wear-level checksum
Shell - compile with arduino-cli and test on twin
arduino-cli compile --fqbn arduino:avr:uno --output-dir build/ sketch/
ct run --json --board arduino-uno --device bme280 build/sketch.ino.elf
tests/arduino-avr.suite.yaml
version: 1
board: arduino-uno
firmware: build/sketch.ino.elf
tests:
  - name: twi-sensor-and-nack-recovery
    timeout_ms: 2500
    faults:
      - at_ms: 300
        bus: TWI
        kind: nack
        address: 0x76
        count: 2
    expect:
      console_contains: "RETRY_OK"
      exit_code: 0

Troubleshooting checklist

SymptomFix
115200 bps UART prints corrupted bytes at 16 MHzSet UCSR0A |= (1 << U2X0) and UBRR0 = 16; verify error % in the UART Baud Calculator.
TWI/I2C hangs forever waiting on TWINTAdd a bounded timeout loop around while (!(TWCR & (1 << TWINT))) and test it with a NACK fault.
RAM corruption on 2 KB ATmega328PMove constant strings to PROGMEM (F() macro) and inspect stack high-water mark in GDB.
Timer1 16-bit register reads wrong valueRead TCNT1L before TCNT1H (and write TCNT1H before TCNT1L) with interrupts disabled.
Sketch resets randomly during Serial.print()Check .bss + .data size with avr-size; wrap constant strings in F() to keep them out of 2 KB SRAM.
Wire library hangs forever on bus errorEnable Wire.setWireTimeout(25000, true) and verify recovery with an I2C NACK fault.

Frequently asked questions

QuestionAnswer
Can CircuitTwin run standard .ino sketches?Compile the sketch with arduino-cli compile --output-dir build to produce the .ino.elf file, then pass that ELF to ct run.

Related boards & component twins

More in MCU Testing & CI