# ciqi6/embedlearn architecture

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

- Interactive diagram: https://gitdiagram.com/ciqi6/embedlearn
- Repository: https://github.com/ciqi6/embedlearn

## Overview

##### Project type and purpose
- This is an embedded-system learning/demo project targeting an STM32F10x microcontroller.
- It uses ARM’s CMSIS core support plus ST’s “FWlib” standard-peripheral library.
- The “User” folder contains drivers (LED, Key, SysTick, TimerBase, USART) and the main application.

##### File structure
- Top-level folders:
- Libraries/CMSIS – core Cortex‐M3 startup, vector table, system init
- Libraries/FWlib – ST’s peripheral drivers (GPIO, TIM, USART, EXTI, etc.)
- User – board-support drivers and application code
- Notice the typical HAL/BSP layering: application → BSP (User/*.c,h) → peripheral library → CMSIS → hardware.

##### README
- Brief description: “A embedded system Learning project organized by GDOU.”
- Confirms this is an educational/demo full-embedded stack from reset/startup to application.

##### Main components and their interactions
a. Components
- MCU Block (STM32F10x)
– Cortex‐M3 core (startup_stm32f10x*.s, system_stm32f10x.c)
– Peripherals: GPIO, EXTI, TIM (SysTick, TimerBase), USART
- Middleware
– CMSIS (core headers & system init)
– FWlib (stm32f10x_*.c/h drivers)
- Board-support & application
– LED driver (User/Led)
– Key (button) driver (User/Key, external interrupt)
– SysTick & TimerBase (User/SysTick, User/TimerBase)
– USART1 module (User/Usatrt)
– main.c & interrupt handlers (User/main.c, User/stm32f10x_it.c)
b. Relationships & data flow
– On reset: startup assembly → system_stm32f10x.c configures clock → main() in User launches init.
– main() initializes BSP modules (LED, Key, SysTick, TimerBase, USART1).
– SysTick and TimerBase drive scheduling/ticks.
– Key presses generate EXTI interrupts → User/Key/exti.c → signals application.
– USART1 handles serial RX/TX with interrupt service routines (stm32f10x_it.c).
– Application logic toggles LED or sends data over USART.
c. Architectural patterns
– Layered: hardware → CMSIS → peripheral library → BSP → application.
– ISR-driven events + tick scheduler for timeouts.
d. Key technologies & libraries
– ARM Cortex‐M3 (CMSIS)
– ST Standard Peripheral Library (FWlib)
– GNU ARM toolchain or Keil (implied by .s startup files)

##### Essential details to capture
- Startup/reset path (assembly → system init → main).
- The layered encapsulation: application never touches registers directly, it uses BSP → FWlib → CMSIS.
- ISR registration: vector table in startup files, mapping to User interrupt handlers.
- Timer architecture: SysTick vs general-purpose TimerBase.
- Pin mapping (e.g., PAx for LED, PBx for Key, PA9/PA10 for USART1).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Hardware
    subgraph "External Hardware" 
        direction TB
        PBUTTON["Push-Button"]:::external
        LED_EXT["LED"]:::external
        TERMINAL["Serial Terminal"]:::external
    end

    %% Layers
    subgraph "Hardware (STM32F10x)" 
        direction TB
        CORE["Cortex-M3 Core"]:::hardware
        PERIPH_GPIO["GPIO Peripheral"]:::hardware
        PERIPH_EXTI["EXTI Peripheral"]:::hardware
        PERIPH_TIM["SysTick & TimerBase"]:::hardware
        PERIPH_USART["USART1 Peripheral"]:::hardware
    end

    subgraph "CMSIS Layer" 
        direction TB
        StartUp["Startup & Vector Table"]:::cmsis
        SystemInit["System Init\n(system_stm32f10x.c)"]:::cmsis
        CoreSupport["Core Support\n(core_cm3.c/h,\nstm32f10x.h)"]:::cmsis
    end

    subgraph "FWlib Layer" 
        direction TB
        FWLib["Standard Peripheral Library Drivers"]:::fwlib
    end

    subgraph "BSP Layer (User)" 
        direction TB
        Led["LED Driver"]:::bsp
        KeyDrv["Key Driver"]:::bsp
        EXTI["EXTI Handler"]:::bsp
        SysTickMod["SysTick Module"]:::bsp
        TimerBaseMod["TimerBase Module"]:::bsp
        USART1Mod["USART1 Module"]:::bsp
        Conf["BSP Config\n(stm32f10x_conf.h)"]:::bsp
    end

    subgraph "Application Layer" 
        direction TB
        Main["main.c\n(Application Entry)"]:::app
        ISR["Interrupt Service Routines\n(stm32f10x_it.c)"]:::app
    end

    %% Connections: Initialization Flow
    StartUp -->|"system_<br>init()"| SystemInit
    SystemInit --> CoreSupport
    CoreSupport --> Main

    %% Main init calls BSP modules
    Main --> Led
    Main --> KeyDrv
    Main --> SysTickMod
    Main --> TimerBaseMod
    Main --> USART1Mod

    %% BSP to FWlib
    Led --> FWLib
    KeyDrv --> FWLib
    EXTI --> FWLib
    SysTickMod --> FWLib
    TimerBaseMod --> FWLib
    USART1Mod --> FWLib

    %% FWlib to CMSIS to hardware
    FWLib --> CoreSupport
    CoreSupport --> CORE
    CoreSupport --> PERIPH_GPIO
    CoreSupport --> PERIPH_EXTI
    CoreSupport --> PERIPH_TIM
    CoreSupport --> PERIPH_USART

    %% External hardware interactions
    PERIPH_GPIO -->|LED toggle| LED_EXT
    LED_EXT -.-> Led
    PBUTTON -->|button press| PERIPH_EXTI
    PERIPH_EXTI --> EXTI
    TERMINAL -->|Rx/Tx| PERIPH_USART
    PERIPH_USART --> USART1Mod

    %% Interrupt flows
    PERIPH_EXTI -->|"EXTI IRQ"| ISR
    PERIPH_USART -->|"USART1 IRQ"| ISR
    PERIPH_TIM -->|"SysTick IRQ"| ISR

    %% ISR to Application
    ISR --> Main

    %% Click Events
    click StartUp "https://github.com/ciqi6/embedlearn/blob/main/Libraries/CMSIS/startup/startup_stm32f10x_md.s"
    click SystemInit "https://github.com/ciqi6/embedlearn/blob/main/Libraries/CMSIS/system_stm32f10x.c"
    click CoreSupport "https://github.com/ciqi6/embedlearn/blob/main/Libraries/CMSIS/core_cm3.c"
    click FWLib "https://github.com/ciqi6/embedlearn/tree/main/Libraries/FWlib"
    click Led "https://github.com/ciqi6/embedlearn/blob/main/User/Led/led.c"
    click KeyDrv "https://github.com/ciqi6/embedlearn/blob/main/User/Key/key.c"
    click EXTI "https://github.com/ciqi6/embedlearn/blob/main/User/Key/exti.c"
    click SysTickMod "https://github.com/ciqi6/embedlearn/blob/main/User/SysTick/sysTick.c"
    click TimerBaseMod "https://github.com/ciqi6/embedlearn/blob/main/User/TimerBase/timerBase.c"
    click USART1Mod "https://github.com/ciqi6/embedlearn/blob/main/User/Usatrt/usart1.c"
    click Main "https://github.com/ciqi6/embedlearn/blob/main/User/main.c"
    click ISR "https://github.com/ciqi6/embedlearn/blob/main/User/stm32f10x_it.c"
    click Conf "https://github.com/ciqi6/embedlearn/blob/main/User/stm32f10x_conf.h"

    %% Styles
    classDef hardware fill:#dddddd,stroke:#333,stroke-width:1px
    classDef cmsis fill:#add8e6,stroke:#333,stroke-width:1px
    classDef fwlib fill:#87cefa,stroke:#333,stroke-width:1px
    classDef bsp fill:#98fb98,stroke:#333,stroke-width:1px
    classDef app fill:#ffa500,stroke:#333,stroke-width:1px
    classDef external fill:#ffc0cb,stroke:#333,stroke-width:1px
```
