# dungjk/grbl-stm32 architecture

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

- Interactive diagram: https://gitdiagram.com/dungjk/grbl-stm32
- Repository: https://github.com/dungjk/grbl-stm32

## Overview

This repository is STM32F10x firmware for a Grbl CNC motion controller, with USB virtual-COM support and a serial fallback. The user-facing workflow is to submit G-code or control commands, parse and plan motion, then generate timed stepper outputs while controlling spindle, coolant, probing, and limits. The README also documents jogging, overrides, laser operation, sleep, and safety-door parking. The excerpts show initialization and selected USB/peripheral behavior; links between most runtime stages are therefore marked unverified rather than inferred from module names.

Main entry points: [`grbl/main.c`](https://github.com/dungjk/grbl-stm32/blob/main/grbl/main.c) (Grbl startup), [`grbl/planner.c`](https://github.com/dungjk/grbl-stm32/blob/main/grbl/planner.c) (Motion planner), [`grbl/system.c`](https://github.com/dungjk/grbl-stm32/blob/main/grbl/system.c) (System and overrides), [`grbl/gcode.c`](https://github.com/dungjk/grbl-stm32/blob/main/grbl/gcode.c) (G-code parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Command Interface"]
  node_usb_vcp["USB virtual COM<br/>[usb_prop.c]"]
  node_usb_stack["USB device stack<br/>[usb_core.c]"]
  node_serial["Serial transport<br/>[serial.c]"]
  node_protocol["Command protocol<br/>[protocol.c]"]
end

subgraph group_motion["G-code and Motion"]
  node_gcode["G-code parser<br/>[gcode.c]"]
  node_jog["Jogging<br/>[jog.c]"]
  node_planner["Motion planner<br/>[planner.c]"]
  node_motion_control["Motion control<br/>[motion_control.c]"]
  node_stepper["Stepper execution<br/>[stepper.c]"]
end

subgraph group_machine["Machine Control"]
  node_system["System and overrides<br/>[system.c]"]
  node_limits["Limits and homing<br/>[limits.c]"]
  node_probe["Probing<br/>[probe.c]"]
  node_spindle["Spindle control<br/>[spindle_control.c]"]
  node_coolant["Coolant control<br/>[coolant_control.c]"]
  node_settings["Settings and EEPROM<br/>[settings.c]"]
end

subgraph group_platform["STM32 Platform"]
  node_stm32_spl["STM32 peripheral drivers<br/>[stm32f10x_tim.c]"]
  node_usb_irqs["USB interrupt handling<br/>[usb_istr.c]"]
  node_eeprom[("Flash-backed EEPROM<br/>[stm32eeprom.h]")]
  node_firmware_init["Grbl startup<br/>[main.c]"]
end

node_operator(("CNC sender"))

node_operator -.->|"sends commands"| node_usb_vcp
node_operator -.->|"sends commands"| node_serial
node_usb_vcp -.->|"uses device stack"| node_usb_stack
node_usb_stack -.->|"dispatches interrupts"| node_usb_irqs
node_serial -.->|"provides input"| node_protocol
node_protocol -.->|"dispatches commands"| node_gcode
node_gcode -.->|"requests motion"| node_motion_control
node_gcode -.->|"submits motion"| node_planner
node_jog -.->|"plans jogs"| node_planner
node_planner -.->|"provides motion blocks"| node_stepper
node_motion_control -.->|"plans moves"| node_planner
node_stepper -->|"uses timer drivers"| node_stm32_spl
node_firmware_init -->|"resets buffer"| node_serial
node_firmware_init -->|"initializes parser"| node_gcode
node_firmware_init -->|"resets planner"| node_planner
node_firmware_init -->|"resets stepper"| node_stepper
node_firmware_init -->|"initializes spindle"| node_spindle
node_firmware_init -->|"initializes coolant"| node_coolant
node_firmware_init -->|"initializes limits"| node_limits
node_firmware_init -->|"initializes probe"| node_probe
node_settings -.->|"stores settings"| node_eeprom
node_system -.->|"controls runtime motion"| node_stepper
node_system -.->|"applies overrides"| node_spindle
node_system -.->|"applies overrides"| node_coolant
node_limits -.->|"signals limit events"| node_system
node_probe -.->|"supports probe moves"| node_motion_control

click node_usb_vcp "https://github.com/dungjk/grbl-stm32/blob/main/usb/usb_prop.c"
click node_usb_stack "https://github.com/dungjk/grbl-stm32/blob/main/stm_usb_fs_lib/src/usb_core.c"
click node_serial "https://github.com/dungjk/grbl-stm32/blob/main/grbl/serial.c"
click node_protocol "https://github.com/dungjk/grbl-stm32/blob/main/grbl/protocol.c"
click node_gcode "https://github.com/dungjk/grbl-stm32/blob/main/grbl/gcode.c"
click node_jog "https://github.com/dungjk/grbl-stm32/blob/main/grbl/jog.c"
click node_planner "https://github.com/dungjk/grbl-stm32/blob/main/grbl/planner.c"
click node_motion_control "https://github.com/dungjk/grbl-stm32/blob/main/grbl/motion_control.c"
click node_stepper "https://github.com/dungjk/grbl-stm32/blob/main/grbl/stepper.c"
click node_system "https://github.com/dungjk/grbl-stm32/blob/main/grbl/system.c"
click node_limits "https://github.com/dungjk/grbl-stm32/blob/main/grbl/limits.c"
click node_probe "https://github.com/dungjk/grbl-stm32/blob/main/grbl/probe.c"
click node_spindle "https://github.com/dungjk/grbl-stm32/blob/main/grbl/spindle_control.c"
click node_coolant "https://github.com/dungjk/grbl-stm32/blob/main/grbl/coolant_control.c"
click node_settings "https://github.com/dungjk/grbl-stm32/blob/main/grbl/settings.c"
click node_stm32_spl "https://github.com/dungjk/grbl-stm32/blob/main/SPL/src/stm32f10x_tim.c"
click node_usb_irqs "https://github.com/dungjk/grbl-stm32/blob/main/usb/usb_istr.c"
click node_eeprom "https://github.com/dungjk/grbl-stm32/blob/main/util/stm32eeprom.h"
click node_firmware_init "https://github.com/dungjk/grbl-stm32/blob/main/grbl/main.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_usb_vcp,node_usb_stack,node_serial,node_protocol toneBlue
class node_gcode,node_jog,node_planner,node_motion_control,node_stepper toneAmber
class node_system,node_limits,node_probe,node_spindle,node_coolant,node_settings toneMint
class node_stm32_spl,node_usb_irqs,node_eeprom,node_firmware_init toneRose
class node_operator toneIndigo
```

## Components

### Command Interface

- [USB virtual COM](https://github.com/dungjk/grbl-stm32/blob/main/usb/usb_prop.c): `usb/usb_prop.c`
- [USB device stack](https://github.com/dungjk/grbl-stm32/blob/main/stm_usb_fs_lib/src/usb_core.c): `stm_usb_fs_lib/src/usb_core.c`
- [Serial transport](https://github.com/dungjk/grbl-stm32/blob/main/grbl/serial.c): `grbl/serial.c`
- [Command protocol](https://github.com/dungjk/grbl-stm32/blob/main/grbl/protocol.c): `grbl/protocol.c`

### G-code and Motion

- [G-code parser](https://github.com/dungjk/grbl-stm32/blob/main/grbl/gcode.c): `grbl/gcode.c`
- [Jogging](https://github.com/dungjk/grbl-stm32/blob/main/grbl/jog.c): `grbl/jog.c`
- [Motion planner](https://github.com/dungjk/grbl-stm32/blob/main/grbl/planner.c): `grbl/planner.c`
- [Motion control](https://github.com/dungjk/grbl-stm32/blob/main/grbl/motion_control.c): `grbl/motion_control.c`
- [Stepper execution](https://github.com/dungjk/grbl-stm32/blob/main/grbl/stepper.c): `grbl/stepper.c`

### Machine Control

- [System and overrides](https://github.com/dungjk/grbl-stm32/blob/main/grbl/system.c): `grbl/system.c`
- [Limits and homing](https://github.com/dungjk/grbl-stm32/blob/main/grbl/limits.c): `grbl/limits.c`
- [Probing](https://github.com/dungjk/grbl-stm32/blob/main/grbl/probe.c): `grbl/probe.c`
- [Spindle control](https://github.com/dungjk/grbl-stm32/blob/main/grbl/spindle_control.c): `grbl/spindle_control.c`
- [Coolant control](https://github.com/dungjk/grbl-stm32/blob/main/grbl/coolant_control.c): `grbl/coolant_control.c`
- [Settings and EEPROM](https://github.com/dungjk/grbl-stm32/blob/main/grbl/settings.c): `grbl/settings.c`

### STM32 Platform

- [STM32 peripheral drivers](https://github.com/dungjk/grbl-stm32/blob/main/SPL/src/stm32f10x_tim.c): `SPL/src/stm32f10x_tim.c`
- [USB interrupt handling](https://github.com/dungjk/grbl-stm32/blob/main/usb/usb_istr.c): `usb/usb_istr.c`
- [Flash-backed EEPROM](https://github.com/dungjk/grbl-stm32/blob/main/util/stm32eeprom.h): `util/stm32eeprom.h`
- [Grbl startup](https://github.com/dungjk/grbl-stm32/blob/main/grbl/main.c): `grbl/main.c`

### Other components

- **CNC sender**

## Connections

- CNC sender → USB virtual COM: sends commands
- CNC sender → Serial transport: sends commands
- USB virtual COM → USB device stack: uses device stack
- USB device stack → USB interrupt handling: dispatches interrupts (evidence: `usb/usb_istr.c`)
- Serial transport → Command protocol: provides input
- Command protocol → G-code parser: dispatches commands
- G-code parser → Motion control: requests motion
- G-code parser → Motion planner: submits motion
- Jogging → Motion planner: plans jogs
- Motion planner → Stepper execution: provides motion blocks
- Motion control → Motion planner: plans moves
- Stepper execution → STM32 peripheral drivers: uses timer drivers (evidence: `grbl/stepper.c`)
- Grbl startup → Serial transport: resets buffer (evidence: `grbl/main.c`)
- Grbl startup → G-code parser: initializes parser (evidence: `grbl/main.c`)
- Grbl startup → Motion planner: resets planner (evidence: `grbl/main.c`)
- Grbl startup → Stepper execution: resets stepper (evidence: `grbl/main.c`)
- Grbl startup → Spindle control: initializes spindle (evidence: `grbl/main.c`)
- Grbl startup → Coolant control: initializes coolant (evidence: `grbl/main.c`)
- Grbl startup → Limits and homing: initializes limits (evidence: `grbl/main.c`)
- Grbl startup → Probing: initializes probe (evidence: `grbl/main.c`)
- Settings and EEPROM → Flash-backed EEPROM: stores settings
- System and overrides → Stepper execution: controls runtime motion
- System and overrides → Spindle control: applies overrides
- System and overrides → Coolant control: applies overrides
- Limits and homing → System and overrides: signals limit events
- Probing → Motion control: supports probe moves
