s32ct-peripherals-graft-mex
Grafts one or more Peripherals-tool driver instances (`Spi`, `Uart`, `Can_43_FLEXCAN`, `Lin_43_LPUART_FLEXIO`, `Adc`, `Pwm`, `Wdg_43_*`, `Icu`, `Gpt`, `Mcl`, `Eth_43_GMAC`, `I2c`, ...) into an existin
Files15
View on GitHubSKILL.mdskills/s32ct/s32ct-peripherals-graft-mex/SKILL.md
GitHubS32CT Peripherals - Graft .mex (lift and adapt)
Lift the working <instance> block for a driver straight out of the
matching NXP RTD example .mex, surgically change the small number of
fields that must differ for the user's board (hw-channel selector,
instance name, controller count), splice into the target .mex, then
run a systematic sanitize + validate loop. Trades authoring flexibility
for speed: 3-6 validator rounds instead of 25+, because the RTD example
is already validated by NXP and its XML shape, cross-reference paths,
CommonPublishedInformation, and enum casing are guaranteed accepted.
When to use
- Use for: adding driver
<instance>blocks to a Pins-populated.mexwhen a matching RTD example ships on disk; extending a.mexwith several drivers at once (cost is roughly-flat because sanitize is a global pass); reaching a validating.mexquickly, then fine-tuning individual settings. - Do not use this skill for: drivers with no shipped RTD example (custom drivers,
Eth_43_GMACon small parts) - uses32ct-peripherals-author-mexinstead; Pins / Clocks / DCD / IVT / eFUSE / QuadSPI / GTM / FFC tools; generating driver C sources (uses32ct-generate-codeafter validation is clean).
Available Capabilities
| Capability | Notes |
|---|---|
| Discover matching RTD example | Auto-picks the closest MCU-family variant (e.g. S32K344 example for an S32K312 target). See scripts/discover.py. |
Extract example <instance> blocks |
scripts/extract_examples.py lifts <instance ... type_id="X">...</instance> XML fragments verbatim. |
| Splice with re-UUID | scripts/splice.py inserts before </instances>, handles balanced-array nesting and indent, regenerates instance-level UUIDs. |
| Systematic sanitize (idempotent) | scripts/sanitize.py redirects /Mcu/.../McuClockReferencePoint_* refs, self-closes <array> bodies referencing absent drivers (typically /Mcl/), blanks singleton dangling refs. |
| Honest validation gate | scripts/check_problems.bat (Windows) or scripts/check_problems.sh (Linux/macOS) + scripts/filter_problems.py run the launcher with -HeadlessTool <Tool> -ShowProblems, capture stderr to a file, apply the 9-pattern noise filter, count real problems. |
| Multi-driver in one call | drivers array accepts several entries per invocation; splice + sanitize is one pass. |
Quickstart
Follow the canonical 7-step workflow. Full detail with per-step
scripts, common failure modes, and iteration expectations lives in
references/iteration-playbook.md.
- Inventory the target
.mex:python scripts/inventory.py <project_path>- lists existing<instance>blocks andMcuClockReferencePoint_*names. - Discover the RTD example per driver:
python scripts/discover.py --driver Spi --mcu S32K312 --sdk PlatformSDK_S32K3. - Lift the example's
<instance>block:python scripts/extract_examples.py --driver Spi --example <path> --out work/Spi_instance.xml. Repeat per driver. - Adapt hw-channel selectors and cross-refs per driver. Consult
references/per-driver-gotchas.mdfor the concrete edits. Regenerate the instance-level UUID. - Splice into the target
.mex:python scripts/splice.py --project <project_path> --out <output_path> --instances work/*.xml. - Sanitize cross-references (idempotent):
python scripts/sanitize.py --mex <output_path>. - Validate + loop. Stage the
.mexin the probe directory, run the check wrapper, filter, count. Repeat 3-6 times.
Windows (cmd.exe) - a no-space staging path is required because cmd
mishandles redirection when a quoted path contains spaces:
copy /Y <output_path> C:\tmp_mex\probe.mex
scripts\check_problems.bat probe Peripherals
python scripts/filter_problems.py --stderr C:\tmp_mex\probe_Peripherals_stderr.txt
scripts\check_problems.bat probe Pins
python scripts/filter_problems.py --stderr C:\tmp_mex\probe_Pins_stderr.txt
Linux / macOS (sh/bash) - check_problems.sh is the POSIX
counterpart and takes the same arguments:
export S32CT_PROBE_DIR="${TMPDIR:-/tmp}/s32ct_probe"
export S32CT_INSTALL=/opt/nxp/S32ConfigTools.<release>
mkdir -p "$S32CT_PROBE_DIR"
cp -f <output_path> "$S32CT_PROBE_DIR/probe.mex"
sh scripts/check_problems.sh probe Peripherals
python3 scripts/filter_problems.py \
--stderr "$S32CT_PROBE_DIR/probe_Peripherals_stderr.txt"
sh scripts/check_problems.sh probe Pins
python3 scripts/filter_problems.py \
--stderr "$S32CT_PROBE_DIR/probe_Pins_stderr.txt"
When a filtered line survives, map it to a fix via
references/error-decision-tree.md, apply, re-run sanitize, re-check.
Configuration
- Launcher:
toolsc.exe(desktop) ors32dsc.exe(integrated_s32ds), auto-discovered at MCP startup. Sees32ct-distributions. - Path discipline: on Windows,
cmd's stderr redirection fails when any path on the command line contains a space. Copy the.mexto a no-space path (e.g.C:\tmp_mex\<name>.mex) before validating. POSIX shells quote correctly, socheck_problems.shhas no such restriction; it stages under$S32CT_PROBE_DIR(default${TMPDIR:-/tmp}/s32ct_probe). - RTD example location:
<S32DS_INSTALL>/S32DS/software/<PLATFORM_SDK>/RTD/<Driver>_<RTD_VER>/examples/S32DS/<MCU_FAMILY>/<example_dir>/<example>.mex. - Driver request schema and hw-channel selector fields live in
references/per-driver-gotchas.md.
Guardrails
- Scope. Writes the new
.mex(and propagatesClockConfigurationMappings.txtif present alongside) plus temp probe copies under a no-space directory. Reads but never writes RTD example.mex,.componentschemas,resource_tables/*.xml. Validation invocations are read-only on the filesystem; they spawn onetoolsc.exechild process per pass. No target hardware, no FreeMASTER, no registers. - Destructive actions. Refuse to overwrite the target
output_pathunlessoverwrite=true. Never modify RTD example files or component schemas. Do not "improve" the lifted block while adapting - keep the single-purpose adaptation clean so bisection remains cheap. - Refuse and escalate. If no RTD example exists for a requested
driver on the target family, stop and hand off to
s32ct-peripherals-author-mex. If a path with spaces is unavoidable, copy first; do not attempt to work aroundcmd's parser.
Validation loop
The only honest gate: toolsc.exe exits 0 almost regardless of how
many problems it logged. Trust the captured text, not the exit code.
- Copy the target
.mexto a no-space path. - Run
scripts/check_problems.bat <name> <Tool>on Windows, orscripts/check_problems.sh <name> <Tool>on Linux/macOS - it invokes the launcher with-Load ... -HeadlessTool <Tool> -Enable -ShowProblemsand redirects stdout / stderr to files under the probe directory (C:\tmp_mex\or$S32CT_PROBE_DIR). - Run
scripts/filter_problems.py --stderr <captured_stderr>- it strips the 9 framework-noise patterns (Cannot get container for IPath,derefAsr,Port_GetNumOfPinConfig,getTotalNumOfChans,getTotalNumOfGroups,getChildById,Missing right bracket, theSerDescodegen note, and theSiul2_Port ... InfoSettingnote). - Zero surviving lines is pass. Anything else is real - consult
references/error-decision-tree.md, apply the mapped fix, re-runsanitize.py, and re-validate. - Repeat the loop for Pins (regression check) after Peripherals is clean.
Plan for 3-6 rounds on the first run with a new driver mix; on repeat runs for the same MCU one or two rounds usually suffice.
Out of scope
- Populating the Pins tool (that is
s32ct-pins-author-mex). - Populating Clocks, DCD, IVT, eFUSE, QuadSPI, GTM, FFC tools.
- Adding
McuClockReferencePoint_*entries so redirected clock refs resolve to real clocks at runtime (hand off tos32ct-clocks-info). - Application-level driver containers (
SpiChannel/Job/Sequence,CanHwFiltermasks,AdcGroupDefinitioncross-refs,LinScheduletables) - project-specific; sees32ct-peripherals-info. - Generating driver C sources (that is
s32ct-generate-codeafter validation is clean).
See Also
references/per-driver-gotchas.md- per-driver adaptation rules (Spi, Uart, Can, Lin, Adc, Pwm): concrete enum casings, container path quirks, the "empty vs absent" subtleties.references/error-decision-tree.md- map eachSEVERE: [TOOL]/SEVERE: [Generationmessage pattern to a targeted fix.references/iteration-playbook.md- step-by-step recipe for rounds 1-N; expected error class per round.references/cross-reference-map.md- systematic list of cross-reference families that fail by default (/Mcl/,/Mcu/.*_CLK,BOARD_BootClockRUN) and the canonical redirect for each.s32ct-peripherals-author-mex- sibling; authoring-from-scratch path when no RTD example is available.s32ct-peripherals-info- schema and resource-table lookup for application-level containers.s32ct-pins-author-mex- prerequisite; produces the Pins-populated.mex.s32ct-clocks-info- addMcuClockReferencePoint_*entries so redirected refs resolve at runtime.s32ct-generate-mex-config- lower-level clone-and-patch operator.s32ct-generate-code- emit C sources once validation passes.s32ct-distributions- launcher and prefix selection.