Files
pcb/scripts/report_routing.py
T
onur af7c43b2a8 Restack to four signal layers and route the board
The Ti375 fanout could not be resolved with three routing layers, so L5
stops being a dedicated 1.8-V plane and becomes a signal layer.  No rail
owns a whole layer any more: the supplies are split into zone islands on
L4 and L6, L2 and L7 stay solid and completely unrouted, and F.Cu, L3, L5
and B.Cu are all available for signals.

Routing is staged rather than handed to the autorouter wholesale.  The
BGA escape, the buck high-current loops, plane stitching and the local
power completion all run first and are locked; Freerouting then sees only
the ordinary digital classes, with everything else present as fixed
copper.  finalize_routing.py installs the audited RF and USB geometry and
closes whatever the autorouter left.

Four bugs behind the routing failures, all of them the same shape - a
layer list written down instead of read from the board, which was correct
while L5 was a plane and silently wrong afterwards:

- export_routing_stage.py emitted via keepouts for three layers only, so
  every existing via was invisible to the router on L5.  It drove traces
  straight through them: 102 shorting_items in DRC.
- route_local_power.py never used L5 at all, and picked up escape vias on
  two layers instead of all four.
- add_rf_ground() judged fence positions against vias and pads but not
  tracks.  It runs after the session import, when that region already has
  routed copper, and dropped a ground via on top of a signal trace.

route_local_power.py also grew a via cloud on every rail: reaching a
plane counted as progress even when it merged nothing, so the same pad
collected a via per pass, 0.4 mm further out each time.  Progress is now
measured by the group count actually falling, and groups already sitting
on their plane are skipped.  That removed 404 redundant vias.

The MAX2771 PLL loop filter was spread across three corners of the
package, which forced the charge-pump node onto an inner layer under the
GPS front end.  All three parts now sit in the pocket at U21's north-west
corner and the net stays on F.Cu.  A permanent RF_NO_DIGITAL area plus a
scoped rule keeps that region free of non-power copper on L3/L5/L6/B.Cu,
and the local router enforces the same restriction, since it is the one
stage that runs after the temporary keepout is deleted.

Also enables the solder-mask bridge check that was switched off
board-wide; the board passes it with no violations.

Final board: DRC clean - no shorts, clearance, disallowed-item or
dangling-copper violations - with 26 unconnected endpoints left.  Routing
is spread 37% L3, 27% F.Cu, 26% L5, 10% B.Cu over 6548 mm and 971 vias.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 01:41:43 +03:00

98 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Summarise what a routed board actually contains.
DRC answers "is anything wrong"; this answers "is anything missing, and does
the copper match the rules it was routed under". It reports the still-open
connections per net, the track width actually used per net class (the Specctra
round trip is where widths silently drift), the layer split, and the via count.
"""
from __future__ import annotations
import argparse
from collections import Counter, defaultdict
from pathlib import Path
import pcbnew
def net_groups(board: pcbnew.BOARD, net: str) -> int:
"""Count the separate copper islands a net is currently split into."""
connectivity = board.GetConnectivity()
pads = [pad for fp in board.GetFootprints() for pad in fp.Pads()
if pad.GetNetname() == net]
seen: set[str] = set()
groups = 0
for pad in pads:
key = pad.m_Uuid.AsString()
if key in seen:
continue
members = [item for item in connectivity.GetConnectedItems(pad, 0)
if item.GetClass() == "PAD"]
for item in members:
seen.add(item.m_Uuid.AsString())
seen.add(key)
groups += 1
return groups
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("board", type=Path)
args = parser.parse_args()
board = pcbnew.LoadBoard(str(args.board))
board.BuildConnectivity()
net_class: dict[str, str] = {}
pad_count: Counter[str] = Counter()
for footprint in board.GetFootprints():
for pad in footprint.Pads():
name = pad.GetNetname()
if name:
net_class[name] = pad.GetNetClassName()
pad_count[name] += 1
widths: dict[str, Counter[float]] = defaultdict(Counter)
layers: Counter[str] = Counter()
vias = 0
for item in board.GetTracks():
if isinstance(item, pcbnew.PCB_VIA):
vias += 1
continue
name = item.GetNetname()
widths[net_class.get(name, "?")][round(pcbnew.ToMM(item.GetWidth()), 3)] += 1
layers[board.GetLayerName(item.GetLayer())] += 1
print(f"Board: {args.board}")
print(f"Unconnected endpoints reported by connectivity: "
f"{board.GetConnectivity().GetUnconnectedCount(True)}")
print(f"Tracks: {sum(layers.values())} Vias: {vias}")
print("\nTrack segments per layer:")
for layer, count in layers.most_common():
print(f" {layer:10s} {count:6d}")
print("\nTrack width used per net class (mm: segments):")
for klass in sorted(widths):
used = ", ".join(f"{width}: {count}"
for width, count in sorted(widths[klass].items()))
print(f" {klass:12s} {used}")
print("\nNets still split into more than one copper group:")
incomplete = []
for name in sorted(net_class):
if pad_count[name] < 2:
continue
groups = net_groups(board, name)
if groups > 1:
incomplete.append((groups, name))
for groups, name in sorted(incomplete, reverse=True):
print(f" {name:22s} {net_class[name]:12s} "
f"{pad_count[name]:3d} pads in {groups} groups")
print(f" ({len(incomplete)} nets incomplete)" if incomplete
else " none - every net is one connected group")
if __name__ == "__main__":
main()