diff options
Diffstat (limited to 'knowledge/tooling/pnr.md')
| -rw-r--r-- | knowledge/tooling/pnr.md | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/knowledge/tooling/pnr.md b/knowledge/tooling/pnr.md new file mode 100644 index 0000000..4d2489b --- /dev/null +++ b/knowledge/tooling/pnr.md @@ -0,0 +1,120 @@ +# Place and route your own board (pnr) + +`tools/pnr.sh` takes a KiCad board with its schematic and gives you routed candidates that KiCad's DRC has checked. It places the parts with the [Placer](placer.md) (simulated annealing, 32 runs), routes every candidate with the [Rust router](rust-router.md) (negotiated congestion), then runs apply → route → write → DRC on the best six and installs the one you choose. + +You can also run only the router on a board you placed yourself. See [Route a placed board](#route-a-placed-board). + +## Requirements + +- **KiCad 10**, with `kicad-cli` and a Python that can `import pcbnew`. + - On macOS both come from `KiCad.app` and are found automatically. + - On Linux, the distribution package puts `pcbnew` into the system Python. + - Override with `KICAD_PYTHON=...` and `KICAD_CLI=...` ([tools/kicad_env.sh](../../tools/kicad_env.sh)). +- **Rust** (stable, via rustup). `pnr.sh` builds the placer, and the router crate links into it. Build the router binary yourself once: `cargo build --release --manifest-path tools/router-rs/Cargo.toml`. +- `python3` (3.8+) for the small JSON summaries. +- Two-layer boards. The router uses F.Cu and B.Cu only. + +## The board directory + +``` +myboard/ + myboard.kicad_pro / .kicad_sch / .kicad_pcb name = directory name + placement.toml what the placer must know (can be almost empty) + route.toml how to route (see rust-router.md) +``` + +The board needs: + +- a closed Edge.Cuts outline; +- all footprints on the board, in any position (Update PCB from Schematic and leave them in a heap); +- the net classes set in the project, because the router takes widths and clearances from them; +- zones for the plane net (usually GND on B.Cu, and F.Cu too if you like). The router models their fill and checks that every pad reaches them. + +Lock the parts that must not move: connectors at the edge, a module with an antenna, mounting holes. Or list them in `placement.toml` under `fixed = [...]`. + +## Minimal configs + +`placement.toml`: + +``` toml +fixed = ["J1", "U1"] # besides locked footprints and mounting holes + +[class] # net-class weights for the ratsnest length +Power = 0.5 # wide supply tracks are routed last and go around signals +Default = 1.0 +``` + +`route.toml`: + +``` toml +plane_nets = ["GND"] + +[[step]] +do = "negotiate" +planes = true # the GND drops are negotiated with everything else +cost = "none" + +[[step]] +do = "repair" + +[[step]] +do = "cleanup" + +[[step]] +do = "pour" # check the GND pour for islands and join them with vias +``` + +That is enough for a first run. The [Placer](placer.md) and [Rust router](rust-router.md) pages list what else there is: groups and regions, decap pin assignments, links, pulls, replicated channels, bundles, escapes, cost zones and per-net settings. + +## Run + +``` sh +sh tools/pnr.sh run myboard # RUNS=32 JOBS=6 by default; TOP (6) is the 3rd argument +``` + +Output goes to `myboard/out/pnr/`: + +- `run/routed.tsv`: every candidate, ranked: legal placement first, then split nets, failed connections, pour islands, then the `[rank]` score (length, vias, necks); +- `eval/rank_NN/`: the best TOP candidates after apply → route → write → KiCad DRC (`routed.kicad_pcb`, `drc.json`, `route.log`); +- the summary line: `SUMMARY complete=<boards DRC calls fully connected>/<total> unconnected=... vias=... length=...`. + +Open a few `eval/rank_NN/routed.kicad_pcb` files in KiCad and pick one. Then: + +``` sh +sh tools/pnr.sh install myboard rank_00 +``` + +This checkpoints the board to `myboard/out/before-pnr-<date>/`, then: + +1. places references with `silk_refs.py`; +2. fills the pours and saves; +3. restores the `.kicad_pro`, which pcbnew's `SaveBoard` would otherwise reset; +4. runs DRC with schematic parity and ERC. + +Close the board in KiCad first. Both commands refuse while KiCad's lock file is there. + +## Route a placed board + +``` sh +. tools/kicad_env.sh +R=tools/router-rs/target/release/router +$KPY tools/router/dump_board.py myboard.kicad_pcb /tmp/board.json +$R route /tmp/board.json route.toml /tmp/routes.json +$KPY tools/router/write_board.py myboard.kicad_pcb /tmp/routes.json /tmp/routed.kicad_pcb --replace --prune-vias GND +cp myboard.kicad_pro /tmp/routed.kicad_pro +$KC pcb drc --refill-zones /tmp/routed.kicad_pcb +$KPY tools/router/plot_routes.py /tmp/board.json /tmp/routes.json /tmp/routes.png # needs the router venv +``` + +The last line of `route` reads `RESULT split=0 failed=0 islands=0 vias=… length=…`. Zeros mean complete. KiCad's DRC is the judge. + +## When it does not route + +Most failures come from the placement, not the router: + +- **A pin that never connects** on every candidate: something walls it in. Look at the plot, then give it a fan-out band, keep a corridor free, or raise the net's `priority` in `route.toml`. +- **Interface lines of a block** with one pad each: add `[[escape]]` lines (see the [Rust router](rust-router.md) page), or complete boards will wall them in. +- **Fine-pitch parts off the 0.05 mm grid**: put fixed parts' origins on multiples of 0.05 mm. +- **Placer cost does not predict routability.** Route more candidates (`RUNS=64`) rather than tuning the cost weights. + +See [Placement for routing](../topics/placement-for-routing.md) for the rules behind this. The [Rust router](rust-router.md) page has the lessons that came out of real boards. |
