1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# hw-toolchain
Tools and conventions for building KiCad boards with an AI agent in the loop. At its core is an automatic **placer and router for 2-layer KiCad boards**, written in Rust:
- **Placer** (`tools/placer`): simulated annealing over footprint positions and rotations. Its cost terms come from hand placement: ratsnest length and crossings, decoupling distance, fan-out bands, groups, links and replicated channels.
- **Router** (`tools/router-rs`): a 0.05 mm grid router with negotiated congestion (PathFinder), so all nets route at once with no net order. It adds cleanup passes, a pour-connectivity model for the ground plane, escape lines for module interfaces, and a TOML config per board.
- **pnr.sh**: places 32 candidates, routes all of them, checks the best ones with KiCad's DRC and installs the one you pick.
Around it are KiCad helpers in Python (headless "Update PCB from Schematic", a schematic generator, a placement checker, board composition from routed modules, connector tabs, thermal vias, 3D model checks), an `AGENTS.md` with repo conventions for coding agents, and the notes in `knowledge/` that record how the tools work and what was learned using them.
## Quick start: route your board
Requirements: KiCad 10 (`kicad-cli` and a Python with `pcbnew`) and Rust stable.
``` sh
git clone https://git.dnge.de/hw-toolchain && cd hw-toolchain
cargo build --release --manifest-path tools/router-rs/Cargo.toml
cargo build --release --manifest-path tools/placer/Cargo.toml
# myboard/ holds myboard.kicad_pro/.kicad_sch/.kicad_pcb + placement.toml + route.toml
sh tools/pnr.sh run path/to/myboard # place 32 ×, route all, DRC the best 6
sh tools/pnr.sh install path/to/myboard rank_00
```
The minimal `placement.toml` and `route.toml`, routing an already placed board, and what to do when a board does not route: **[knowledge/tooling/pnr.md](knowledge/tooling/pnr.md)**.
Reference: [Rust router and route.toml](knowledge/tooling/rust-router.md), [Placer and placement.toml](knowledge/tooling/placer.md), [Placement for routing](knowledge/topics/placement-for-routing.md). Everything else: [knowledge/index.md](knowledge/index.md).
The tools are found relative to themselves. The board can live anywhere.
- KiCad paths: macOS is detected; elsewhere, set `KICAD_PYTHON` and `KICAD_CLI` ([tools/kicad_env.sh](tools/kicad_env.sh)).
- Your own KiCad libraries go in `libraries/` next to `tools/`, or set `HW_ROOT` to the repo that has them ([tools/kicad_paths.py](tools/kicad_paths.py)).
## Use it as the base of your hardware repo
`AGENTS.md` describes a monorepo layout (libraries, modules, projects, knowledge) and the rules an agent follows in it. To keep your boards private and still track this repo:
``` sh
git submodule add https://git.dnge.de/hw-toolchain toolchain
ln -s toolchain/tools tools
mkdir -p knowledge && ln -s ../toolchain/knowledge/tooling knowledge/tooling
printf 'Read toolchain/AGENTS.md first; it holds the shared conventions.\n\n# My additions\n' > AGENTS.md
```
## Status
- Used on a dozen real 2-layer boards: industrial I/O modules on DIN rail, ESP32/CH32 + Ethernet, RTD front ends.
- Two layers only. Differential pairs are routed as single nets (bundles only attract).
- No thermal-spoke check in the pour model.
- The DIN-rail tools assume one specific housing format ([knowledge/topics/din-rail-format.md](knowledge/topics/din-rail-format.md)). The rest is general.
## License
MIT, see [LICENSE](LICENSE). The `tools/konnect` submodule ([Konnect](https://github.com/mixelpixx/Konnect), the KiCad MCP server) is a separate project under AGPL-3.0.
|