# eduarmproject/stm32_driver architecture

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

- Interactive diagram: https://gitdiagram.com/eduarmproject/stm32_driver
- Repository: https://github.com/eduarmproject/stm32_driver

## Overview

This repository is firmware for an STM32-based robotic-arm motor controller, with a CAN-addressed motor interface and reusable stepper-driver and encoder components. The visible startup workflow initializes MCU peripherals, reads the motor address from DIP switches, and configures CAN filtering; a CAN receive callback stores incoming commands. Although command opcodes and a state machine are defined, the sampled runtime does not show commands being executed: the main loop is idle, and its separate motor FSM entry point is not called. The README is empty, so capability descriptions are limited to the tree and sampled code.

Main entry points: [`Core/Src/fdcan.c`](https://github.com/eduarmproject/stm32_driver/blob/main/Core/Src/fdcan.c) (CAN controller), [`Core/Src/main.c`](https://github.com/eduarmproject/stm32_driver/blob/main/Core/Src/main.c) (Application entry), [`Core/Src`](https://github.com/eduarmproject/stm32_driver/tree/main/Core/Src) (Peripheral setup), [`EduArmLib/Protocols/canfd_protocol.c`](https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Protocols/canfd_protocol.c) (CAN configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Firmware startup"]
  node_boot["Application entry<br/>[main.c]"]
  node_peripherals["Peripheral setup"]
end

subgraph group_can["CAN motor control"]
  node_motorfsm["Motor state and commands<br/>[motor_can.c]"]
  node_canconfig["CAN configuration<br/>[canfd_protocol.c]"]
  node_canbus["CAN controller<br/>[fdcan.c]"]
end

subgraph group_drivers["Motor and encoder drivers"]
  node_tmc["TMC2209 driver<br/>[tmc2209.c]"]
  node_encoder["AS5047 encoder<br/>[as5047.c]"]
end

subgraph group_protocols["Device protocols"]
  node_uartproto["UART half-duplex<br/>[uart_protocol.c]"]
  node_spiproto["SPI transfer<br/>[spi_protocol.c]"]
end

node_motor(("Motor network"))
node_sensor(("Magnetic encoder"))

node_boot -->|"initializes"| node_peripherals
node_boot -->|"reads address"| node_motorfsm
node_boot -->|"configures CAN"| node_canconfig
node_peripherals -->|"initializes"| node_canbus
node_canconfig -->|"starts interface"| node_canbus
node_motor -.->|"sends commands"| node_canbus
node_canbus -->|"delivers received frame"| node_motorfsm
node_tmc -->|"transmits registers"| node_uartproto
node_encoder -->|"uses SPI transfer"| node_spiproto
node_sensor -.->|"provides measurements"| node_encoder

click node_boot "https://github.com/eduarmproject/stm32_driver/blob/main/Core/Src/main.c"
click node_peripherals "https://github.com/eduarmproject/stm32_driver/tree/main/Core/Src"
click node_motorfsm "https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/FSM/motor_can.c"
click node_canconfig "https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Protocols/canfd_protocol.c"
click node_canbus "https://github.com/eduarmproject/stm32_driver/blob/main/Core/Src/fdcan.c"
click node_tmc "https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Components/tmc2209.c"
click node_encoder "https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Components/as5047.c"
click node_uartproto "https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Protocols/uart_protocol.c"
click node_spiproto "https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Protocols/spi_protocol.c"

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_boot,node_peripherals toneBlue
class node_motorfsm,node_canconfig,node_canbus toneAmber
class node_tmc,node_encoder toneMint
class node_uartproto,node_spiproto toneRose
class node_motor,node_sensor toneIndigo
```

## Components

### Firmware startup

- [Application entry](https://github.com/eduarmproject/stm32_driver/blob/main/Core/Src/main.c): `Core/Src/main.c`
- [Peripheral setup](https://github.com/eduarmproject/stm32_driver/tree/main/Core/Src): `Core/Src`

### CAN motor control

- [Motor state and commands](https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/FSM/motor_can.c): `EduArmLib/FSM/motor_can.c`
- [CAN configuration](https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Protocols/canfd_protocol.c): `EduArmLib/Protocols/canfd_protocol.c`
- [CAN controller](https://github.com/eduarmproject/stm32_driver/blob/main/Core/Src/fdcan.c): `Core/Src/fdcan.c`

### Motor and encoder drivers

- [TMC2209 driver](https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Components/tmc2209.c): `EduArmLib/Components/tmc2209.c`
- [AS5047 encoder](https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Components/as5047.c): `EduArmLib/Components/as5047.c`

### Device protocols

- [UART half-duplex](https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Protocols/uart_protocol.c): `EduArmLib/Protocols/uart_protocol.c`
- [SPI transfer](https://github.com/eduarmproject/stm32_driver/blob/main/EduArmLib/Protocols/spi_protocol.c): `EduArmLib/Protocols/spi_protocol.c`

### Other components

- **Motor network**
- **Magnetic encoder**

## Connections

- Application entry → Peripheral setup: initializes (evidence: `Core/Src/main.c`)
- Application entry → Motor state and commands: reads address (evidence: `Core/Src/main.c`)
- Application entry → CAN configuration: configures CAN (evidence: `Core/Src/main.c`)
- Peripheral setup → CAN controller: initializes (evidence: `Core/Src/fdcan.c`)
- CAN configuration → CAN controller: starts interface (evidence: `EduArmLib/Protocols/canfd_protocol.c`)
- Motor network → CAN controller: sends commands
- CAN controller → Motor state and commands: delivers received frame (evidence: `EduArmLib/FSM/motor_can.c`)
- TMC2209 driver → UART half-duplex: transmits registers (evidence: `EduArmLib/Components/tmc2209.c`)
- AS5047 encoder → SPI transfer: uses SPI transfer
- Magnetic encoder → AS5047 encoder: provides measurements
