# arjun-sadananda/temp architecture

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

- Interactive diagram: https://gitdiagram.com/arjun-sadananda/temp
- Repository: https://github.com/arjun-sadananda/temp

## Overview

1. **Project type and runtime**
   - This is bare-metal embedded firmware for an STM32H743-class MCU, not an app/server.
   - The repo is clearly a drone flight controller stack: it ingests sensors and radio control, estimates attitude/state, runs control loops, and drives motors.

2. **Repo boundary: generated platform code vs application logic**
   - `Core/` and `Drivers/` are the hardware abstraction and startup layer, mostly STM32CubeMX-generated.
   - `Hardware/` and `Modules/` are the application-specific flight stack.
   - `main.cpp` in `Core/Src` is the top-level orchestration point that ties the generated peripherals to the drone logic.

3. **Platform bring-up**
   - `startup_stm32h743xx.s`, `STM32H743XX_FLASH.ld`, and `system_stm32h7xx.c` define boot, memory layout, and system clock/runtime setup.
   - `Core/Src/stm32h7xx_hal_msp.c`, `gpio.c`, `spi.c`, `tim.c`, `usart.c`, `dma.c` initialize the MCU peripherals used by the application.
   - `stm32h7xx_it.c` handles interrupt entry points, so the firmware is interrupt- and DMA-driven rather than polling-only.

4. **Peripheral roles in the architecture**
   - **SPI** is used for sensor communication, especially the IMU.
   - **USART** is used for serial links such as CRSF radio control and likely debugging/telemetry.
   - **TIM + DMA** are used for time-critical motor signaling, which matches the presence of DSHOT.
   - GPIO provides chip selects, mode pins, and other discrete control lines.

5. **Sensor hardware subsystem**
   - `Hardware/IMU/icm426xx.*` is a device driver for the ICM426xx IMU family.
   - `Hardware/OptFlow/mtf01.*` is an optical-flow sensor interface.
   - These modules are the primary state-input sources for estimation and stabilization.

6. **Radio/command input subsystem**
   - `Hardware/RC/crsf.*` implements the CRSF protocol over serial.
   - `Hardware/RC/rc.*` likely normalizes incoming radio channels into internal control inputs.
   - This is the manual command path into the control system.

7. **Motor output subsystem**
   - `Hardware/Motor/dshot.*` is the ESC output protocol layer.
   - `Hardware/Motor/motor.*` is the higher-level motor mixer/actuator interface.
   - `Hardware/Motor/dump.c` suggests diagnostics or captured motor-output/debug data.
   - The output path is therefore abstracted: control code produces throttle/mixer commands, and the motor layer turns them into DSHOT waveform timing.

8. **Estimation subsystem**
   - `Modules/Estimator/Estimator.h` and `MEKF.h` indicate the main estimator is a multiplicative extended Kalman filter.
   - This module fuses IMU and possibly optical-flow inputs into attitude/state estimates.
   - The estimator is the bridge between raw sensors and the controller layer.

9. **Control subsystem**
   - `Modules/Controller/` contains multiple control modes: `Acro`, `Euler_Stabilize`, `Geometric_Stabilize`, and `TP_Control`.
   - This implies the firmware supports at least rate/acro control plus stabilized flight modes.
   - The controller consumes pilot commands plus estimated state and produces desired body rates/attitude/motor corrections.

10. **Math and signal-processing support**
   - `Modules/Math/` provides vector, matrix, quaternion, and rotation primitives used by estimation and control.
   - `Modules/filter.c` / `filter.h` provide additional signal conditioning.
   - These are core reusable utilities, not hardware-specific code.

11. **Application data flow**
   - Input path: IMU / optical flow / RC enter through hardware drivers and MCU peripherals.
   - Processing path: estimator fuses sensor data, control law computes actuation commands, mixer maps commands to motors.
   - Output path: motor module emits DSHOT over timer/DMA to the ESCs.
   - Interrupts and DMA likely feed timing-sensitive acquisition/output, while `main.cpp` coordinates the higher-level loop.

12. **Build and configuration tooling**
   - The project uses CMake (`CMakeLists.txt`, `CMakePresets.json`, `cmake/gcc-arm-none-eabi.cmake`, `cmake/stm32cubemx/`), so the firmware is built outside the IDE as well.
   - The `.ioc` files show STM32CubeMX-generated configuration sources the platform layer was derived from.
   - The repo also vendors STM32 HAL, CMSIS, CMSIS-DSP, and CMSIS-NN packages under `Drivers/`, which form the hardware and DSP foundation.

13. **External/library boundaries**
   - STM32 HAL/CMSIS provide peripheral drivers, startup, and device headers; the flight logic stays above that boundary.
   - CMSIS-DSP and CMSIS-NN are present in-tree, but the visible application code is more centered on classical flight-control math than on neural inference.
   - No web, cloud, or OS service boundary is visible; this is an embedded real-time control system running directly on the MCU.

Main entry points: [`Core/Src/stm32h7xx_hal_msp.c`](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/stm32h7xx_hal_msp.c) (msp init), [`Core/Src/main.cpp`](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/main.cpp) (main), [`Modules/Controller/Acro.h`](https://github.com/arjun-sadananda/temp/blob/main/Modules/Controller/Acro.h) (controller), [`Modules/Estimator/Estimator.h`](https://github.com/arjun-sadananda/temp/blob/main/Modules/Estimator/Estimator.h) (estimator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Platform"]
  node_main["main<br/>orchestrator<br/>[main.cpp]"]
  node_startup["startup<br/>boot/linker"]
  node_system["system<br/>clock/runtime<br/>[system_stm32h7xx.c]"]
  node_hal_msp["msp init<br/>HAL board init"]
  node_irq["interrupts<br/>IRQ handlers<br/>[stm32h7xx_it.c]"]
  node_spi["SPI<br/>peripheral setup<br/>[spi.c]"]
  node_usart["USART<br/>peripheral setup<br/>[usart.c]"]
  node_tim_dma["TIM/DMA<br/>peripheral setup<br/>[tim.c]"]
  node_gpio["GPIO<br/>peripheral setup<br/>[gpio.c]"]
end

subgraph group_hardware["Hardware I/O"]
  node_imu["IMU<br/>sensor driver<br/>[imu.cpp]"]
  node_icm426xx["icm426xx<br/>IMU device driver<br/>[icm426xx.cpp]"]
  node_optflow["opt flow<br/>sensor driver<br/>[mtf01.c]"]
  node_crsf["CRSF<br/>radio protocol<br/>[crsf.c]"]
  node_rc["RC input<br/>input normalize<br/>[rc.c]"]
  node_dshot["DSHOT<br/>motor protocol<br/>[dshot.c]"]
  node_motor["motors<br/>actuator mixer<br/>[motor.c]"]
end

subgraph group_flight["Flight Logic"]
  node_mekf["MEKF<br/>state estimator<br/>[MEKF.h]"]
  node_estimator["estimator<br/>state fusion<br/>[Estimator.h]"]
  node_controller["controller<br/>flight control<br/>[Acro.h]"]
end

subgraph group_support["Support"]
  node_math["math<br/>linear algebra<br/>[quaternion.h]"]
  node_filter["filter<br/>signal processing<br/>[filter.h]"]
end

subgraph group_tooling["Tooling"]
  node_build["cmake<br/>build system<br/>[CMakeLists.txt]"]
  node_cube["CubeMX<br/>config source<br/>[Pushpak.ioc]"]
end

node_startup -->|"boot init"| node_system
node_system -->|"runtime setup"| node_hal_msp
node_hal_msp -->|"configures"| node_spi
node_hal_msp -->|"configures"| node_usart
node_hal_msp -->|"configures"| node_tim_dma
node_hal_msp -->|"configures"| node_gpio
node_irq -->|"services"| node_spi
node_irq -->|"services"| node_tim_dma
node_main -->|"reads"| node_imu
node_imu -->|"implements"| node_icm426xx
node_main -->|"reads"| node_optflow
node_main -->|"receives"| node_crsf
node_crsf -->|"normalizes"| node_rc
node_main -->|"feeds"| node_estimator
node_estimator -->|"implements"| node_mekf
node_estimator -->|"uses"| node_math
node_controller -->|"uses"| node_math
node_controller -->|"uses"| node_filter
node_estimator -->|"state to control"| node_controller
node_rc -->|"pilot commands"| node_controller
node_controller -->|"actuation"| node_motor
node_motor -->|"encodes"| node_dshot
node_dshot -->|"emits"| node_tim_dma
node_main -->|"built by"| node_build
node_cube -.->|"generates"| node_hal_msp

click node_main "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/main.cpp"
click node_startup "https://github.com/arjun-sadananda/temp/blob/main/startup_stm32h743xx.s"
click node_system "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/system_stm32h7xx.c"
click node_hal_msp "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/stm32h7xx_hal_msp.c"
click node_irq "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/stm32h7xx_it.c"
click node_spi "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/spi.c"
click node_usart "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/usart.c"
click node_tim_dma "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/tim.c"
click node_gpio "https://github.com/arjun-sadananda/temp/blob/main/Core/Src/gpio.c"
click node_imu "https://github.com/arjun-sadananda/temp/blob/main/Hardware/IMU/imu.cpp"
click node_icm426xx "https://github.com/arjun-sadananda/temp/blob/main/Hardware/IMU/icm426xx.cpp"
click node_optflow "https://github.com/arjun-sadananda/temp/blob/main/Hardware/OptFlow/mtf01.c"
click node_crsf "https://github.com/arjun-sadananda/temp/blob/main/Hardware/RC/crsf.c"
click node_rc "https://github.com/arjun-sadananda/temp/blob/main/Hardware/RC/rc.c"
click node_dshot "https://github.com/arjun-sadananda/temp/blob/main/Hardware/Motor/dshot.c"
click node_motor "https://github.com/arjun-sadananda/temp/blob/main/Hardware/Motor/motor.c"
click node_mekf "https://github.com/arjun-sadananda/temp/blob/main/Modules/Estimator/MEKF.h"
click node_estimator "https://github.com/arjun-sadananda/temp/blob/main/Modules/Estimator/Estimator.h"
click node_controller "https://github.com/arjun-sadananda/temp/blob/main/Modules/Controller/Acro.h"
click node_math "https://github.com/arjun-sadananda/temp/blob/main/Modules/Math/quaternion.h"
click node_filter "https://github.com/arjun-sadananda/temp/blob/main/Modules/filter.h"
click node_build "https://github.com/arjun-sadananda/temp/blob/main/CMakeLists.txt"
click node_cube "https://github.com/arjun-sadananda/temp/blob/main/Pushpak.ioc"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_startup,node_system,node_hal_msp,node_irq,node_spi,node_usart,node_tim_dma,node_gpio toneBlue
class node_imu,node_icm426xx,node_optflow,node_crsf,node_rc,node_dshot,node_motor toneAmber
class node_mekf,node_estimator,node_controller toneMint
class node_math,node_filter toneRose
class node_build,node_cube toneIndigo
```

## Components

### Platform

MCU startup, HAL, interrupts, and peripheral setup

- [main](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/main.cpp): orchestrator · Top-level firmware entry that wires peripherals into the flight stack · `Core/Src/main.cpp`
- [startup](https://github.com/arjun-sadananda/temp/blob/main/startup_stm32h743xx.s): boot/linker · Reset entry and flash memory layout · `startup_stm32h743xx.s`
- [system](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/system_stm32h7xx.c): clock/runtime · System clock and low-level runtime setup · `Core/Src/system_stm32h7xx.c`
- [msp init](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/stm32h7xx_hal_msp.c): HAL board init · MCU-specific peripheral pin and clock initialization · `Core/Src/stm32h7xx_hal_msp.c`
- [interrupts](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/stm32h7xx_it.c): IRQ handlers · Interrupt entry points for timing- and DMA-driven operation · `Core/Src/stm32h7xx_it.c`
- [SPI](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/spi.c): peripheral setup · Serial bus used for sensor communication · `Core/Src/spi.c`
- [USART](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/usart.c): peripheral setup · Serial links for radio control and telemetry/debug · `Core/Src/usart.c`
- [TIM/DMA](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/tim.c): peripheral setup · Timer and DMA channels used for time-critical output and capture · `Core/Src/tim.c`
- [GPIO](https://github.com/arjun-sadananda/temp/blob/main/Core/Src/gpio.c): peripheral setup · Discrete control lines such as chip selects and modes · `Core/Src/gpio.c`

### Hardware I/O

Device drivers for sensors, radio, and motors

- [IMU](https://github.com/arjun-sadananda/temp/blob/main/Hardware/IMU/imu.cpp): sensor driver · ICM426xx inertial sensor driver and interface · `Hardware/IMU/imu.cpp`
- [icm426xx](https://github.com/arjun-sadananda/temp/blob/main/Hardware/IMU/icm426xx.cpp): IMU device driver · ICM426xx-family register-level driver · `Hardware/IMU/icm426xx.cpp`
- [opt flow](https://github.com/arjun-sadananda/temp/blob/main/Hardware/OptFlow/mtf01.c): sensor driver · Optical-flow sensor interface · `Hardware/OptFlow/mtf01.c`
- [CRSF](https://github.com/arjun-sadananda/temp/blob/main/Hardware/RC/crsf.c): radio protocol · Serial radio-control protocol implementation · `Hardware/RC/crsf.c`
- [RC input](https://github.com/arjun-sadananda/temp/blob/main/Hardware/RC/rc.c): input normalize · Normalizes received radio channels into internal commands · `Hardware/RC/rc.c`
- [DSHOT](https://github.com/arjun-sadananda/temp/blob/main/Hardware/Motor/dshot.c): motor protocol · ESC protocol and waveform generation layer · `Hardware/Motor/dshot.c`
- [motors](https://github.com/arjun-sadananda/temp/blob/main/Hardware/Motor/motor.c): actuator mixer · High-level motor command and mixing interface · `Hardware/Motor/motor.c`

### Flight Logic

Estimation and control layers for the drone

- [MEKF](https://github.com/arjun-sadananda/temp/blob/main/Modules/Estimator/MEKF.h): state estimator · Multiplicative EKF fusing sensors into attitude/state estimates · `Modules/Estimator/MEKF.h`
- [estimator](https://github.com/arjun-sadananda/temp/blob/main/Modules/Estimator/Estimator.h): state fusion · Estimation interface between raw sensors and control · `Modules/Estimator/Estimator.h`
- [controller](https://github.com/arjun-sadananda/temp/blob/main/Modules/Controller/Acro.h): flight control · Flight-mode control layer producing stabilization and rate commands · `Modules/Controller/Acro.h`

### Support

Reusable math and signal-processing code

- [math](https://github.com/arjun-sadananda/temp/blob/main/Modules/Math/quaternion.h): linear algebra · Vectors, matrices, quaternions, and rotations · `Modules/Math/quaternion.h`
- [filter](https://github.com/arjun-sadananda/temp/blob/main/Modules/filter.h): signal processing · Additional filtering and conditioning utilities · `Modules/filter.h`

### Tooling

Build and configuration entry points

- [cmake](https://github.com/arjun-sadananda/temp/blob/main/CMakeLists.txt): build system · CMake and toolchain configuration for the firmware build · `CMakeLists.txt`
- [CubeMX](https://github.com/arjun-sadananda/temp/blob/main/Pushpak.ioc): config source · STM32CubeMX-generated project configuration · `Pushpak.ioc`

## Connections

- startup → system: boot init · Startup transfers into system/runtime initialization
- system → msp init: runtime setup · System setup precedes peripheral bring-up
- msp init → SPI: configures · HAL board init configures SPI peripheral
- msp init → USART: configures · HAL board init configures USART peripheral
- msp init → TIM/DMA: configures · HAL board init configures timer/DMA for time-critical I/O
- msp init → GPIO: configures · HAL board init configures GPIO lines
- interrupts → SPI: services · Interrupts service SPI/DMA-driven sensor traffic
- interrupts → TIM/DMA: services · Interrupts service timer/DMA-driven output timing
- main → IMU: reads · Main orchestration consumes IMU data
- IMU → icm426xx: implements · IMU module is backed by the ICM426xx driver
- main → opt flow: reads · Main orchestration can consume optical-flow data
- main → CRSF: receives · Main orchestration receives radio-control frames
- CRSF → RC input: normalizes · CRSF frames are mapped into internal RC channels
- main → estimator: feeds · Sensor inputs are passed into the estimator
- estimator → MEKF: implements · Estimator interface centers on a MEKF state filter
- estimator → math: uses · State fusion relies on math primitives
- controller → math: uses · Flight control computations rely on math primitives
- controller → filter: uses · Controller uses filtering/conditioning utilities
- estimator → controller: state to control · Estimated state informs the control layer
- RC input → controller: pilot commands · Normalized radio commands drive the controller
- controller → motors: actuation · Controller outputs are mapped to motor commands
- motors → DSHOT: encodes · Motor layer encodes ESC commands as DSHOT
- DSHOT → TIM/DMA: emits · DSHOT waveform generation uses timer/DMA timing
- main → cmake: built by · Firmware is built through the CMake toolchain
- CubeMX → msp init: generates · CubeMX configuration underlies platform initialization
