main
John Lauer
Add reproducible output-locked STM32 USB bring-up build; retain hardware qualification gates
a0235fd
"""Bind the routed MCU pins to the selected package and peripheral assignments.
Source: ST DS13560 Rev 6, LQFP32 GP pinout and alternate-function tables.
This does not validate option bytes, register setup, electrical limits or hardware.
"""
from pathlib import Path
import json,sys,hashlib
import sexp
p=Path(__file__).resolve().parents[1]
map_by_pin={6:('PF2','NRST','reset'),7:('PA0','TEMP_SENSE','ADC_IN0'),8:('PA1','DUT_ADC','ADC_IN1'),9:('PA2','UART_TX','USART2_TX AF1'),10:('PA3','UART_RX','USART2_RX AF1'),11:('PA4','ARM_CLK','GPIO output, initialize LOW'),12:('PA5','MCU_ENABLE','GPIO output, initialize LOW'),13:('PA6','WDI','GPIO output, healthy-cycle toggle only'),14:('PA7','FAN_TACH','GPIO EXTI7 rising; timestamp from 32-bit timer'),15:('PB0','USB_DETECT','GPIO input'),17:('PB2','HW_OK','GPIO input'),20:('PC6','ALERT','GPIO input'),22:('PA11','USB_DM','USB_DM, default pin remap'),23:('PA12','USB_DP','USB_DP, default pin remap'),24:('PA13','SWDIO','SWDIO AF0'),25:('PA14','SWCLK','SWCLK AF0'),26:('PA15','LATCH_Q','GPIO input'),27:('PB3','FAULT_CLEAR','GPIO open-drain, LOW asserts fault clear through D2; never push-pull HIGH'),30:('PB6','I2C_SCL','I2C1_SCL AF6 open-drain'),31:('PB7','I2C_SDA','I2C1_SDA AF6 open-drain')}
n=json.load(open(p/'design/netlist.json'));c=next(c for c in n['components']if c['ref']=='U1');assert c['mpn']=='STM32G0B1KCT6'
b=sexp.parse((p/'kicad/adom-custom-electronic-load.kicad_pcb').read_text());f=next(f for f in sexp.find(b,'footprint')if any(v[1:3]==['Reference','U1']for v in sexp.find(f,'property')));boardpins={x[1]:(sexp.first(x,'net')[-1]if sexp.first(x,'net')else None)for x in sexp.find(f,'pad')};rows=[]
for pin,(gpio,net,function)in map_by_pin.items():
assert c['pins'][str(pin)]==net and boardpins[str(pin)]==net,(pin,net)
rows.append({'packagePin':pin,'gpio':gpio,'net':net,'plannedFunction':function})
for pin,net in [(4,'3V3'),(5,'GND')]:assert c['pins'][str(pin)]==net and boardpins[str(pin)]==net
out={'inputSha256':{str(f.relative_to(p)):hashlib.sha256(f.read_bytes()).hexdigest()for f in [p/'design/netlist.json',p/'kicad/adom-custom-electronic-load.kicad_pcb']},'part':c['mpn'],'package':'LQFP32 GP, not the N-suffix variant','source':'https://www.st.com/resource/en/datasheet/stm32g0b1kc.pdf','sourceRevision':'DS13560 Rev 6','matchedSignalPins':len(rows),'matchedSupplyPins':2,'pins':rows,'limits':['Static assignment audit only; HAL and option-byte validation pending','USB bring-up adapter compiled; clock recovery, VBUS detection and enumeration physically unverified','Tach EXTI timestamps require a 32-bit microsecond timebase and measured ISR latency','Boot identity must be unique on every reset; no fixed production boot nonce']};(p/'design/mcu-pinmap.json').write_text(json.dumps(out,indent=2)+'\n');print('MCU map: 20 signal pins and 2 supply pins agree between design netlist, PCB and selected package assignments.')