MustafaMulla29/usb-pd-motherboard

4-layer USB-C PD hub motherboard with 20 V USB-C input, Linux T113-S3 computer, CH338F USB hub, four individually controlled 5–20 V PD outputs, USB data/camera ports, regulated rails, and hardware watchdog/E-stop safety interlock.

Version
1.0.24
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone MustafaMulla29/usb-pd-motherboard  # download the package files into ./usb-pd-motherboard
tsci add MustafaMulla29/usb-pd-motherboard    # add it to your project as @tsci/MustafaMulla29.usb-pd-motherboard

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

ROUTING.txt

USB-PD motherboard routing: 4-layer board, 2026-11-30

Stack
  L1 top     parts, signals, local power pours
  L2 inner1  GND plane, solid
  L3 inner2  power: VIN_SYS and V5V0 side by side (outlines in data/planes.json, reasons in circuit/planes.tsx)
  L4 bottom  signals, GND pour in the gaps
  Signals use top and bottom only. Vias are through vias, 0.45 mm pad / 0.3 mm hole.
  Rules: 0.1 mm trace, 0.1 mm clearance (the router keeps 0.112 mm).

How to route
  sh tools/router/route.sh        (or: bun run route)     about 4 minutes
  bun run build                                            replays the copper, runs tscircuit's checks
  The whole board is one routing phase. route.sh dumps the routing problem from a build with routing
  switched off, routes every net in one context with tools/router/fastroute.cpp, and saves the copper as
  routing/ALL.routed.json. circuit/fast-routing.ts replays that file during a normal build. Saved routes
  name their pads by position, so adding a part does not invalidate the file; a route whose pad moved is
  dropped and shows up as an unconnected pin in the build.
  After moving parts or changing nets: run route.sh again.
  To redo only a few nets and leave every other trace where it is (parts must not have moved):
    python3 -I tools/router/reroute.py NET [NET...]
  route.sh ends with one such touch-up, for VDD_DDR and PORT_ARM: routed in the main pass, the DRAM supply
  can squeeze under a capacitor at 0.1 mm next to PORT_ARM; redone together, it keeps 0.3 mm all the way.
  The 2026-11-30 copper was produced by route.sh's steps run by hand in the same order after the last
  router change, before the ports were renumbered; the renumbering only renamed the nets in the saved file.
  A fresh route.sh run lays the same wide tracks but may finish the other nets differently.
  2026-12-01: the on-board stop button was added with a partial run (dump build, prep.py, then
  python3 -I tools/router/reroute.py ESTOP_OK ESTOP_SRC ESTOP_LOOP ESTOP_NC ESTOP_NO). The other 1153 saved
  routes are unchanged, compared entry by entry against the file from before.
  After changing data/planes.json or circuit/power-copper.json: run route.sh again (the router reads both).
  When parts were swapped in one area (2026-12-02, the USB hub): dump and prep as route.sh does, then
    python3 -I tools/router/reroute.py NET [NET...] --keep GND,V3V3
  The named nets are routed again from scratch. The --keep nets keep their copper: only routes that start or
  end on a pad that is gone, routes that now touch a pad of another net, and routes that hung on those are taken
  out, and only the pins left without a connection get new copper. Routes of nets that no longer exist are
  dropped. If a route of any other net is affected, the script stops and names that net.

What the router does (details at the top of tools/router/fastroute.cpp)
  0.05 mm grid, 8 directions, A* per connection, rip-up and re-route with history costs.
  Order: nets with a no-via or length rule (hub crystal), USB pair runs, USB pair ends, very short local
  nets, plane stubs, then everything else, shortest first.
  GND, VIN_SYS and V5V0 pads each get a short stub to a via inside their plane's outline.
  Wide nets (0.3 / 0.5 mm) step down to 0.3 / 0.2 / 0.1 mm only where the wider trace does not fit.
  USB pairs (0.22 mm lines, 0.35 mm pitch):
    Each pair's long run, from the host pins to the ESD chip (or the hub), is laid as ONE wide track on the
    top layer and split into two parallel lines. 45-degree turns only, at least 0.2 mm straight after a
    turn, no vias. These runs are fixed copper; the ordinary router only connects their ends to the pins.
    tools/router/prep.py works out where each run starts and ends and which line is on the left (PAIRJOB).
    Runs are walls for each other, so the hub's five pairs are tried in pin order and in reverse and the
    better order is kept. A run starts beyond anything that sits right in front of the pins (the hub has a
    row of decoupling capacitors there).
    A pair with no free path on the top layer falls back to the older method: the second line is routed
    beside the first by cost (8x for every cell that is not one pitch away), vias allowed.
  Non-GND top power pours (circuit/power-copper.json) cost 6x for other nets, so signals stay out of them
  unless a pin inside one has to get out.
  The hub's centre pad gets four ground vias INSIDE the pad (0.7 mm from its centre in x and y). It is the
  CH338F's only ground pin and its pin ring leaves 0.35 mm between pad and pins: no track or via fits there.
  The board therefore allows vias in pads (isViaInPadAllowed in index.circuit.tsx); the router uses that for
  this one pad only (THERMAL_VIA_PARTS in tools/router/prep.py). Nothing is soldered by hand: the factory's
  reflow does it. Solder can run down an open hole in a pad, so JLCPCB's QFN guide asks for 0.3 mm holes that
  are covered with solder mask on the opposite (bottom) side. These are 0.3 mm, and the exported Gerbers open
  the bottom mask only for through-hole pins and mounting holes, never for vias (checked on the 2026-11-30
  export: 1268 via holes, 72 bottom-mask openings, none of via size). Order with "Via covering: Tented".

Port names (2026-12-01)
  The ports are general USB-C ports, not only for motors, so every "M" / "motor" name was replaced.
  Printed on the board: "PD OUT 1".."PD OUT 4" (were "M1 PWR".."M4 PWR") and "USB 1".."USB 4" (were
  "M1 DATA".."M4 DATA"). "CAM", "PC" and "PD IN" are unchanged (CAM was hub port 5; hub port 3 since 2026-12-02).
  Parts: PD output N uses the prefix P<N> (UP1BB, LP1, QP1H ...; were UM1BB, LM1, QM1H) and its connector is
  JOUT<N> (was JM<N>P). Data port N uses USB<N> (UUSB1ESD, UUSB1PWR ...) and its connector is JUSB<N> (was JM<N>D).
  Nets: P<N>_... (were M<N>_...), USB<N>_... (were M<N>D_...), PORT_ARM, PORT_HW_EN, PORT_HW_EN_N (were MOTOR_...).
  Schematic sheets pd_out_1..4 (were motor_port_1..4); circuit/pd-output-port.tsx (was motor-power-port.tsx).
  200 parts and 167 nets were renamed; the full old -> new list was checked against the board before and after:
  every part is at the same place under its new name, the 294 connections join the same pads at the same
  widths, and all 2948 pads, holes and vias of the routing problem are identical.
  docs/*.md and docs/enclosure.html were written before this and still use the old names.

Port numbering (changed 2026-11-30, circuit/port-positions.ts)
  (Hub port numbers changed again with the CH338F on 2026-12-02: see "USB hub replaced" below. The connector
  numbers printed on the board did not change.)
  The four port groups on the right edge are numbered from the bottom up: port 1 is the lowest, port 4 the highest
  (before, port 1 was at the top). Hub port N feeds DATA connector N, so Linux reports the number printed on the
  board. Why bottom-up: the hub's downstream pins sit in the order DN1..DN5 along one side, and laid out on
  one layer without crossing they reach the connectors bottom-first. Numbering top-down would mean either
  crossed pairs (vias, no wide tracks) or hub port 4 on connector 1.
  Only names changed: no part or trace moved. Checked by comparing the routing problem before and after:
  all 291 connections join the same pads at the same widths, and every pad, hole and via is where it was.
  What moved with the names: supervisor A now runs ports 4 and 3 (its PD channels 1 and 2), supervisor B
  ports 2 and 1; the converter I2C addresses are 0x75, 0x74, 0x75, 0x74 for ports 1 to 4. Supervisor
  firmware needs that table. docs/*.md were written before this and use the old numbers.

USB hub replaced (2026-12-02, circuit/usb.tsx): USB2517I -> CH338F
  Why: cost. CH338F (WCH, JLCPCB C42387425, 7,649 in stock) is $0.96 to $1.70; the USB2517I was $3.32.
  The chip is 4 x 4 mm (the old one 9 x 9) and sits at the same centre, (-10, 2), turned 90 degrees clockwise.
  Wiring follows the datasheet (CH338DS1 V1.3, figures 8-1 and 8-4): 3.3 V on both VDD33 pins (1 uF + 100 nF,
  1 uF), 1 uF on AVDDK, 100 nF on DVDDK, 25 MHz crystal (YHUB, C9006, a JLCPCB basic part) with 4.7M from XI to
  GND and 30 pF from XO to GND, 5.1k from PWREN# to GND (the chip's own USB-PD function off), CFG / CC / SMBus
  pins and downstream ports 6 and 7 open. RESET# has a 40k pull-up inside and wants 1k or less to pull it low:
  RHUBRST is 1k (was 10k), so the hub stays in reset until Linux drives PG3 high, as before.
  Also compared with WCH's own evaluation board (CH338EVT.ZIP V1.2 of 2026-11-05, board CH338F-R0-1v1): the
  same supply capacitors, the same oscillator circuit (X1 "25M" in a 3.2 x 2.5 mm package, 4.7M, 30 pF), CFG,
  CC and SMBus pins not used. One difference was taken over: the evaluation board pulls PWREN# down with 5.1k,
  the datasheet's drawing with 10k. Against the chip's internal pull-up (30 to 55 kOhm) 10k leaves the pin at up
  to 0.83 V, above the 0.8 V limit for a low level; 5.1k leaves 0.48 V at most. RHUBPD is 5.1k.
  The evaluation board also has 100 nF on RESET#; not needed here, RESET# is driven by the SoC.
  Three things work differently:
  1 Port numbers. The chip's pins go round it in the order 1, 2, 5, 4, 3. To keep the USB pairs from crossing,
    "USB 3" is hub port 5 and "CAM" is hub port 3; USB 1, 2 and 4 are hub ports 1, 2 and 4 (HUB_PORT_OF in
    circuit/usb.tsx). Linux has to name the ports from that table.
  2 Port power. The CH338F has one shared power output, not one per port. Each port's 5 V switch (SY6280) is
    now driven by a Linux GPIO: PD0 USB 1, PD1 USB 2, PD2 USB 3, PD3 USB 4, PD4 CAM (high = on). A 10k to GND
    on each line (RUSB1EN..RUSB4EN, RCAMEN, right of the SoC) keeps the port off until Linux drives the pin.
    The T113's PD pins on its top side (PD10..PD19) cannot be used: they sit between two USB pairs.
  3 Over-current. The hub no longer sees it (OVCUR# is tied high; the USB2517I's inputs were not wired either).
    Each SY6280 still limits its port to 0.5 A (CAM 1 A) by itself.
  Routing: a partial run (see "How to route"). Of the 1168 saved routes, 1041 are unchanged, entry for entry;
  127 were taken out (every route of the hub's own nets, the six USB pairs that end at the hub, the five port
  enables, and the 20 GND and 19 V3V3 stubs that ended on the old hub's parts) and 107 were added.
  Three small GND pours and vias for the old strap resistors were removed from circuit/power-copper.json.
  A picture of the hub area before and after: bun tools/routeviz.ts -26 -14 4 14 out.png --layers top

Stop button (added 2026-12-01, circuit/safety.tsx)
  SWSTOP, XKB8080-Z (JLCPCB C318860): 8 x 8 mm latching push button, through-hole, at the bottom edge straight
  below the three status LEDs. Centre (-4.5, -44.25) from the board centre = 40.5 mm from the left edge,
  4.75 mm from the bottom edge. The LEDs are at x = -4.5, y = -37 / -35 / -33: 7.25 / 9.25 / 11.25 mm above it.
  No existing part or trace moved: its six pins clear all other copper by 0.25 mm or more (SYS_SCL is the
  nearest), and both inner planes stay in one piece around the six holes.
  Loop: V3V3_AON - RESTSRC 330R - ESTOP_SRC - [JESTOP pins 1-2, bridged by RSTOPEXT 0R] - ESTOP_LOOP -
  [SWSTOP] - ESTOP_OK - RESTPD 2k2 - GND. 1.3 mA when closed (0.3 mA before, with 1k / 10k).
  RSTOPEXT (0R, left of JESTOP): fitted = connector bypassed. Remove it to use an external normally-closed
  button on JESTOP; with it fitted an external button does nothing.
  RSTOPNC (0R, fitted, right of the button) / RSTOPNO (not fitted, left): which contact pair the loop uses.
  The datasheet's circuit diagram draws pins 2-3 and 5-6 closed with the button released but does not label
  the positions. Check the first board with a multimeter; if it stops with the button UP, move the link.
  ESTOP_LOOP runs from JESTOP to the button: 172 mm, 14 vias, 0.1 mm wide (under 1 ohm; a DC on/off signal).
  Enclosure numbers (datasheet XKB8080-Z): body 8.0 x 8.0 mm, top 8.15 mm above the board; stem top 13.66 mm
  above the board with the button up; lock travel 2.0 mm, full travel 2.5 mm; force 160 +/- 80 gf.
  Stem tip, the part a cap pushes onto: 2.00 mm across (board x) by 2.98 mm (board y), 3.0 mm tall, with small
  grooves; below it the stem is 3.8 mm wide. A cap must stay below y = -39.5 so the lowest LED keeps 2.5 mm:
  a round cap up to about 9.5 mm centred on the stem, or a rounded bar up to about 14 x 9.5 mm.
  The cap should hit a stop on the enclosure after about 2.5 mm so a hard press does not load the switch.
  Not a certified emergency stop: a latching signal switch in a 3.3 V logic loop.

Result (tools/router/audit.py prints this; 2026-11-30 run, the stop-button nets of 2026-12-01, the hub of 2026-12-02)
  1148 routes, 1148 routed vias (+141 power vias), 0 unconnected pins.
  Copper: top 5368 mm, bottom 4846 mm.
  Build: zero errors from tscircuit (no clearance, connection or placement errors).
  Planes (bun tools/plane-connectivity.ts): every GND, VIN_SYS and V5V0 pad in one copper component,
  no isolated pours.
  Hub crystal: HUB_XI 8.2 mm, HUB_XO 3.9 mm, no vias (limit 10 mm, no vias).
  USB pairs, host pin to far-end pin, D- / D+, and how much of the pair runs at the 0.35 mm design pitch
  (in brackets: the same pair with the USB2517I hub, before 2026-12-02):
    USBH  wide track   44.4 / 42.6 mm   mismatch 1.8 mm   vias 0 / 0   95 % at pitch   (44.0 / 43.9, 0.1 mm, 2 / 2, 92 %)
    CAM   wide track   44.9 / 44.4 mm   mismatch 0.6 mm   vias 0 / 0   75 %            (77.5 / 74.8, 2.7 mm, 2 / 2, 79 %)
    USB4  wide track   68.8 / 68.5 mm   mismatch 0.3 mm   vias 0 / 2   89 %            (94.7 / 92.7, 1.9 mm, 2 / 2, 88 %)
    USB3  wide track   88.2 / 86.7 mm   mismatch 1.5 mm   vias 0 / 2   91 %            (92.3 / 96.5, 4.3 mm, 2 / 4, 90 %)
    USB2  wide track   86.8 / 85.0 mm   mismatch 1.8 mm   vias 2 / 0   88 %            (92.7 / 89.8, 2.9 mm, 2 / 4, 85 %)
    USB1  by cost      83.0 / 83.1 mm   mismatch 0.1 mm   vias 8 / 6   69 %            (86.8 / 87.6, 0.8 mm, 6 / 8, 69 %)
    OTG   by cost      59.0 / 57.8 mm   mismatch 1.1 mm   vias 4 / 4   52 %            (not changed)
  The part of a wide-track pair that is not at pitch is its two ends: the fan-out at the hub or SoC pins
  and at the ESD chip, where the ordinary router takes over and may use a via pair.

USB pair impedance
  Sized for JLCPCB's default 4-layer stackup (JLC04161H-7628, 0.2104 mm from the top layer to the GND plane).
  JLCPCB's impedance calculator (2026-11-30, 1.6 mm, 1 oz outer, 90 ohm differential) gives 0.211 mm lines
  at a 0.125 mm gap and 0.247 mm at 0.15 mm; the board uses 0.22 mm lines at a 0.35 mm pitch (0.13 mm gap).
  The earlier 0.1 mm lines, sized for the 6-layer stackup, would have been about 104 ohm here.
  The 90 ohm figure only holds where the two lines run at that pitch (see the table). Where they separate
  the impedance rises: two uncoupled 0.22 mm lines are roughly 120 ohm by formula, not checked with a field
  solver.

Schematic (reworked 2026-12-02)
  Sheet 1 is a connection guide (blocks, power flow, how to connect, stop, programming). Every other sheet has
  a title, a label above each chip and notes underneath that name the datasheet circuit it follows and give the
  formulas for the set values.
  Every chip is drawn with its pins grouped by what they do, as its datasheet draws the application circuit:
  inputs and control on the left, outputs on the right, supply on top, ground and set-up pins underneath
  (lib/sch-pins.ts, one entry per chip type, used by imports/*.tsx). tools/sch-layout.py then puts each resistor
  and capacitor at the pin it belongs to (at its most specific signal; a ground pin is the last resort), lays a
  part across two pins of one side when it joins them (coil between the switch pins), and packs the groups in
  signal-flow order (ORDER in that file, "|" = new row).
  To redo after a change (each schematic-only build takes about 40 s):
    SCH_ONLY=1 bun tools/build-schematic.ts          schematic alone -> dist/codex-schematic.circuit.json
    python3 -I tools/sch-chip-sizes.py               chip box sizes tscircuit asks for; rebuild, repeat until 0 changes
    python3 -I tools/sch-layout.py dist/codex-schematic.circuit.json     where each part sits
      (add --pcb dist/index/circuit.json after parts moved on the board: a supply capacitor is drawn at the chip
       it is next to on the board; the positions are kept in data/board-positions.json)
    SCH_ONLY=1 bun tools/build-schematic.ts && python3 -I tools/sch-notes.py     where each text goes
    SCH_ONLY=1 bun tools/build-schematic.ts && bun tools/render-schematic.ts     pictures in dist/schematic-preview/
  The wording of labels and notes is in data/schematic-notes-content.json.
  Two net-label overlaps are left (CSOCR1 / UMPU on sheet 10, LEDACT / RLEDHWEN on sheet 15).
  Trap: a <group> that only holds schematic drawings still counts as a board item. Without pcbX / pcbY it makes
  the board re-pack its parts (169 parts moved, 1545 errors). circuit/schematic-notes.tsx sets pcbX={0} pcbY={0}.

Engineering drawings (added 2026-12-02)
  enclosure/drawings.tsx: three A3 sheets (general arrangement with overall dimensions, three sections with the
  board inside, printed parts), rendered from enclosed-system.circuit.tsx. Quick check without the board (30 s):
    bunx tsci export enclosure/drawings.circuit.tsx -f drawing-svg --drawing enclosure_general_arrangement -o ga.svg
  From a finished build:  tsci export dist/index/circuit.json -f drawing-svg --drawing enclosure_sections -o s.svg
  Not possible with CLI 0.1.2488: exploded views / part labels ("Assembly views require resolveSceneParts"), and
  dimension lines on a view that contains board parts. Plain views are turned half a turn about z (helpers SHOWS,
  cutAtY, cutAtX in drawings.tsx hide that).

Parts list check (added 2026-12-02)
  python3 -I tools/bom-value-check.py     after a build with the parts engine, before every push
  tscircuit remembers the JLCPCB part it picked for a resistor or capacitor by the part's NAME, not its value
  (.tscircuit/cache/). Change a value and the next build on the same computer keeps the old part number.
  The check compares every resistor and capacitor's value with JLCPCB's data for its part number and names the
  cache file to delete. It found two wrong parts in the published 1.0.20: RESTSRC had a 1 kOhm part (design
  330 Ohm) and RESTPD a 10 kOhm part (design 2.2 kOhm), left from the stop-button change of 2026-12-01. The
  stop loop would still have worked with them, at 0.3 mA instead of 1.3 mA. Fixed in the build of 2026-12-02.

Open items before fabrication
  USB: USB1 and OTG have no wide track (no free path on the top layer) and are only 69 % and 52 % at pitch;
  USB1 has 8 / 6 vias and runs 28 mm on the bottom layer, part of it under the hub chip (the GND plane is
  between them). Every pair's mismatch is now under 2 mm (common USB 2.0 guideline: under about 3.8 mm).
  USB1, USB2 and USB3 still loop round the hub's left side and are 83 to 88 mm long. Needs electrical review.
  CH338F hub: wired from the datasheet only, not from a built board. Check on the first board: the 25 MHz
  oscillator starts, the hub enumerates with PWREN# held low, and the centre pad is soldered well over its
  four vias. Linux needs the port table and the five port-enable GPIOs.
  Crystal (YHUB, X322525MOB4SI, JLCPCB C9006, 25 MHz, rated for a 12 pF load): the datasheet gives the circuit
  but not the crystal's load rating, and neither does WCH's evaluation board (it says only "25M", 3.2 x 2.5 mm,
  which this crystal is). Evidence collected on 2026-12-02: a built and tested CH338F hub on
  oshwhub.com (dian1234, "USBHUB 七口输出5V3.5A") uses the same circuit and lists this same crystal; two
  CH339 designs there (the sister chip, same 4.7M / 30 pF circuit) list it too. Worst case by calculation: if
  the load the chip presents were anywhere from 5 to 35 pF, the frequency would be -190 to +315 ppm off
  including tolerance, temperature and ageing (assumed crystal values: motional capacitance 2 to 6 fF, shunt
  1 to 3 pF); USB 2.0 allows +/-500 ppm. Not shown on paper: that the oscillator starts on this board.
  A few short 0.1 mm sections remain on wide nets outside their pads: VDD 7.1 mm, P1_VBB 3.1 mm,
  V3V3_AON 2.4 mm, P3_VBB 1.9 mm, V3V3 1.8 mm (audit.py lists them per net).
  python3 -I tools/router/reroute.py VDD   redoes a net at full width where room exists, as route.sh
  already does for VDD_DDR.
  Routing DRC does not check current capacity. High-current paths rely on the top pours and plane vias in
  circuit/power-copper.json, which were generated for the 6-layer board and kept unchanged apart from one
  pour edge next to the camera port.
  Fabrication files (fabrication/): for 9 parts (R5VFB1, UP1EF..UP4EF, UP1BB..UP4BB) JLCPCB's library has no
  footprint to check the pick-and-place rotation against. Check them in JLCPCB's placement preview before
  ordering assembly. The TPD6S300 (UP1CC..UP4CC) is drawn a quarter turn differently in JLCPCB's library than
  on this board; the build records that, so the export turns it.
  The files in fabrication/ were exported on 2026-11-30, BEFORE the stop button: export again before ordering.
  The stop button is the board's only through-hole part: JLCPCB adds a through-hole soldering step for it,
  or its six pins are soldered by hand.
  The board is an engineering prototype and has not been built.

Known quirks
  tscircuit's routing problem reports pill-shaped plated holes without their rotation (USB-C shell slots
  turned 90 degrees come out 1.2 x 2.0 mm instead of 2.0 x 1.2 mm). tools/router/prep.py takes those sizes
  from the circuit JSON instead.
  tscircuit's dangling-end check wants a wire segment at a trace end that is not on a pad. A route that ends
  with a via landing on another trace of its net gets a 0.1 mm tail along that trace (tools/router/post.py).
  tscircuit's pour-short check can report a short that is not there when a pour corner lies exactly in line
  with a trace edge. Pour clearances are 0.253 / 0.203 mm, not 0.25 / 0.2, to stay off the 0.05 mm grid
  (circuit/planes.tsx, circuit/power-copper.tsx).

History
  The 6-layer board (v1.0.9 and earlier) was routed phase by phase with separate tools and saved files
  under routing/*.hand.json. Those files and tools were removed with the move to 4 layers; they are in
  v1.0.9 on the registry. docs/via-migration-status.md, docs/verification-2026-11-26.md and
  docs/pending-fixes-2026-11-27.md describe that older board.