Fault Injection & Debugging

# Testing IWDG, WWDG and watchdog starvation resets in CI

Inject a sensor deadlock or infinite loop and verify hardware watchdog reset plus RCC\_CSR reset-cause logging in CI.

A watchdog that is refreshed inside a timer ISR instead of the main control loop passes every happy-path test while letting deadlocked application tasks hang forever in the field.

CircuitTwin runs hardware watchdog countdowns in virtual time so CI can stall a peripheral, let the watchdog expire, and assert that firmware boots back cleanly with IWDGRSTF set.

## Watchdog checks in CI

| Watchdog type            | Fault tested                  | Required verification                                |
| ------------------------ | ----------------------------- | ---------------------------------------------------- |
| Independent (IWDG)       | Main task hangs on bus lockup | MCU resets within timeout and logs RCC\_CSR.IWDGRSTF |
| Window (WWDG)            | Refresh too early or too late | Immediate reset on window violation                  |
| External PMIC (TLF35584) | Missed SPI/WDI trigger pulse  | PMIC drives ROT reset pin and logs fault             |

## Local CLI workflow

Shell - run watchdog starvation recovery test

```
ct test run --json --junit results/wdt.xml tests/watchdog.suite.yaml
```

## Suite & fault configuration

tests/watchdog.suite.yaml

```
version: 1
board: nucleo-f446re
firmware: build/wdt_app.elf
tests:
  - name: task-deadlock-triggers-iwdg-reset
    timeout_ms: 4000
    faults:
      - at_ms: 300
        bus: I2C1
        kind: nack
        address: 0x68
        count: 100
    expect:
      console_contains: "RESET_CAUSE_IWDG"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/watchdog-ci.yml

```
name: Watchdog Starvation CI
on: [push, pull_request]
jobs:
  wdt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: circuittwin/action@v1
        with:
          suite: tests/watchdog.suite.yaml
```

## Troubleshooting checklist

| Symptom                                             | Fix                                                                                                          |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Watchdog never fires during deadlock test           | Move HAL\_IWDG\_Refresh() out of SysTick/timer ISRs into a health supervisor that checks every task bitmask. |
| Reset cause shows POR instead of IWDG on every boot | Clear reset flags via RCC\_CSR.RMVF after reading them at startup.                                           |

## Frequently asked questions

| Question                                                                 | Answer                                                                                                                                                |
| ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| Why should firmware never kick the watchdog inside a periodic timer ISR? | If the main control loop deadlocks while interrupts remain enabled, a timer ISR keeps kicking the watchdog indefinitely and defeats the safety reset. |

## Related boards & component twins

[Board: nucleo-f446re](https://circuittwin.ai/boards/nucleo-f446re) [Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: nrf52840-dk](https://circuittwin.ai/boards/nrf52840-dk) [Board: aurix-tc375-lite](https://circuittwin.ai/boards/aurix-tc375-lite) [Twin: TLF35584](https://circuittwin.ai/twins/tlf35584) [Twin: MPU-6050](https://circuittwin.ai/twins/mpu-6050) [Suite & fault testing docs](https://circuittwin.ai/docs/testing)

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