# veecle/tricore-probe architecture

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

- Interactive diagram: https://gitdiagram.com/veecle/tricore-probe
- Repository: https://github.com/veecle/tricore-probe

## Overview

##### Project type and purpose
- This is a Rust‑based CLI tool (“tricore-probe”) plus a helper library (“rust‑mcd”) for flashing and debugging Infineon AURIX/Tricore microcontrollers.
- It integrates with Infineon’s DAS and AurixFlasher tools (on Windows directly, on Linux via a Docker + Wine environment) and uses the `defmt` framework for log decoding.

##### File structure
- Top‑level workspace:
- Cargo.toml (workspace manifest)
- src/ (main crate: tricore‑probe CLI)
- rust‑mcd/ (subcrate: MCD FFI wrapper + demos)
- tricore‑docker/ (Docker build context for Linux support)
- CI, formatting, and license files
- src/ contains modules for each subsystem:
- main.rs (CLI entry)
- chip_communication.rs, das.rs, flash.rs (hardware interface layers)
- elf.rs (ELF parsing & objcopy integration)
- defmt.rs (invoke defmt‑print)
- backtrace/, registers.rs, memory.rs, transaction.rs (debug support)
- rust‑mcd/:
- build.rs & bindgen setup → generates `pregenerated.rs`
- src/raw/ → thin wrappers over the C MCD query APIs
- other Rust abstractions: library.rs, core.rs, connection.rs, etc.
- mcd_demo_basic_* folder: a C++ demo showing how to use the native MCD API

##### Key README insights
- The tool supports two platforms:
- Windows: calls native Infineon CLI tools via environment variables (`DAS_HOME`, `AURIX_FLASHER_PATH`).
- Linux: encapsulates those tools in a Docker container (`veecle/flash-tricore`) built from tricore‑docker/ using Wine.
- It’s designed as a Cargo runner and integrates with `defmt` for seamless logging.

##### Detail without overthinking
- Module in src/ to demonstrate responsibilities
- Both Windows and Linux code paths distinctly

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level manifest
    Workspace["Cargo.toml"]:::rust
    click Workspace "https://github.com/veecle/tricore-probe/blob/main/Cargo.toml"

    %% CLI Layer
    CLI["tricore-probe CLI"]:::rust
    click CLI "https://github.com/veecle/tricore-probe/blob/main/src/main.rs"

    Workspace --> CLI

    %% Core Rust Modules
    subgraph "Core Rust Modules"
        direction TB
        Main["main.rs"]:::rust
        click Main "https://github.com/veecle/tricore-probe/blob/main/src/main.rs"
        ChipComm["chip_communication.rs"]:::rust
        click ChipComm "https://github.com/veecle/tricore-probe/blob/main/src/chip_communication.rs"
        DASMod["das.rs"]:::rust
        click DASMod "https://github.com/veecle/tricore-probe/blob/main/src/das.rs"
        FlashMod["flash.rs"]:::rust
        click FlashMod "https://github.com/veecle/tricore-probe/blob/main/src/flash.rs"
        ELFMod["elf.rs"]:::rust
        click ELFMod "https://github.com/veecle/tricore-probe/blob/main/src/elf.rs"
        DefmtMod["defmt.rs"]:::rust
        click DefmtMod "https://github.com/veecle/tricore-probe/blob/main/src/defmt.rs"
        subgraph "Backtrace Support"
            direction TB
            BackMod["mod.rs"]:::rust
            click BackMod "https://github.com/veecle/tricore-probe/blob/main/src/backtrace/mod.rs"
            CSA["csa.rs"]:::rust
            click CSA "https://github.com/veecle/tricore-probe/blob/main/src/backtrace/csa.rs"
            PCXI["pcxi.rs"]:::rust
            click PCXI "https://github.com/veecle/tricore-probe/blob/main/src/backtrace/pcxi.rs"
        end
    end

    CLI -->|"parses args"| Main
    Main -->|"invokes"| ChipComm
    Main -->|"invokes"| DASMod
    Main -->|"invokes"| FlashMod
    Main -->|"invokes"| ELFMod
    Main -->|"spawns defmt-print"| DefmtMod
    DefmtMod --> BackMod

    %% rust-mcd FFI Library
    subgraph "rust-mcd FFI Library"
        direction TB
        CargoMcd["Cargo.toml"]:::rust
        click CargoMcd "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/Cargo.toml"
        BuildMcd["build.rs"]:::rust
        click BuildMcd "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/build.rs"
        Preg["pregenerated.rs"]:::rust
        click Preg "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/pregenerated.rs"
        subgraph "Rust Abstractions"
            direction TB
            LibRs["lib.rs"]:::rust
            click LibRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/lib.rs"
            CoreRs["core.rs"]:::rust
            click CoreRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/core.rs"
            LibraryRs["library.rs"]:::rust
            click LibraryRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/library.rs"
            ConnectionRs["connection.rs"]:::rust
            click ConnectionRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/connection.rs"
            MemoryRs["memory.rs"]:::rust
            click MemoryRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/memory.rs"
            RegistersRs["registers.rs"]:::rust
            click RegistersRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/registers.rs"
            TransactionRs["transaction.rs"]:::rust
            click TransactionRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/transaction.rs"
            ResetRs["reset.rs"]:::rust
            click ResetRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/reset.rs"
            SystemRs["system.rs"]:::rust
            click SystemRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/system.rs"
            ConfigRs["config.rs"]:::rust
            click ConfigRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/config.rs"
            ErrorRs["error.rs"]:::rust
            click ErrorRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/error.rs"
            BreakRs["breakpoint.rs"]:::rust
            click BreakRs "https://github.com/veecle/tricore-probe/blob/main/rust-mcd/src/breakpoint.rs"
        end
        subgraph "Raw C API Wrappers"
            direction TB
            Raw["src/raw/*"]:::ffi
            click Raw "https://github.com/veecle/tricore-probe/tree/main/rust-mcd/src/raw/"
        end
        Demo["mcd_demo_basic_120412/"]:::external
        click Demo "https://github.com/veecle/tricore-probe/tree/main/rust-mcd/mcd_demo_basic_120412/"
    end

    %% Connections between core and FFI
    FlashMod -->|"FFI call"| LibRs
    DASMod --> LibRs
    ChipComm --> LibRs

    %% Native MCD C Library
    Native["Native MCD Library"]:::ffi

    LibRs -->|"loads DLL"| Native

    %% Hardware
    HW["Tricore Hardware"]:::hardware
    Native -->|"JTAG commands"| HW

    %% Windows External Tools
    subgraph "Windows Tools"
        direction TB
        DAStool["Infineon DAS"]:::external
        Flasher["AurixFlasher"]:::external
        Objcopy["objcopy"]:::external
        Addr2line["addr2line"]:::external
        DefmtPrint["defmt-print"]:::external
    end

    DASMod -->|"spawn process"| DAStool
    FlashMod -->|"spawn process"| Flasher
    ELFMod -->|"invoke"| Objcopy
    ELFMod -->|"invoke"| Addr2line
    DefmtMod -->|"spawn process"| DefmtPrint

    %% Linux path via Docker
    subgraph "Linux Support via Docker/Wine"
        direction TB
        Docker["tricore-docker"]:::external
        click Docker "https://github.com/veecle/tricore-probe/tree/main/tricore-docker/Dockerfile"
        click Docker "https://github.com/veecle/tricore-probe/blob/main/tricore-docker/DAS_V8_1_4_installer_script.qs"
        Wine["Wine Environment"]:::external
        FTD2["wineftd2xx/"]:::external
        click FTD2 "https://github.com/veecle/tricore-probe/tree/main/tricore-docker/wineftd2xx/"
    end

    CLI -->|"Docker API"| Docker
    Docker -->|"runs Wine"| Wine
    Wine -->|"executes MCD tools"| Native
    Wine --> FTD2
    Native --> HW

    %% CI Pipeline
    CI[".github/workflows/ci.yml"]:::external
    click CI "https://github.com/veecle/tricore-probe/blob/main/.github/workflows/ci.yml"
    Workspace --> CI

    %% Styles
    classDef rust fill:#ccffcc,stroke:#006600,stroke-width:1px;
    classDef ffi fill:#ffe5cc,stroke:#cc6600,stroke-width:1px;
    classDef external fill:#cce5ff,stroke:#0066cc,stroke-width:1px;
    classDef hardware fill:#e0e0e0,stroke:#666666,stroke-width:1px;
```
