# stlink-org/stlink architecture

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

- Interactive diagram: https://gitdiagram.com/stlink-org/stlink
- Repository: https://github.com/stlink-org/stlink

## Overview

STLINK is a suite for programming and debugging STM32 devices through ST-LINK probes. The main workflow is to connect to a probe, identify or access the target, then read, erase, or program flash; companion tools expose chip information, trace capture, GDB debugging, and remote probe access. The shared library contains USB/remote transport and STM32-specific operations. The README establishes the suite’s capabilities, while sampled source confirms selected tool and library behavior; unsampled implementation links are omitted where ownership is uncertain.

Main entry points: [`inc/stlink.h`](https://github.com/stlink-org/stlink/blob/testing/inc/stlink.h) (STLINK API), [`src/st-util/gdb-server.c`](https://github.com/stlink-org/stlink/blob/testing/src/st-util/gdb-server.c) (GDB server), [`src/st-flash/flash.c`](https://github.com/stlink-org/stlink/blob/testing/src/st-flash/flash.c) (st-flash), [`src/st-server/server.c`](https://github.com/stlink-org/stlink/blob/testing/src/st-server/server.c) (st-server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tools["User tools"]
  node_flash["st-flash<br/>[flash.c]"]
  node_flash_opts["Flash options<br/>[flash_opts.c]"]
  node_info["st-info<br/>[info.c]"]
  node_gui["stlink-gui<br/>[gui.c]"]
end

subgraph group_debug["Debug and trace"]
  node_trace["st-trace<br/>[trace.c]"]
  node_gdb_server["GDB server<br/>[gdb-server.c]"]
  node_gdb_remote["GDB protocol<br/>[gdb-remote.c]"]
  node_semihosting["Semihosting<br/>[semihosting.c]"]
end

subgraph group_library["STLINK library"]
  node_core_api["STLINK API<br/>[stlink.h]"]
  node_flash_ops["Flash operations<br/>[common_flash.c]"]
  node_chipid["Chip identification<br/>[chipid.c]"]
  node_option_bytes["Option bytes<br/>[option_bytes.c]"]
end

subgraph group_transport["Probe transport"]
  node_server["st-server<br/>[server.c]"]
  node_usb["USB backend<br/>[usb.c]"]
  node_remote["Remote backend<br/>[remote.c]"]
end

node_user(("User"))
node_probe{{"ST-LINK probe"}}
node_target{{"STM32 target"}}
node_gdb_client(("GDB client"))
node_remote_tools(("Remote stlink tools"))
node_tcp["TCP connection"]

node_user -->|"runs"| node_flash
node_flash -->|"parses options"| node_flash_opts
node_user -->|"runs"| node_info
node_info -->|"probes and queries"| node_core_api
node_user -->|"uses"| node_gui
node_gui -->|"accesses device"| node_core_api
node_user -->|"runs"| node_trace
node_trace -->|"configures trace"| node_core_api
node_user -->|"starts debugging"| node_gdb_server
node_gdb_client -->|"sends commands"| node_gdb_server
node_gdb_server -->|"handles protocol"| node_gdb_remote
node_gdb_server -->|"handles requests"| node_semihosting
node_gdb_server -->|"controls target"| node_core_api
node_user -->|"starts service"| node_server
node_remote_tools -->|"sends requests"| node_tcp
node_tcp -->|"forwards requests"| node_server
node_server -->|"forwards operations"| node_core_api
node_flash -->|"manipulates flash"| node_core_api
node_core_api -->|"uses"| node_flash_ops
node_core_api -->|"identifies chip"| node_chipid
node_core_api -->|"accesses options"| node_option_bytes
node_core_api -->|"uses local transport"| node_usb
node_core_api -.->|"uses remote transport"| node_remote
node_usb -->|"communicates over USB"| node_probe
node_remote -.->|"communicates over TCP"| node_tcp
node_probe -->|"programs and debugs"| node_target

click node_flash "https://github.com/stlink-org/stlink/blob/testing/src/st-flash/flash.c"
click node_flash_opts "https://github.com/stlink-org/stlink/blob/testing/src/st-flash/flash_opts.c"
click node_info "https://github.com/stlink-org/stlink/blob/testing/src/st-info/info.c"
click node_gui "https://github.com/stlink-org/stlink/blob/testing/src/stlink-gui/gui.c"
click node_trace "https://github.com/stlink-org/stlink/blob/testing/src/st-trace/trace.c"
click node_gdb_server "https://github.com/stlink-org/stlink/blob/testing/src/st-util/gdb-server.c"
click node_gdb_remote "https://github.com/stlink-org/stlink/blob/testing/src/st-util/gdb-remote.c"
click node_semihosting "https://github.com/stlink-org/stlink/blob/testing/src/st-util/semihosting.c"
click node_server "https://github.com/stlink-org/stlink/blob/testing/src/st-server/server.c"
click node_core_api "https://github.com/stlink-org/stlink/blob/testing/inc/stlink.h"
click node_flash_ops "https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/common_flash.c"
click node_chipid "https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/chipid.c"
click node_option_bytes "https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/option_bytes.c"
click node_usb "https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/usb.c"
click node_remote "https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/remote.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_flash,node_flash_opts,node_info,node_gui,node_user,node_gdb_client toneBlue
class node_trace,node_gdb_server,node_gdb_remote,node_semihosting toneAmber
class node_core_api,node_flash_ops,node_chipid,node_option_bytes toneMint
class node_server,node_usb,node_remote toneRose
class node_probe,node_target,node_remote_tools,node_tcp toneIndigo
```

## Components

### User tools

- [st-flash](https://github.com/stlink-org/stlink/blob/testing/src/st-flash/flash.c): `src/st-flash/flash.c`
- [Flash options](https://github.com/stlink-org/stlink/blob/testing/src/st-flash/flash_opts.c): `src/st-flash/flash_opts.c`
- [st-info](https://github.com/stlink-org/stlink/blob/testing/src/st-info/info.c): `src/st-info/info.c`
- [stlink-gui](https://github.com/stlink-org/stlink/blob/testing/src/stlink-gui/gui.c): `src/stlink-gui/gui.c`

### Debug and trace

- [st-trace](https://github.com/stlink-org/stlink/blob/testing/src/st-trace/trace.c): `src/st-trace/trace.c`
- [GDB server](https://github.com/stlink-org/stlink/blob/testing/src/st-util/gdb-server.c): `src/st-util/gdb-server.c`
- [GDB protocol](https://github.com/stlink-org/stlink/blob/testing/src/st-util/gdb-remote.c): `src/st-util/gdb-remote.c`
- [Semihosting](https://github.com/stlink-org/stlink/blob/testing/src/st-util/semihosting.c): `src/st-util/semihosting.c`

### STLINK library

- [STLINK API](https://github.com/stlink-org/stlink/blob/testing/inc/stlink.h): `inc/stlink.h`
- [Flash operations](https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/common_flash.c): `src/stlink-lib/common_flash.c`
- [Chip identification](https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/chipid.c): `src/stlink-lib/chipid.c`
- [Option bytes](https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/option_bytes.c): `src/stlink-lib/option_bytes.c`

### Probe transport

- [st-server](https://github.com/stlink-org/stlink/blob/testing/src/st-server/server.c): `src/st-server/server.c`
- [USB backend](https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/usb.c): `src/stlink-lib/usb.c`
- [Remote backend](https://github.com/stlink-org/stlink/blob/testing/src/stlink-lib/remote.c): `src/stlink-lib/remote.c`

### Other components

- **User**
- **ST-LINK probe**
- **STM32 target**
- **GDB client**
- **Remote stlink tools**
- **TCP connection**

## Connections

- User → st-flash: runs
- st-flash → Flash options: parses options
- User → st-info: runs
- st-info → STLINK API: probes and queries
- User → stlink-gui: uses
- stlink-gui → STLINK API: accesses device
- User → st-trace: runs
- st-trace → STLINK API: configures trace
- User → GDB server: starts debugging
- GDB client → GDB server: sends commands
- GDB server → GDB protocol: handles protocol
- GDB server → Semihosting: handles requests
- GDB server → STLINK API: controls target
- User → st-server: starts service
- Remote stlink tools → TCP connection: sends requests
- TCP connection → st-server: forwards requests
- st-server → STLINK API: forwards operations
- st-flash → STLINK API: manipulates flash
- STLINK API → Flash operations: uses
- STLINK API → Chip identification: identifies chip
- STLINK API → Option bytes: accesses options
- STLINK API → USB backend: uses local transport
- STLINK API → Remote backend: uses remote transport
- USB backend → ST-LINK probe: communicates over USB
- Remote backend → TCP connection: communicates over TCP
- ST-LINK probe → STM32 target: programs and debugs
