# sabanekko3/smdu_firmware_v2 architecture

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

- Interactive diagram: https://gitdiagram.com/sabanekko3/smdu_firmware_v2
- Repository: https://github.com/sabanekko3/smdu_firmware_v2

## Overview

This is STM32F3 embedded motor-control firmware. Its central runtime is the MCU application: timer callbacks invoke motor control and encoder sampling, while the main loop provides ongoing application/debug activity. The user library separates motor actuation, sensing and encoder handling, CAN communication, and motor math. Hardware setup and vendor CMSIS/HAL support are represented as internal layers. Source excerpts are partial and the README is empty, so links not directly evidenced are omitted.

Main entry points: [`Core/Src/main.cpp`](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/Src/main.cpp) (Application loop), [`Core/user_lib/motor.cpp`](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/motor.cpp) (Motor control), [`Core/user_lib/encoder.cpp`](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/encoder.cpp) (Encoder handling), [`Core/Src`](https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Core/Src) (Peripheral setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Firmware runtime"]
  node_main["Application loop<br/>[main.cpp]"]
  node_board_data["Board definitions<br/>[board_data.hpp]"]
end

subgraph group_control["Motor control"]
  node_motor["Motor control<br/>[motor.cpp]"]
  node_driver["Motor driver<br/>[driver.cpp]"]
  node_pwm["PWM output<br/>[pwm.cpp]"]
  node_motor_math["Motor math<br/>[motor_math.cpp]"]
end

subgraph group_sensing["Sensing and communication"]
  node_measure["Motor measurement<br/>[motor_measure.cpp]"]
  node_encoder["Encoder handling<br/>[encoder.cpp]"]
  node_analog["Analog sensors<br/>[analog_sens.cpp]"]
  node_can["CAN communication<br/>[can.cpp]"]
end

subgraph group_platform["MCU platform"]
  node_peripherals["Peripheral setup"]
  node_interrupts["Interrupt handlers<br/>[stm32f3xx_it.c]"]
  node_cmsis["CMSIS core and DSP"]
  node_device["STM32 device access"]
  node_hal["STM32 HAL"]
end

node_mcu(("STM32F3 MCU"))
node_motor_hardware{{"Motor and sensors"}}
node_can_bus{{"CAN bus"}}

node_main -->|"invokes control"| node_motor
node_main -->|"starts sampling"| node_encoder
node_main -->|"instantiates"| node_measure
node_main -->|"instantiates"| node_can
node_main -->|"configures outputs"| node_pwm
node_motor -.->|"actuates"| node_motor_hardware
node_encoder -.->|"reads position"| node_motor_hardware
node_analog -.->|"reads signals"| node_motor_hardware
node_can -.->|"communicates"| node_can_bus
node_motor -.->|"uses"| node_driver
node_motor -.->|"uses"| node_pwm
node_motor -.->|"uses"| node_motor_math
node_motor -.->|"uses"| node_encoder
node_main -.->|"initializes"| node_peripherals
node_interrupts -.->|"handles events"| node_peripherals
node_peripherals -.->|"uses"| node_hal
node_hal -.->|"accesses registers"| node_device
node_motor_math -->|"uses DSP"| node_cmsis
node_main -.->|"runs on"| node_mcu
node_board_data -.->|"defines board data"| node_main

click node_main "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/Src/main.cpp"
click node_motor "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/motor.cpp"
click node_driver "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/driver.cpp"
click node_pwm "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/pwm.cpp"
click node_motor_math "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/motor_math.cpp"
click node_measure "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/motor_measure.cpp"
click node_encoder "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/encoder.cpp"
click node_analog "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/analog_sens.cpp"
click node_can "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/can.cpp"
click node_board_data "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/board_data.hpp"
click node_peripherals "https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Core/Src"
click node_interrupts "https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/Src/stm32f3xx_it.c"
click node_cmsis "https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Drivers/CMSIS/Include"
click node_device "https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Drivers/CMSIS/Device/ST/STM32F3xx/Include"
click node_hal "https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Drivers/STM32F3xx_HAL_Driver"

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_board_data toneBlue
class node_motor,node_driver,node_pwm,node_motor_math toneAmber
class node_measure,node_encoder,node_analog,node_can toneMint
class node_peripherals,node_interrupts,node_cmsis,node_device,node_hal toneRose
class node_mcu,node_motor_hardware,node_can_bus toneIndigo
```

## Components

### Firmware runtime

- [Application loop](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/Src/main.cpp): `Core/Src/main.cpp`
- [Board definitions](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/board_data.hpp): `Core/user_lib/board_data.hpp`

### Motor control

- [Motor control](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/motor.cpp): `Core/user_lib/motor.cpp`
- [Motor driver](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/driver.cpp): `Core/user_lib/driver.cpp`
- [PWM output](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/pwm.cpp): `Core/user_lib/pwm.cpp`
- [Motor math](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/motor_math.cpp): `Core/user_lib/motor_math.cpp`

### Sensing and communication

- [Motor measurement](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/motor_measure.cpp): `Core/user_lib/motor_measure.cpp`
- [Encoder handling](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/encoder.cpp): `Core/user_lib/encoder.cpp`
- [Analog sensors](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/analog_sens.cpp): `Core/user_lib/analog_sens.cpp`
- [CAN communication](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/user_lib/can.cpp): `Core/user_lib/can.cpp`

### MCU platform

- [Peripheral setup](https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Core/Src): `Core/Src`
- [Interrupt handlers](https://github.com/sabanekko3/smdu_firmware_v2/blob/master/Core/Src/stm32f3xx_it.c): `Core/Src/stm32f3xx_it.c`
- [CMSIS core and DSP](https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Drivers/CMSIS/Include): `Drivers/CMSIS/Include`
- [STM32 device access](https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Drivers/CMSIS/Device/ST/STM32F3xx/Include): `Drivers/CMSIS/Device/ST/STM32F3xx/Include`
- [STM32 HAL](https://github.com/sabanekko3/smdu_firmware_v2/tree/master/Drivers/STM32F3xx_HAL_Driver): `Drivers/STM32F3xx_HAL_Driver`

### Other components

- **STM32F3 MCU**
- **Motor and sensors**
- **CAN bus**

## Connections

- Application loop → Motor control: invokes control (evidence: `Core/Src/main.cpp`)
- Application loop → Encoder handling: starts sampling (evidence: `Core/Src/main.cpp`)
- Application loop → Motor measurement: instantiates (evidence: `Core/Src/main.cpp`)
- Application loop → CAN communication: instantiates (evidence: `Core/Src/main.cpp`)
- Application loop → PWM output: configures outputs (evidence: `Core/Src/main.cpp`)
- Motor control → Motor and sensors: actuates
- Encoder handling → Motor and sensors: reads position
- Analog sensors → Motor and sensors: reads signals
- CAN communication → CAN bus: communicates
- Motor control → Motor driver: uses
- Motor control → PWM output: uses
- Motor control → Motor math: uses
- Motor control → Encoder handling: uses
- Application loop → Peripheral setup: initializes
- Interrupt handlers → Peripheral setup: handles events
- Peripheral setup → STM32 HAL: uses
- STM32 HAL → STM32 device access: accesses registers (evidence: `Drivers/STM32F3xx_HAL_Driver/Inc/stm32f3xx_hal_def.h`)
- Motor math → CMSIS core and DSP: uses DSP
- Application loop → STM32F3 MCU: runs on
- Board definitions → Application loop: defines board data
