# wiznet/rp2040-hat-micropython architecture

> Architecture diagram of the GitHub repository wiznet/rp2040-hat-micropython, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wiznet/rp2040-hat-micropython
- Repository: https://github.com/wiznet/rp2040-hat-micropython

## Overview

##### Project type and purpose
- This is an embedded-software/hardware integration project: a MicroPython driver library and example suite that adds WIZnet W5100S Ethernet capability to a Raspberry Pi Pico (RP2040).
- The README and file tree show a core library (in Python/C patches), build scripts, and multiple network examples (DHCP, HTTP client/server, MQTT, etc.).

##### File structure
- Top-level:
- CMakeLists.txt, rp2_net_patch.cmake, and patches/ → tooling to build C-level patches or firmware image.
- libraries/ → likely the MicroPython driver modules (SPI interface, socket wrapper).
- examples/ → categorized by network protocol (DHCP, HTTP, MQTT, etc.), each with its own Python scripts and PCAP captures.
- static/images/ → documentation assets.
- Patterns:
- Layered design: Examples (app layer) → MicroPython driver library (abstraction layer) → C patches and SPI (HAL) → W5100S hardware → Ethernet network.

##### README
- Describes the WIZnet W5100S chip, SPI connection to RP2040, and points to “Getting Started” guide.

##### Elements
- From Examples → Driver API → SPI HAL → W5100S
- From W5100S → Physical Ethernet port → External Network
- Blue rectangles for software layers (Examples, Runtime, Library)
- Green rectangle for hardware (RP2040)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application layer
    subgraph "Application Examples" 
        direction TB
        EX["Application Examples"]:::software
        DHCP["DHCP Client\n(dhcp.py)"]:::software
        HTTPC["HTTP Client\n(HTTP_Client.py)"]:::software
        HTTPH["HTTP Helper\n(urequests.py)"]:::software
        HTTPS["HTTP Server\n(HTTP_Server.py)"]:::software
        LOOP["Loopback\n(W5x00_Loopback.py)"]:::software
        PING["Ping Test\n(w5x00_Ping_Test.py)"]:::software
        MQTTP["MQTT Publish\n(MQTT_pub.py)"]:::software
        MQTTS["MQTT Subscribe\n(MQTT_sub.py)"]:::software
        UPIP["UPIP\n(upip.py)"]:::software
    end

    %% MicroPython runtime
    MRT["MicroPython Runtime\n(on RP2040)"]:::software

    %% Driver library
    LIB["WIZnet MicroPython Driver Library"]:::software

    %% SPI HAL & C Patches
    subgraph "SPI HAL & C Patches"
        direction TB
        PATCH1["0001-Added-WIZnet-Chip-library.patch"]:::patch
        PATCH2["0002-Added-AXTLSlibrary.patch"]:::patch
        CMAKE1["CMakeLists.txt"]:::build
        CMAKE2["rp2_net_patch.cmake"]:::build
    end

    %% Hardware
    RM["RP2040 MCU\n(Raspberry Pi Pico)"]:::hardware
    SPI["SPI Bus\n@10MHz\n(machine.SPI(0))"]:::bus
    WIZ["W5100S Ethernet Chip"]:::chip

    %% External network
    NET["External Network Services\n(DHCP, HTTP, MQTT Broker)"]:::cloud

    %% Build flow
    CMAKE1 -->|applies patches| PATCH1
    CMAKE1 -->|applies patches| PATCH2
    CMAKE2 -.->|build firmware| RM

    %% Data flow
    EX -->|import calls| MRT
    DHCP --> MRT
    HTTPC --> MRT
    HTTPH --> HTTPC
    HTTPS --> MRT
    LOOP --> MRT
    PING --> MRT
    MQTTP --> MRT
    MQTTS --> MRT
    UPIP --> MRT

    MRT -->|native module| LIB
    LIB -->|SPI transactions| PATCH1
    LIB -->|SPI transactions| PATCH2
    PATCH1 --> SPI
    PATCH2 --> SPI

    RM --> SPI
    SPI --> WIZ
    WIZ --> NET
    NET --> WIZ
    WIZ --> SPI
    SPI --> RM

    %% Click events
    click EX "https://github.com/wiznet/rp2040-hat-micropython/tree/main/examples/"
    click DHCP "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/DHCP/dhcp.py"
    click HTTPC "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/HTTP/HTTP_Client/HTTP_Client.py"
    click HTTPH "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/HTTP/HTTP_Client/urequests.py"
    click HTTPS "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/HTTP/HTTP_Server/HTTP_Server.py"
    click LOOP "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/Loopback/W5x00_Loopback.py"
    click PING "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/PING_TEST/w5x00_Ping_Test.py"
    click MQTTP "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/MQTT/Publish/MQTT_pub.py"
    click MQTTS "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/MQTT/Subscribe/MQTT_sub.py"
    click UPIP "https://github.com/wiznet/rp2040-hat-micropython/blob/main/examples/UPIP/upip.py"
    click LIB "https://github.com/wiznet/rp2040-hat-micropython/tree/main/libraries/"
    click PATCH1 "https://github.com/wiznet/rp2040-hat-micropython/blob/main/patches/0001-Added-WIZnet-Chip-library.patch"
    click PATCH2 "https://github.com/wiznet/rp2040-hat-micropython/blob/main/patches/0002-Added-AXTLSlibrary.patch"
    click CMAKE1 "https://github.com/wiznet/rp2040-hat-micropython/blob/main/CMakeLists.txt"
    click CMAKE2 "https://github.com/wiznet/rp2040-hat-micropython/blob/main/rp2_net_patch.cmake"

    %% Styles
    classDef software fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1
    classDef hardware fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20
    classDef bus fill:#FFE0B2,stroke:#EF6C00,color:#E65100
    classDef chip fill:#E0E0E0,stroke:#424242,color:#424242
    classDef cloud fill:#E3F2FD,stroke:#1565C0,color:#1565C0
    classDef patch fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A
    classDef build fill:#FFF9C4,stroke:#F57F17,color:#F57F17
```
