ESP32 + W5500 Ethernet Loop Detector — Written in Rust (no_std)
Rust (no_std) network loop detection for ESP32 + W5500 Ethernet. Detects Layer 2 loops without STP using MACRAW socket probe frames. Japanese dev. 2025.
Overview
This is a network loop detection tool for the ESP32 + WIZnet W5500 combination, written entirely in Rust (no_std embedded). Developed by a Japanese engineer, the project addresses a practical problem in small embedded Ethernet networks: detecting Layer 2 (Ethernet) loops without relying on Spanning Tree Protocol (STP), which is typically unavailable on embedded Ethernet controllers.
When a loop exists in an Ethernet network (e.g., two ports of the same switch connected together, or a cable connected to two ports of the same W5500 hub), broadcast frames circulate indefinitely, saturating bandwidth and causing network failures. This tool detects such conditions from the embedded side.
What This Project Does
- Sends tagged probe frames and listens for echoes — if a sent frame is received back, a loop is detected
- Operates at Layer 2 (raw Ethernet frames) via W5500 MACRAW socket mode
- Written in Rust with
no_stdfor embedded bare-metal use - Targets ESP32 + W5500 SPI Ethernet hardware
- Practical utility for network diagnostics on embedded systems without managed switches
Why Rust? The project uses Rust's embedded ecosystem (no_std, embedded-hal) to leverage memory safety guarantees without an OS. This is increasingly common in embedded Ethernet projects where reliability is critical and buffer overflows from C code are a concern.
Hardware
- MCU: ESP32
- Ethernet: WIZnet W5500 (SPI, MACRAW socket mode for raw frame access)
How to Build
- Clone:
git clone https://github.com/t13801206/esp32-loopchk - Install Rust embedded toolchain:
rustup target add xtensa-esp32-none-elf - Install
cargo-espflash:cargo install cargo-espflash - Build and flash:
cargo espflash flash --release
FAQ
Q1. What is a network loop and why is it harmful? A Layer 2 loop occurs when there are two or more active paths between network switches/devices with no STP to block redundant paths. Broadcast frames circulate endlessly, rapidly saturating network bandwidth and causing all devices on the segment to become unreachable.
Q2. Why not just use STP? STP is a managed switch feature. WIZnet W5500 is a simple Ethernet controller with no switching fabric — it connects a single device to a network. STP is not applicable. This tool detects loops from the endpoint's perspective using probe frames.
Q3. Why write this in Rust instead of C? Rust provides compile-time memory safety guarantees that prevent buffer overflows and use-after-free bugs. For embedded networking code that handles raw frames, Rust eliminates an entire class of vulnerabilities that are common in C-based implementations.
Key Takeaway
This is a niche but genuinely useful project — a Rust-based network loop detector for embedded ESP32 + W5500 systems. It demonstrates both a practical networking diagnostic tool and how modern Rust embedded development (no_std) integrates with WIZnet W5500 at the raw frame level.
Source Code: https://github.com/t13801206/esp32-loopchk
