Fault Injection & Debugging

# Ethernet link-down and packet-loss testing in CI

Test cable unplug, PHY auto-negotiation flaps and burst packet loss on compiled networking firmware without a switch.

Embedded lwIP and socket stacks frequently leak pbufs or stall RX DMA rings when an Ethernet cable unplugs mid-transfer. Bench testing requires physically pulling RJ45 cables.

CircuitTwin injects link\_down and packet\_loss faults on RMII PHYs (LAN8720A) and SPI controllers (W5500) so CI proves DHCP renew and socket reconnect succeed every time.

## Ethernet fault scenarios

| Fault kind   | Target interface               | Regression caught                                            |
| ------------ | ------------------------------ | ------------------------------------------------------------ |
| link\_down   | MDIO BSR bit 2 / W5500 PHYCFGR | Stuck netif\_is\_link\_up() or unclosed dead TCP sockets     |
| packet\_loss | Ethernet MAC RX ring           | TX retry exhaustion or pbuf pool exhaustion                  |
| crc\_error   | Corrupted FCS frame            | MAC accepts bad frame when checksum offload is misconfigured |

## Local CLI workflow

Shell - run Ethernet link-down recovery suite

```
ct test run --json --junit results/eth-link.xml tests/eth-linkfault.suite.yaml
```

## Suite & fault configuration

tests/eth-linkfault.suite.yaml

```
version: 1
board: nucleo-f767zi
firmware: build/lwip_app.elf
tests:
  - name: rmii-link-drop-and-reconnect
    timeout_ms: 4000
    faults:
      - at_ms: 500
        part: lan8720a
        kind: link_down
        duration_ms: 800
    expect:
      console_contains: "ETH_RECONNECTED"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/eth-fault-ci.yml

```
name: Ethernet Link Fault CI
on: [push, pull_request]
jobs:
  eth:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: circuittwin/action@v1
        with:
          suite: tests/eth-linkfault.suite.yaml
```

## Troubleshooting checklist

| Symptom                                                  | Fix                                                                                    |
| -------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| STM32H7 ETH DMA descriptors return garbage               | Place ETH RX/TX descriptors in D2 SRAM (0x30040000) with non-cacheable MPU attributes. |
| W5500 socket stays in SOCK\_ESTABLISHED after disconnect | Enable TCP keepalive (Sn\_KPALVTR) and check PHYCFGR link bit periodically.            |

## Frequently asked questions

| Question                                                                              | Answer                                                                                                         |
| ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| Can CircuitTwin test Ethernet link-down faults on both RMII MACs and W5500 SPI chips? | Yes. Inject link\_down faults against MDIO PHYs like LAN8720A or SPI controllers like W5500 inside suite.yaml. |

## Related boards & component twins

[Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: nucleo-h743zi2](https://circuittwin.ai/boards/nucleo-h743zi2) [Board: frdm-k64f](https://circuittwin.ai/boards/frdm-k64f) [Board: rpi-pico](https://circuittwin.ai/boards/rpi-pico) [Twin: LAN8720A](https://circuittwin.ai/twins/lan8720a) [Twin: W5500](https://circuittwin.ai/twins/w5500) [Fault-injection reference](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)
