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.

circuit/usb.tsx

import { schematicPlacement } from "../lib/schematic-placement"
import { DATA_Y } from "./port-positions"
import { CH338F } from "../imports/CH338F"
import { X322525MOB4SI } from "../imports/X322525MOB4SI"
import { SY6280AAC } from "../imports/SY6280AAC"
import { USBLC6_2SC6 } from "../imports/USBLC6_2SC6"
import { C, R, n } from "../lib/common"
import { UsbC5A } from "../lib/usbc-5a"
import { SCH_PINS } from "../lib/sch-pins"

/**
 * USB topology (simultaneous, independent):
 *   T113 USB1 (host) -> CH338F 7-port hub (WCH, QFN32 4 x 4 mm; replaced the USB2517I on 2026-12-02 to cut cost)
 *       five of the seven downstream ports are used, ports 6 and 7 are left open (they have pull-downs inside).
 *   T113 USB0 (OTG) -> PC_DATA receptacle (device / gadget, UFP; also the FEL flashing port).
 * All receptacles: JLC C7431072 16-pin USB-C (5 A rated) via lib/usbc-5a.tsx; the builtin
 * <connector standard="usb_c"> could not be resolved by the fanout breakout phase in this core version.
 * Downstream ports are DFPs: Rp 56k to 5 V on CC1/CC2 (default USB power), switched VBUS.
 * USBLC6-2SC6 pinout (ST datasheet): 1 I/O1, 2 GND, 3 I/O2, 4 I/O2, 5 VBUS, 6 I/O1.
 *
 * CH338F wiring (datasheet V1.3, figures 8-1 and 8-4): single 3.3 V supply, 25 MHz crystal, CFG / CC / SMBus pins
 * open (plain hub, no EEPROM), PWREN# low at reset (PD function off), the centre pad is the only ground pin.
 */
/** Centre of the hub on the board (mm): the same spot the USB2517I had. */
export const HUB_AT = { x: -10.0, y: 2.0 }
/**
 * Hub port behind each connector. The CH338F's pins go round the chip in the order 1, 2, 5, 4, 3, so to keep the
 * USB pairs from crossing, "USB 3" is hub port 5 and "CAM" is hub port 3; USB 1, 2 and 4 keep their own number.
 * Linux has to use this table when it names the ports.
 */
export const HUB_PORT_OF = { USB1: 1, USB2: 2, USB3: 5, USB4: 4, CAM: 3 } as const
/**
 * 5 V switch enable of each port and the SoC pin that drives it (high = on). The USB2517I switched each port
 * itself; the CH338F only has one shared (gang) output, so Linux does it: one GPIO per port, PD0..PD4 on the
 * SoC's right-hand side (the PD pins on its top side are shut in between two USB pairs). The 10k pull-downs
 * that keep a port off until Linux drives its pin are next to the SoC (circuit/processor.tsx).
 */
export const PORT_ENABLES = [["CAM_PWREN", "PD4"], ["USB4_PWREN", "PD3"], ["USB3_PWREN", "PD2"], ["USB2_PWREN", "PD1"], ["USB1_PWREN", "PD0"]] as const
type Edge = "left" | "right" | "top"
const DfpPort = ({ name, label, x, y, edge, dp, dm, en, iset, sheet }:
  { name: string; label: string; x: number; y: number; edge: Edge; dp: string; dm: string; en: string; iset: string; sheet: string }) => {
  const N = (s: string) => n(`${label}_${s}`)
  // Local frame: u = distance inboard from the connector anchor, v = sideways. The support parts sit inboard.
  // "top" is the left-edge layout turned 90 deg clockwise (connector opens toward +y).
  const at = (u: number, v: number) => edge === "left" ? { x: x + u, y: y + v } : edge === "right" ? { x: x - u, y: y + v } : { x: x + v, y: y - u }
  const rot = edge === "left" ? -90 : edge === "right" ? 90 : 180
  const pr = edge === "top" ? 0 : 90
  const P = (u: number, v: number) => ({ pcbX: at(u, v).x, pcbY: at(u, v).y, pcbRotation: pr })
  const A = (u: number, v: number) => ({ ...at(u, v), r: pr })
  return (
    <group schLayout={{ layoutMode: "relative" }} name={`PORT_${label}`} schSheetName={sheet} pcbX={0} pcbY={0}>
      <UsbC5A {...schematicPlacement(name)} name={name} pcbX={x} pcbY={y} pcbRotation={rot} noConnect={["SBU1", "SBU2"]}
        connections={{
          VBUS1: N("VBUS"), VBUS2: N("VBUS"), GND1: n("GND"), GND2: n("GND"), SHELL: n("GND"),
          DP1: n(dp), DP2: n(dp), DN1: n(dm), DN2: n(dm), CC1: N("CC1"), CC2: N("CC2"),
        }} />
      <USBLC6_2SC6 {...schematicPlacement(`U${label}ESD`)} name={`U${label}ESD`} {...P(6.8, 2.2)}
        connections={{ pin1: n(dp), pin6: n(dp), pin3: n(dm), pin4: n(dm), pin2: n("GND"), pin5: N("VBUS") }} />
      <R name={`R${label}CC1`} v="56k" a={N("CC1")} b={n("V5V0")} at={A(7.4, -2.2)} />
      <R name={`R${label}CC2`} v="56k" a={N("CC2")} b={n("V5V0")} at={A(6.1, -2.2)} />
      <SY6280AAC {...schematicPlacement(`U${label}PWR`)} name={`U${label}PWR`} {...P(11.8, 2.2)}
        connections={{ IN: n("V5V0"), OUT: N("VBUS"), EN: n(en), ISET: N("ISET"), GND: n("GND") }} />
      <R name={`R${label}SET`} v={iset} a={N("ISET")} b={n("GND")} at={A(12.4, -2.4)} />
      <C name={`C${label}VB`} v="10uF" rating="10V" fp="0603" a={N("VBUS")} at={A(9.2, -2.4)} />
      <C name={`C${label}IN`} v="1uF" fp="0402" a={n("V5V0")} at={A(11.1, -2.4)} />
    </group>
  )
}

export const UsbSection = () => (
  <>
    <group schLayout={{ layoutMode: "relative" }} name="USB_HUB" schSheetName="usb_hub" pcbX={HUB_AT.x} pcbY={HUB_AT.y}>
      {/* Turned 90 deg clockwise: upstream pins and crystal pins at the top / top-left, ports 1, 2, 5 on the left,
          ports 4, 3 on the right, RESET# / PWREN# / OVCUR# on the bottom (facing the SoC). */}
      <CH338F {...schematicPlacement("UHUB")} name="UHUB" pcbX={0} pcbY={0} pcbRotation={-90}
        // drawn like the datasheet's figures: upstream, clock and control pins on the left, the ports on the right
        {...(SCH_PINS.CH338F as any)}
        noConnect={["DM6", "DP6", "DM7", "DP7", "SMBDAT", "SMBCLK", "CFG", "CC1", "CC2", "CC3", "CC3_CTL"]}
        connections={{
          DPU: n("USBH_DP"), DMU: n("USBH_DM"),
          // Which hub port feeds which connector (see HUB_PORT_OF above): the order the pins sit around the chip.
          DP1: n("USB1_DP"), DM1: n("USB1_DM"), DP2: n("USB2_DP"), DM2: n("USB2_DM"),
          DP5: n("USB3_DP"), DM5: n("USB3_DM"), DP4: n("USB4_DP"), DM4: n("USB4_DM"),
          DP3: n("CAM_DP"), DM3: n("CAM_DM"),
          XI: n("HUB_XI"), XO: n("HUB_XO"),
          VDD331: n("V3V3"), VDD332: n("V3V3"), AVDDK: n("HUB_AVDDK"), DVDDK: n("HUB_DVDDK"), EP: n("GND"),
          N_RESET: n("HUB_RESET_N"), N_PWREN: n("HUB_PDDIS"), N_OVCUR: n("HUB_OCS_N"),
        }} />
      {/* Supply decoupling as in the datasheet's figures 8-1 / 8-4: 1 uF + 100 nF on VDD33 pin 5, 1 uF on VDD33
          pin 19, 1 uF on AVDDK, 100 nF on DVDDK (the two 1.2 V core pins are fed by the chip itself). */}
      <C name="CHUB1" v="1uF" a={n("V3V3")} at={{ x: 0.35, y: 3.75, r: 90 }} />
      <C name="CHUB2" v="100nF" a={n("V3V3")} at={{ x: 1.3, y: 3.75, r: 90 }} />
      <C name="CHUB3" v="1uF" a={n("V3V3")} at={{ x: -1.5, y: -3.3, r: 180 }} />
      <C name="CHUBA" v="1uF" a={n("HUB_AVDDK")} at={{ x: -3.98, y: 1.3, r: 180 }} />
      <C name="CHUBD" v="100nF" a={n("HUB_DVDDK")} at={{ x: 3.4, y: -1.0, r: 270 }} />
      {/* 25 MHz crystal, 4.7M from XI to GND and 30 pF from XO to GND: the datasheet's oscillator circuit (R1, C8, X1). */}
      <X322525MOB4SI {...schematicPlacement("YHUB")} name="YHUB" loadCapacitance="12pF" pcbX={-4.6} pcbY={4.3} pcbRotation={90}
        connections={{ pin1: n("HUB_XO"), pin3: n("HUB_XI"), pin2: n("GND"), pin4: n("GND") }} />
      <C name="CHUBX2" v="30pF" a={n("HUB_XO")} at={{ x: -2.3, y: 4.35, r: 90 }} />
      <R name="RHUBX" v="4.7M" a={n("HUB_XI")} b={n("GND")} at={{ x: -6.2, y: 1.6, r: 180 }} />
      {/* PWREN# is read at reset: low = the chip's own USB PD function off ("Disable PD" in the datasheet).
          5.1k as on WCH's evaluation board (CH338F-R0-1v1); the datasheet's drawing says 10k, but against the
          chip's internal pull-up (30 to 55 kOhm) 10k leaves up to 0.83 V on the pin, above the 0.8 V limit for a low
          level, and 5.1k at most 0.48 V. After reset the pin is the gang power output, which this board does not use. */}
      <R name="RHUBPD" v="5.1k" a={n("HUB_PDDIS")} b={n("GND")} at={{ x: 0.75, y: -4.75, r: 270 }} />
      {/* RESET# has a 40k pull-up inside the chip; the datasheet asks for 1k or less to pull it low. 1k holds the
          hub in reset until Linux drives PG3 high (3.3 mA). */}
      <R name="RHUBRST" v="1k" a={n("HUB_RESET_N")} b={n("GND")} at={{ x: -0.2, y: -4.75, r: 270 }} />
      {/* OVCUR# (gang over-current input, active low) is not used: held high. */}
      <R name="RHUBOCS" v="10k" a={n("HUB_OCS_N")} b={n("V3V3")} at={{ x: 1.7, y: -4.75, r: 270 }} />
    </group>

    {/* right edge, each directly below its PD output port: USB 1..4, USB 1 lowest */}
    {[1, 2, 3, 4].map((i) => (
      <DfpPort {...schematicPlacement(`JUSB${i}`)} key={i} name={`JUSB${i}`} label={`USB${i}`} x={39.4} y={DATA_Y[i]} edge="right"
        dp={`USB${i}_DP`} dm={`USB${i}_DM`} en={`USB${i}_PWREN`} iset="13.7k" sheet="usb_ports" />
    ))}
    {/* top edge, between the power input and motor stage 1: USB_CAMERA (1 A VBUS limit). An output, so it is
        kept off the input (left) edge; moved here 2026-11-30 after review. */}
    <DfpPort {...schematicPlacement("JCAM")} name="JCAM" label="CAM" x={-5.95} y={43.4} edge="top"
      dp="CAM_DP" dm="CAM_DM" en="CAM_PWREN" iset="6.8k" sheet="usb_ports" />

    {/* left edge, below PD_INPUT: PC_DATA (UFP, USB device/gadget on MPU OTG).
        Parts are drawn for a connector at (-46.4, 6); the group offset puts it at (-39.4, 27.5). */}
    <group schLayout={{ layoutMode: "relative" }} name="PORT_PC" schSheetName="usb_ports" pcbX={7} pcbY={21.5}>
      <UsbC5A {...schematicPlacement("JPC")} name="JPC" {...(SCH_PINS.USBC_IN as any)} pcbX={-46.4} pcbY={6} pcbRotation={-90} noConnect={["SBU1", "SBU2"]}
        connections={{
          VBUS1: n("PC_VBUS"), VBUS2: n("PC_VBUS"), GND1: n("GND"), GND2: n("GND"), SHELL: n("GND"),
          DP1: n("OTG_DP"), DP2: n("OTG_DP"), DN1: n("OTG_DM"), DN2: n("OTG_DM"), CC1: n("PC_CC1"), CC2: n("PC_CC2"),
        }} />
      <R name="RPCCC1" v="5.1k" a={n("PC_CC1")} b={n("GND")} at={{ x: -40.2, y: 4.4, r: 90 }} />
      <R name="RPCCC2" v="5.1k" a={n("PC_CC2")} b={n("GND")} at={{ x: -38.9, y: 4.4, r: 90 }} />
      <USBLC6_2SC6 {...schematicPlacement("UPCESD")} name="UPCESD" pcbX={-39.9} pcbY={7.6} pcbRotation={90}
        connections={{ pin1: n("OTG_DP"), pin6: n("OTG_DP"), pin3: n("OTG_DM"), pin4: n("OTG_DM"), pin2: n("GND"), pin5: n("PC_VBUS") }} />
      {/* OTG_VBUS sense: PC VBUS through 10k/20k divider (3.3 V at 5 V) */}
      <R name="RPCVB1" v="10k" a={n("PC_VBUS")} b={n("OTG_VBUS_SNS")} at={{ x: -36.9, y: 7.6, r: 90 }} />
      <R name="RPCVB2" v="20k" a={n("OTG_VBUS_SNS")} b={n("GND")} at={{ x: -35.6, y: 7.6, r: 90 }} />
      <C name="CPCVB" v="1uF" rating="10V" a={n("PC_VBUS")} at={{ x: -37.6, y: 4.4, r: 90 }} />
    </group>
  </>
)