Fault Injection & Debugging

# Triaging exit code 4 unmodelled-register diagnostics

Silent zero-reads turn real bugs into false green builds. Exit code 4 tells you the exact peripheral, register address and PC.

Many simulators return 0x00000000 for any peripheral register they have not implemented. Firmware then appears to pass in CI while failing on silicon.

CircuitTwin treats every unmodelled MMIO access as inconclusive (exit code 4) by default and prints the exact register name, address and program counter in JSON so you can resolve it explicitly.

## Exit code 4 triage options

| Cause                  | Diagnostic clue                                           | Clean resolution                                             |
| ---------------------- | --------------------------------------------------------- | ------------------------------------------------------------ |
| Unused init peripheral | Access inside MX\_USB\_OTG\_Init() during sensor test     | Guard unused USB/Wi-Fi init out of non-RF test build         |
| Missing SVD companion  | Register exists in datasheet but omitted from minimal SVD | Regenerate MCU twin with vendor CMSIS header or RM companion |
| Out-of-bounds pointer  | Random address in peripheral space                        | Real firmware bug caught! Inspect PC in GDB                  |

## Local CLI workflow

Shell - inspect exact unmodelled register in JSON

```
ct run --json --board nucleo-f767zi build/app.elf | jq '.unmodelled'
```

## Suite & fault configuration

tests/strict-mode.suite.yaml

```
version: 1
board: nucleo-f767zi
firmware: build/app.elf
tests:
  - name: zero-unmodelled-register-gate
    timeout_ms: 2500
    expect:
      console_contains: "APP_OK"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/strict-exit4.yml

```
name: Strict Unmodelled-Register Gate
on: [push, pull_request]
jobs:
  strict:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: circuittwin/action@v1
        with:
          suite: tests/strict-exit4.suite.yaml
```

## Troubleshooting checklist

| Symptom                                                 | Fix                                                                                                    |
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| Exit code 4 points to a strange address like 0x4002FFFF | Resolve the reported PC with arm-none-eabi-addr2line -e build/app.elf to check for a wild pointer bug. |

## Frequently asked questions

| Question                                                                                       | Answer                                                                                                                                                             |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Why does CircuitTwin fail with exit code 4 instead of returning zero for unmodelled registers? | Returning zero silently creates false-positive CI passes. Failing explicitly with exit code 4 guarantees you always know the exact boundary of what was simulated. |

## Related boards & component twins

[Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: esp32s3-devkitc](https://circuittwin.ai/boards/esp32s3-devkitc) [Board: nrf52840-dk](https://circuittwin.ai/boards/nrf52840-dk) [Twin: BME280](https://circuittwin.ai/twins/bme280) [Twin: LSM6DSO](https://circuittwin.ai/twins/lsm6dso) [Troubleshooting guide](https://circuittwin.ai/docs/troubleshooting)

## More in Fault Injection & Debugging

[I2C NACK and stuck-bus fault injection in CI](https://circuittwin.ai/guides/i2c-nack-fault-injection) [SPI bus fault testing and chip-select verification](https://circuittwin.ai/guides/spi-bus-fault-testing) [Debugging UART baud mismatches and framing errors](https://circuittwin.ai/guides/uart-baud-mismatch-debugging) [Cortex-M HardFault triage in CI and reverse GDB](https://circuittwin.ai/guides/cortex-m-hardfault-ci-triage)

> ## 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)
