# ve3wwg/stm32f103c8t6 architecture

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

- Interactive diagram: https://gitdiagram.com/ve3wwg/stm32f103c8t6
- Repository: https://github.com/ve3wwg/stm32f103c8t6

## Overview

##### Project type and purpose
- This is an embedded‐firmware “monorepo” of STM32F103 Cortex-M3 examples, drawn from the book “Beginning STM32: Developing with FreeRTOS, libopencm3 and GCC.”
- It provides both bare-metal demos (e.g. miniblink, uart, uarthwfc) and FreeRTOS-based demos (under rtos/) using libopencm3 as HAL and FreeRTOS as RTOS.
- Purpose: give end-to-end build+flash environment and multiple peripheral demos for learning and reference.

##### File structure
- Top‐level directories:
- libopencm3 (git submodule → hardware‐abstraction layer)
- miniblink, uart, uarthwfc, hse, hsi, mco_pll2, stlink (bare-metal example apps)
- rtos/ (FreeRTOS projects)
- Makefile, Makefile.incl (build orchestrator)
- Under rtos/:
- Project.mk, Makefile.rtos (RTOS project generator + build rules)
- src/ (templates for new projects)
- FreeRTOSv10.x subdirectory (external RTOS source; not compiled in place)
- One folder per demo (blinky, can, i2c-pcf8574, usbcdc, winbond, oled, etc.), each containing:
– main.c (application entry)
– Makefile (application build)
– rtos/ (copied-in FreeRTOS port files)
- Build flow: top‐level Makefile → builds libopencm3 → static libs → builds each example → arm-none-eabi-gcc → .elf/.bin → st‐link flash.

##### Insights from README
- Emphasizes open-source toolchain (arm-none-eabi-gcc, make, st-link)
- Outlines environment setup (git submodule update, unzip FreeRTOS, setting PREFIX/FREERTOS vars)
- Describes separation between libopencm3‐only projects and FreeRTOS projects.

##### Capturing essential elements
- Two core libraries (libopencm3, FreeRTOS) and how they integrate with applications.
- Both build and runtime flows to give a complete architectural picture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build-time components (blue)
    subgraph "Repository" 
        direction TB
        Repo["Git Repository"]:::build
        Repo -->|submodule| HAL["Hardware Abstraction Layer\n(libopencm3)"]:::build
        click HAL "https://github.com/ve3wwg/stm32f103c8t6/tree/master/libopencm3/"
        Repo -->|includes| MakefileTop["Makefile"]:::build
        click MakefileTop "https://github.com/ve3wwg/stm32f103c8t6/tree/master/Makefile"
        Repo -->|includes| MakefileIncl["Makefile.incl"]:::build
        click MakefileIncl "https://github.com/ve3wwg/stm32f103c8t6/blob/master/Makefile.incl"
        Repo -->|includes| LinkerLD["stm32f103c8t6.ld"]:::build
        click LinkerLD "https://github.com/ve3wwg/stm32f103c8t6/blob/master/stm32f103c8t6.ld"
        Repo --> BareMetalApps["Bare-metal Demos"]:::appCluster
        subgraph "Bare-metal Demos" 
            direction TB
            MB["miniblink app"]:::app
            click MB "https://github.com/ve3wwg/stm32f103c8t6/blob/master/miniblink/miniblink.c"
            click MB "https://github.com/ve3wwg/stm32f103c8t6/tree/master/miniblink/Makefile"
            UART["uart app"]:::app
            click UART "https://github.com/ve3wwg/stm32f103c8t6/blob/master/uart/uart.c"
            click UART "https://github.com/ve3wwg/stm32f103c8t6/tree/master/uart/Makefile"
            UARTFC["uarthwfc app"]:::app
            click UARTFC "https://github.com/ve3wwg/stm32f103c8t6/blob/master/uarthwfc/uarthwfc.c"
            click UARTFC "https://github.com/ve3wwg/stm32f103c8t6/tree/master/uarthwfc/Makefile"
            HSE["hse clock demo"]:::app
            click HSE "https://github.com/ve3wwg/stm32f103c8t6/blob/master/hse/hse.c"
            click HSE "https://github.com/ve3wwg/stm32f103c8t6/tree/master/hse/Makefile"
            HSI["hsi clock demo"]:::app
            click HSI "https://github.com/ve3wwg/stm32f103c8t6/blob/master/hsi/hsi.c"
            click HSI "https://github.com/ve3wwg/stm32f103c8t6/tree/master/hsi/Makefile"
            PLL2["MCO via PLL2 demo"]:::app
            click PLL2 "https://github.com/ve3wwg/stm32f103c8t6/blob/master/mco_pll2/pll2.c"
            click PLL2 "https://github.com/ve3wwg/stm32f103c8t6/tree/master/mco_pll2/Makefile"
            STLINK["st-link util wrapper"]:::app
            click STLINK "https://github.com/ve3wwg/stm32f103c8t6/tree/master/stlink/"
        end
        Repo --> RTOSRoot["rtos/"]:::build
        click RTOSRoot "https://github.com/ve3wwg/stm32f103c8t6/tree/master/rtos/"
        subgraph "RTOS Projects" 
            direction TB
            RTOSMake["Makefile.rtos"]:::build
            click RTOSMake "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/Makefile.rtos"
            RTOSProjMk["Project.mk"]:::build
            click RTOSProjMk "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/Project.mk"
            RTOSMakeTop["Makefile"]:::build
            click RTOSMakeTop "https://github.com/ve3wwg/stm32f103c8t6/tree/master/rtos/Makefile"
            RTOSInventory["INVENTORY.md"]:::build
            click RTOSInventory "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/INVENTORY.md"
            RTOSReadme["README.md"]:::build
            click RTOSReadme "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/README.md"
            subgraph "Templates" 
                direction TB
                TMain["main.c"]:::build
                click TMain "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/src/main.c"
                TMake["Makefile"]:::build
                click TMake "https://github.com/ve3wwg/stm32f103c8t6/tree/master/rtos/src/Makefile"
                TOpencm3["opencm3.c"]:::build
                click TOpencm3 "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/src/opencm3.c"
                TLD["stm32f103c8t6.ld"]:::build
                click TLD "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/src/stm32f103c8t6.ld"
            end
            subgraph "CAN Demo" 
                direction TB
                CANMain["main.c"]:::app
                click CANMain "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/can/main.c"
                CANFront["front.c"]:::app
                click CANFront "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/can/front.c"
                CANRear["rear.c"]:::app
                click CANRear "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/can/rear.c"
                CANMsgs["canmsgs.c"]:::app
                click CANMsgs "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/can/canmsgs.c"
                CANMake["Makefile"]:::build
                click CANMake "https://github.com/ve3wwg/stm32f103c8t6/tree/master/rtos/can/Makefile"
                CANMakeF["Makefile.front"]:::build
                click CANMakeF "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/can/Makefile.front"
                CANMakeR["Makefile.rear"]:::build
                click CANMakeR "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/can/Makefile.rear"
                CANLD["stm32f103c8t6.ld"]:::build
                click CANLD "https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/can/stm32f103c8t6.ld"
                subgraph "CAN RTOS Port" 
                    direction TB
                    CRtosC["*.c"]:::build
                    click CRtosC "https://github.com/ve3wwg/stm32f103c8t6/tree/master/rtos/can/rtos/"
                    CRtosH["*.h"]:::build
                    click CRtosH "https://github.com/ve3wwg/stm32f103c8t6/tree/master/rtos/can/rtos/"
                end
            end
        end
    end

    Toolchain["Toolchain\n(arm-none-eabi-gcc, ld, objcopy)"]:::build
    Host["Development Host\n(Linux/Mac/BSD)"]:::build
    Host -->|invoke| MakefileTop
    MakefileTop -->|calls| Toolchain
    MakefileTop -->|includes| MakefileIncl
    MakefileTop -->|links| HAL
    MakefileTop -->|links| BareMetalApps
    MakefileTop -->|links| RTOSRoot

    %% Build outputs
    Bin["Binary (.elf/.bin)"]:::build
    Toolchain -->|compile/link| Bin
    Bin -->|flash| StLink["st-link utility"]:::build
    StLink -->|SWD| MCU["STM32F103C8T6 MCU"]:::hardware

    %% Runtime flow
    subgraph "Runtime on STM32" 
        direction TB
        AppTasks["Application Tasks"]:::app
        RTOSKernel["FreeRTOS Kernel"]:::middleware
        HALDrv["HAL Drivers\n(libopencm3)"]:::middleware
        Peripherals["On-chip & External Peripherals"]:::hardware
        AppTasks -->|calls| RTOSKernel
        RTOSKernel -->|uses| HALDrv
        HALDrv -->|drives| Peripherals
    end

    Bin -->|run| AppTasks

    classDef build fill:#D0E6FF,stroke:#004A99,color:#004A99;
    classDef middleware fill:#DFFFE0,stroke:#228B22,color:#228B22;
    classDef app fill:#FFE7B2,stroke:#FF8C00,color:#FF8C00;
    classDef hardware fill:#E0E0E0,stroke:#666666,color:#666666;
    classDef appCluster fill:#FFF0E0,stroke:#FF8C00,color:#FF8C00;
```
