# pierremergon/pleiades-sensor-integration architecture

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

- Interactive diagram: https://gitdiagram.com/pierremergon/pleiades-sensor-integration
- Repository: https://github.com/pierremergon/pleiades-sensor-integration

## Overview

##### Project type and purpose
- This is an embedded‐firmware project for an STM32H5 series microcontroller, generated by STM32CubeIDE. Its purpose is to integrate an SHT40 temperature/humidity sensor (over I²C) with the Pleiades hardware platform, using STM32 HAL drivers plus a custom sensor library.

##### File structure
- Top‐level:
- Pleiades-Sensor-Integration.ioc — CubeMX configuration defining clocks, pins, I²C, NVIC, middleware.
- Core/Inc & Core/Src — application entry point (main.c), system & interrupt handlers, HAL MSP init, timebase, syscalls, sysmem, sensor‐library header/.c.
- Core/Startup — MCU startup assembly for STM32H503RBTx.
- Drivers/STM32H5xx_HAL_Driver — STM32Cube HAL source code (I²C, GPIO, timers, NVIC, etc.).
- STM32H503RBTX_FLASH.ld — linker script.
- Debug folder is auto‐generated build artifacts.

##### README
- Minimal: project title indicates “Sensor Integration for Pleiades.” No further architecture details.

##### Main components
a. Hardware layer
- STM32H503RBTx MCU (core, registers, NVIC)
- SHT40 Sensor (I²C peripheral on MCU)
- Optional: USB/UART connector for debug/PC comms
b. Firmware layers
- Startup code (assembly, vector table)
- System initialization (system_stm32h5xx.c, HAL_Init, clock config)
- HAL drivers (I²C, GPIO, TIM, NVIC)
- Sensor library (sht40_lib.c/.h)
- Application logic (main.c)
- Syscalls/sysmem for newlib retarget (syscalls.c, sysmem.c)
c. Toolchain and build
- STM32CubeIDE/CubeMX (ioc, .mxproject) generating code + Makefile
- Linker script, output ELF

##### Relationships and interactions
- MCU startup → system init → HAL_Init
- HAL I²C driver ↔ SHT40 sensor on I²C bus
- Application (main.c) calls sensor API → returns temperature/humidity
- TIM2 timebase → HAL tick interrupt → systick for delays/timeouts
- NVIC dispatches I²C/TIM interrupts to HAL callbacks
- Syscalls layer provides read/write for printf over UART (if used)

##### Architectural patterns & principles
- Layered architecture: hardware abstraction (HAL) below sensor driver, below application.
- Initialization flow: Reset handler → SystemClock_Config → peripheral init → main loop.
- ISR‐driven events and polling coexist: HAL_I2C_Master_Receive() or interrupt callbacks.

##### What to include for maximum detail
- Vector table startup → Reset_Handler
- SystemClock_Config block
- HAL_Init and peripheral init sequence
- I²C peripheral instance (e.g. I2C1) mapped to GPIO pins
- Timer used for HAL tick (TIM2)
- Sensor library API functions (e.g. SHT40_Read)
- main() infinite loop or RTOS hook if used
- Linker script region assignments (FLASH, SRAM) if relevant for memory map
- Debug interface (UART or SWD)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration and Build
    subgraph "Configuration & Build"
        direction TB
        IOC["Pleiades-Sensor-Integration.ioc"]:::config
        LINKER["STM32H503RBTX_FLASH.ld"]:::config
    end

    %% Startup
    subgraph "Startup Code"
        direction TB
        RESET["Reset_Handler\n(vector table)"]:::startup
    end

    %% System Initialization
    subgraph "System Initialization"
        direction TB
        SYSCLK["SystemClock_Config\n& HAL_Init"]:::system
        MSP["HAL MSP Init"]:::system
        TIMEBASE["HAL Timebase (TIM2)"]:::system
    end

    %% Interrupt Handlers
    subgraph "Interrupt Handlers"
        direction TB
        NVIC_IT["NVIC Dispatch & ISRs"]:::interrupt
    end

    %% HAL Drivers
    subgraph "HAL Drivers"
        direction TB
        HAL["STM32H5xx HAL Driver\n(I2C, GPIO, TIM, NVIC)"]:::hal
    end

    %% Sensor Library
    subgraph "Sensor Library"
        direction TB
        SHT40["SHT40 Library\n(sht40_lib.c/.h)"]:::sensor
    end

    %% Application Logic
    subgraph "Application"
        direction TB
        MAIN["main.c\nmain.h"]:::app
    end

    %% Syscalls & Sysmem
    subgraph "Syscalls & Sysmem"
        direction TB
        SYSCALLS["syscalls.c"]:::system
        SYSMEM["sysmem.c"]:::system
    end

    %% Hardware Layer
    subgraph "Hardware"
        direction TB
        MCU["STM32H503RBTx MCU"]:::hardware
        I2C1["I2C1 Peripheral"]:::hardware
        TIM2["TIM2 Timer"]:::hardware
        NVIC_HW["NVIC"]:::hardware
        SHT40_HW["SHT40 Sensor"]:::hardware
        UART["UART Debug Interface"]:::hardware
    end

    %% Flows
    IOC -->|"generates"| RESET
    RESET -->|"calls"| SYSCLK
    SYSCLK -->|"initializes"| MSP
    MSP -->|"configures tick"| TIMEBASE
    TIMEBASE -->|"drives SysTick"| MAIN
    SYSCLK -->|"initializes HAL"| HAL
    MAIN -->|"calls SHT40_Read"| SHT40
    SHT40 -->|"uses HAL I2C API"| HAL
    HAL -->|"drives I2C1"| I2C1
    I2C1 -->|"connects to"| SHT40_HW
    NVIC_HW ---|"interrupts"| NVIC_IT
    NVIC_IT -->|"calls HAL callbacks"| MAIN
    TIM2 -->|"tick interrupt"| NVIC_IT
    SYSCALLS -->|"retargets printf"| UART
    SYSMEM -->|"manages heap"| MAIN
    LINKER -->|"links sections"| MAIN

    %% Click Events
    click IOC "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Pleiades-Sensor-Integration.ioc"
    click LINKER "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/STM32H503RBTX_FLASH.ld"
    click RESET "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Startup/startup_stm32h503rbtx.s"
    click SYSCLK "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/system_stm32h5xx.c"
    click MSP "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/stm32h5xx_hal_msp.c"
    click TIMEBASE "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/stm32h5xx_hal_timebase_tim.c"
    click NVIC_IT "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/stm32h5xx_it.c"
    click HAL "https://github.com/pierremergon/pleiades-sensor-integration/tree/main/Pleiades-Sensor-Integration/Drivers/STM32H5xx_HAL_Driver/"
    click SHT40 "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/sht40_lib.c"
    click MAIN "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/main.c"
    click SYSCALLS "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/syscalls.c"
    click SYSMEM "https://github.com/pierremergon/pleiades-sensor-integration/blob/main/Pleiades-Sensor-Integration/Core/Src/sysmem.c"

    %% Styles
    classDef config fill:#f9f,stroke:#333,stroke-width:1px
    classDef startup fill:#ffeb99,stroke:#333,stroke-width:1px
    classDef system fill:#fff2cc,stroke:#333,stroke-width:1px
    classDef interrupt fill:#fde9d9,stroke:#333,stroke-width:1px
    classDef hal fill:#cfe2f3,stroke:#333,stroke-width:1px
    classDef sensor fill:#d9ead3,stroke:#333,stroke-width:1px
    classDef app fill:#f4cccc,stroke:#333,stroke-width:1px
    classDef hardware fill:#e7e6e6,stroke:#333,stroke-width:1px
```
