# alkamotors/am32-multirotor-esc-firmware architecture

> Architecture diagram of the GitHub repository alkamotors/am32-multirotor-esc-firmware, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alkamotors/am32-multirotor-esc-firmware
- Repository: https://github.com/alkamotors/am32-multirotor-esc-firmware

## Overview

AM32 is embedded ESC firmware for STM32-based brushless motor controllers. Its principal workflow is receiving servo PWM or DShot throttle commands, interpreting them in firmware, and driving motor commutation; documented variants add bidirectional DShot, telemetry, sinusoidal startup, and crawler-oriented behavior. The tree also shows MCU-specific peripheral, ADC, comparator, IO, and flash-settings layers. The main-loop excerpt confirms startup and motor-control responsibilities, but omitted source prevents tracing every protocol and peripheral call, so uncertain wiring is left out.

Main entry points: [`Src/main.c`](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/main.c) (Control loop), [`Src/dshot.c`](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/dshot.c) (DShot), [`Mcu/f051/Src/peripherals.c`](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/peripherals.c) (Peripheral setup), [`Src/phaseouts.c`](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/phaseouts.c) (Phase outputs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Motor control"]
  node_main["Control loop<br/>[main.c]"]
  node_phaseouts["Phase outputs<br/>[phaseouts.c]"]
  node_functions["Control helpers<br/>[functions.c]"]
  node_sounds["Startup sounds<br/>[sounds.c]"]
end

subgraph group_protocols["Input protocols"]
  node_signal["Servo PWM<br/>[signal.c]"]
  node_dshot["DShot<br/>[dshot.c]"]
  node_crsf["CRSF<br/>[crsf.c]"]
end

subgraph group_hardware["MCU hardware"]
  node_targets["Target config<br/>[targets.h]"]
  node_peripherals["Peripheral setup<br/>[peripherals.c]"]
  node_io["Pin IO<br/>[IO.c]"]
  node_adc["ADC sensing<br/>[ADC.c]"]
  node_comparator["Comparator sensing<br/>[comparator.c]"]
end

subgraph group_support["Telemetry and settings"]
  node_eeprom["Flash settings<br/>[eeprom.c]"]
  node_telemetry["Serial telemetry<br/>[serial_telemetry.c]"]
  node_dshot_telemetry["DShot telemetry<br/>[dshot.c]"]
end

node_flight_controller(("Flight controller"))
node_motor_esc["ESC and motor"]

node_flight_controller -->|"sends PWM"| node_signal
node_flight_controller -->|"sends DShot"| node_dshot
node_signal -->|"provides throttle"| node_main
node_dshot -->|"provides throttle"| node_main
node_main -->|"commutates motor"| node_phaseouts
node_phaseouts -->|"drives phases"| node_motor_esc
node_main -->|"initializes"| node_peripherals
node_main -->|"plays startup tune"| node_sounds
node_main -->|"loads settings"| node_eeprom
node_main -.->|"reports telemetry"| node_telemetry
node_dshot -.->|"supports bidirectional mode"| node_dshot_telemetry
node_targets -->|"selects hardware"| node_peripherals
node_peripherals -->|"configures pins"| node_io
node_main -->|"reads measurements"| node_adc
node_main -->|"reads phase state"| node_comparator
node_crsf -.->|"supplies serial input"| node_main
node_main -->|"uses control helpers"| node_functions

click node_main "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/main.c"
click node_signal "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/signal.c"
click node_dshot "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/dshot.c"
click node_crsf "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/crsf.c"
click node_phaseouts "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/phaseouts.c"
click node_functions "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/functions.c"
click node_sounds "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/sounds.c"
click node_targets "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Inc/targets.h"
click node_peripherals "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/peripherals.c"
click node_io "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/IO.c"
click node_adc "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/ADC.c"
click node_comparator "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/comparator.c"
click node_eeprom "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/eeprom.c"
click node_telemetry "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/serial_telemetry.c"
click node_dshot_telemetry "https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/dshot.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_main,node_phaseouts,node_functions,node_sounds toneBlue
class node_signal,node_dshot,node_crsf toneAmber
class node_targets,node_peripherals,node_io,node_adc,node_comparator toneMint
class node_eeprom,node_telemetry,node_dshot_telemetry toneRose
class node_flight_controller,node_motor_esc toneIndigo
```

## Components

### Motor control

- [Control loop](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/main.c): `Src/main.c`
- [Phase outputs](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/phaseouts.c): `Src/phaseouts.c`
- [Control helpers](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/functions.c): `Src/functions.c`
- [Startup sounds](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/sounds.c): `Src/sounds.c`

### Input protocols

- [Servo PWM](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/signal.c): `Src/signal.c`
- [DShot](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/dshot.c): `Src/dshot.c`
- [CRSF](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/crsf.c): `Src/crsf.c`

### MCU hardware

- [Target config](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Inc/targets.h): `Inc/targets.h`
- [Peripheral setup](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/peripherals.c): `Mcu/f051/Src/peripherals.c`
- [Pin IO](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/IO.c): `Mcu/f051/Src/IO.c`
- [ADC sensing](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/ADC.c): `Mcu/f051/Src/ADC.c`
- [Comparator sensing](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/comparator.c): `Mcu/f051/Src/comparator.c`

### Telemetry and settings

- [Flash settings](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/eeprom.c): `Mcu/f051/Src/eeprom.c`
- [Serial telemetry](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Mcu/f051/Src/serial_telemetry.c): `Mcu/f051/Src/serial_telemetry.c`
- [DShot telemetry](https://github.com/alkamotors/am32-multirotor-esc-firmware/blob/master/Src/dshot.c): `Src/dshot.c`

### Other components

- **Flight controller**
- **ESC and motor**

## Connections

- Flight controller → Servo PWM: sends PWM
- Flight controller → DShot: sends DShot
- Servo PWM → Control loop: provides throttle
- DShot → Control loop: provides throttle
- Control loop → Phase outputs: commutates motor
- Phase outputs → ESC and motor: drives phases
- Control loop → Peripheral setup: initializes
- Control loop → Startup sounds: plays startup tune
- Control loop → Flash settings: loads settings
- Control loop → Serial telemetry: reports telemetry
- DShot → DShot telemetry: supports bidirectional mode
- Target config → Peripheral setup: selects hardware
- Peripheral setup → Pin IO: configures pins
- Control loop → ADC sensing: reads measurements
- Control loop → Comparator sensing: reads phase state
- CRSF → Control loop: supplies serial input
- Control loop → Control helpers: uses control helpers
