# infineon/mtb-example-xmc-ccu4-capture architecture

> Architecture diagram of the GitHub repository infineon/mtb-example-xmc-ccu4-capture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/infineon/mtb-example-xmc-ccu4-capture
- Repository: https://github.com/infineon/mtb-example-xmc-ccu4-capture

## Overview

##### Project type and purpose
- This is an embedded firmware code example for an Infineon XMC™ MCU.
- It demonstrates CCU4 slice capture and compare functionality: one slice generates a 2 Hz PWM (75 % duty), another slice captures rising/falling edges of that PWM and reports timer values over UART.
- The project uses ModusToolbox™ for project creation, configuration templates for different evaluation kits, XMCLib peripheral drivers, and retarget-io for UART.

##### Main components
a. Developer Environment (Host PC)
- ModusToolbox™ tools: Eclipse IDE or project-creator-cli
- Makefile orchestrating `make getlibs`, build, export
- Toolchains: GCC_ARM (default), ARM, or IAR
- Git repo containing source and templates

b. Build System
- Makefile invokes project-creator, fetches libraries in `deps/retarget-io-cat3.mtb` and XMCLib
- Templates directory (`templates/TARGET_…/config/design.modus`) provides BSP overrides for each kit
- Compiler/linker assembles `main.c` and library code into a firmware image

c. Firmware Software Layers
- Application layer: `main.c`
- Board Support Package (BSP) layer: design.modus files in `templates` override default pin/peripheral settings
- Peripheral Abstraction: XMCLib CCU4 personalities (PWM_0 and CAPTURE_0), CYBSP_DEBUG_UART personality, retarget-io

d. MCU Hardware
- XMC™ MCU core (e.g., XMC1400, XMC4700, or XMC4800)
- CCU4 Slice 0 configured as PWM generator
- CCU4 Slice 1 configured as capture input
- Single GPIO pin routing PWM output to capture input
- UART peripheral (CYBSP_DEBUG_UART) for debug messages

e. Debug & Communication Interfaces
- SEGGER J-Link: SWD for programming & debugging, CDC UART for serial output
- USB connection to Host PC

f. User Interface (Host PC)
- Terminal emulator (e.g., Tera Term) at 115200 baud, 8N1

##### Relationships and data flow
1. Development:
Host PC → (project-creator-cli / Eclipse) → generates application skeleton
Makefile → fetch libraries (`getlibs`) → compile/link → firmware.bin
2. Programming:
Host PC → (J-Link) → flashes firmware.bin into MCU
3. Runtime:
MCU boots → application initializes BSP and peripherals →
- CCU4 PWM_0 toggles output pin at 2 Hz → same pin fed into CCU4 CAPTURE_0 → capture events logged
- On each capture event, firmware reads timer value and calls `printf` → retarget-io → CYBSP_DEBUG_UART →
MCU UART → (J-Link CDC) → USB → Host PC Terminal emulator displays compare/period values

##### Architectural patterns & design principles
- Layered modular design: application logic separated from peripheral drivers and BSP
- Template-based configuration: each kit’s design.modus customizes pins and personalities
- Reusable library components: XMCLib modules for CCU4, retarget-io for UART redirection
- Makefile-driven automation for build, library acquisition, and IDE export

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Environment
    subgraph "Developer Environment"
        DevPC["Host PC: Eclipse / project-creator-cli"]:::tools
        README["README.md"]:::docs
        GITIGNORE[".gitignore"]:::docs
        CYIGNORE[".cyignore"]:::docs
        IMAGES["images/"]:::docs
    end

    %% Build System
    subgraph "Build System"
        Make["Makefile orchestration"]:::libs
        Retarget["retarget-io-cat3.mtb"]:::libs
        XMCLib["XMCLib"]:::libs
        T14["XMC1400 BSP: design.modus"]:::firmware
        T47["XMC4700 BSP: design.modus"]:::firmware
        T48["XMC4800 BSP: design.modus"]:::firmware
    end

    %% Firmware Layer
    subgraph "Firmware"
        App["main.c (Application Logic)"]:::firmware
    end

    %% MCU Hardware
    subgraph "MCU Hardware"
        MCU["XMC MCU\nCCU4 PWM_0 → CCU4 CAPTURE_0\nCYBSP_DEBUG_UART"]:::hardware
    end

    %% Debug & Communication
    subgraph "Debug & Communication"
        JLink["SEGGER J-Link\n(SWD + CDC UART)"]:::hardware
        Terminal["Host PC Terminal Emulator"]:::tools
    end

    %% Build and Deployment Flows
    DevPC -->|"invoke make"| Make
    Make -->|"fetch libraries"| Retarget
    Make -->|"fetch libraries"| XMCLib
    Make -->|"apply BSP overrides"| T14
    Make -->|"apply BSP overrides"| T47
    Make -->|"apply BSP overrides"| T48
    Make -->|"compile/link"| App
    DevPC -->|"program"| JLink
    JLink -->|"flash firmware.bin"| MCU

    %% Runtime Data Flows
    MCU -->|"PWM signal"| MCU
    MCU -->|"UART data"| JLink
    JLink -->|"CDC UART → USB"| Terminal

    %% Click Events
    click Make "https://github.com/infineon/mtb-example-xmc-ccu4-capture/tree/master/Makefile"
    click Retarget "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/deps/retarget-io-cat3.mtb"
    click App "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/main.c"
    click T14 "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/templates/TARGET_KIT_XMC14_BOOT_001/config/design.modus"
    click T47 "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/templates/TARGET_KIT_XMC47_RELAX_V1/config/design.modus"
    click T48 "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/templates/TARGET_KIT_XMC48_RELAX_ECAT_V1/config/design.modus"
    click README "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/README.md"
    click GITIGNORE "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/.gitignore"
    click CYIGNORE "https://github.com/infineon/mtb-example-xmc-ccu4-capture/blob/master/.cyignore"
    click IMAGES "https://github.com/infineon/mtb-example-xmc-ccu4-capture/tree/master/images/"

    %% Styling
    classDef tools fill:#AED6F1,stroke:#1B4F72
    classDef libs fill:#D5DBDB,stroke:#7F8C8D
    classDef firmware fill:#ABEBC6,stroke:#196F3D
    classDef hardware fill:#F5B7B1,stroke:#922B21
    classDef docs fill:#FCF3CF,stroke:#B7950B
```
