From 7590a8e0c951124c54755e9ccebc669e5cb77054 Mon Sep 17 00:00:00 2001 From: Thorsten de Buhr Date: Wed, 18 Nov 2026 10:26:27 +0100 Subject: [PATCH] Preserve RA8P1 trace state during debug preparation --- .agents/skills/prepare-ra8p1-trace/SKILL.md | 104 +++++++++++++------- .github/workflows/build.yml | 2 +- Board/EK-RA8P1/README.md | 16 ++- Board/EK-RA8P1/debug-run.yml | 19 ++-- README.md | 2 +- docs/BOARD_SUPPORT.md | 2 +- docs/BUILD.md | 4 +- docs/DEBUG_PROBES.md | 2 +- docs/DESIGN.md | 2 +- docs/TRACE_APP.md | 11 ++- docs/VALIDATION.md | 25 +++++ 11 files changed, 133 insertions(+), 56 deletions(-) diff --git a/.agents/skills/prepare-ra8p1-trace/SKILL.md b/.agents/skills/prepare-ra8p1-trace/SKILL.md index a1118dd..3d68ff6 100644 --- a/.agents/skills/prepare-ra8p1-trace/SKILL.md +++ b/.agents/skills/prepare-ra8p1-trace/SKILL.md @@ -1,6 +1,6 @@ --- name: prepare-ra8p1-trace -description: Prepare this repository's EK-RA8P1 CPU0 debug description and normal SWO trace runtime after a build or CMSIS refresh. Applies the temporary RA_DFP 6.6.0 configuration with CMake and the installed pyTS; does not start a hardware session. +description: Prepare this repository's EK-RA8P1 CPU0 debug description and SWO file runtime after the final build or CMSIS refresh, using the pinned debug template and installed pyTS. Does not patch a PDSC or start hardware. --- # Prepare RA8P1 trace @@ -9,49 +9,77 @@ Apply the temporary CPU0/AP0 and SWO configuration for `EK-RA8P1@ULINKplus` in the repository containing `Trace.csolution.yml`. Read the [board procedure](../../../Board/EK-RA8P1/README.md#debug-and-trace-preparation) for the DFP gap and the [trace workflow](../../../docs/TRACE_APP.md#configure-and-generate-trace) -for normal profile generation. Other targets use their existing setup. - -1. Check that the selected solution/target is this repository's - `EK-RA8P1@ULINKplus`, with `Renesas::R7KA8P1KF:CPU0` and - `Renesas::RA_DFP@6.6.0`. Do not switch a different active target silently or - apply this pinned description to another DFP version. -2. Complete any required build/refresh first. Use `cmsis_action build` when - available, or the documented `cbuild` command in the board procedure. - Require the current `out/TraceDemo/EK-RA8P1/Debug/TraceDemo.elf` and generated - `out/Trace+EK-RA8P1.cbuild-run.yml`. Preserve existing source trace settings. -3. From the repository root, apply the versioned description with the existing - build tool; no custom script or YAML rewrite is needed: +for normal profile generation. Use file tools; no custom helper or build hook. + +## Preflight before changing files + +1. Verify this workspace's selected solution/target is `EK-RA8P1@ULINKplus`, + device `Renesas::R7KA8P1KF:CPU0`, pack `Renesas::RA_DFP@6.6.0` and the normal + Debug context. Stop on a mismatch; do not switch another target silently. +2. Complete any required build/refresh first through `cmsis_action build` for + this workspace/target, or the documented `cbuild` command. Require the current + `out/TraceDemo/EK-RA8P1/Debug/TraceDemo.elf` and generated + `out/Trace+EK-RA8P1.cbuild-run.yml`. Check the template's pack/image paths and + resources against that output; report unexpected drift before replacing it. +3. Inspect `.cmsis/Trace+EK-RA8P1@ULINKplus.ctrace.yml` before editing the run + description. Preserve CPU0 source choices, including custom watches/channels. + The normal demo uses `g_trace_sine`, `g_trace_noise`, ITM1, PC samples, + 8 MHz timestamps and DWT synchronization. Stop on an active CPU1 setup or an + incompatible timestamp clock. Plan to remove only disabled CPU1 placeholders: + pyTS can otherwise emit CPU1 disable register accesses. + If a matching `~` preview profile could redirect generation, report the + conflict and stop without changing either profile. Do not replace user + settings with defaults. + +## Prepare and validate + +1. Apply the preflighted profile changes: back up before removing disabled CPU1 + placeholders, and preserve every CPU0 setting. If no placeholders exist, + leave the profile unchanged. Back up the generated run description outside + the pack and build inputs. + Apply the versioned [debug template](../../../Board/EK-RA8P1/debug-run.yml) + with the agent's file tools only if its contents differ. The equivalent + POSIX command from the repository root is: ```sh - cmake -E copy_if_different Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml + cp Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml ``` -4. Generate the trace runtime from that run description and current ELF using - the installed CMSIS Debugger's pyTS. Resolve its executable from the installed - extension or the host's tool configuration; never hardcode a host path or - install a separate Python package. Quote the resolved executable path: + This replaces a generated description, not a pack file. Preserve the vendor + pack; this skill does not patch a PDSC. Do not add interpreter helpers, + CMake/Make preparation steps or automatic build hooks. +2. Generate the trace runtime with the installed CMSIS Debugger's bundled pyTS. + Resolve its executable from the extension or tools configuration; quote it, + and do not install a separate package or hardcode a host-specific path: ```sh "$trace_pyts" out/Trace+EK-RA8P1.cbuild-run.yml --format json ``` - The normal **Trace Generation → Convert *.ctrace.yml to *.ctrace-run.yml** - command is equivalent. If neither route is available, report the missing - trace tool and stop before claiming preparation succeeded. -5. Check the generated - `.trace/Trace+EK-RA8P1@ULINKplus.ctrace-run.yml` against the selected source - profile and current ELF: resolve enabled watches without missing symbols, - retain the requested ITM/PC/timestamp/sync sources, and require CPU0-only - register operations. Disabled CPU1 metadata alone is not a register access. - The standard demo enables `g_trace_sine`, `g_trace_noise`, ITM1, PC samples, - 8 MHz timestamps and DWT synchronization. Require SWO `mode: file` at 1 Mbaud. - -Report the prepared target, ELF/profile and generation result. Preparation -does not flash, reset, start/stop debugging or open a live trace TCP service. -For a separately requested hardware run, use the CMSIS tools and the normal -file capture → automatic CSV conversion on pause/end workflow. - -A subsequent build, refresh or target change can replace the prepared run -description. Repeat the copy and trace generation after the last such operation -and before Enter Debug. Remove this skill and the template once the DFP/tool -flow supplies the required behavior natively and has been validated. + The UI **Convert *.ctrace.yml to *.ctrace-run.yml** command uses the same + generator with `--allow-missing`. For either route inspect errors and missing + symbols explicitly; a successful exit alone is insufficient. +3. Parse the run description through the installed pyOCD `TraceConfig` consumer + without creating a session/probe. Require one enabled SWO source in `file` + mode with 1000000 Hz input and 1000000 bit/s output, without ignored-source + warnings. `mode` and clocks are siblings of the null `swo-uart` key; nesting + them inside it passes basic YAML/pyTS checks but is ignored by pyOCD. +4. Inspect `.trace/Trace+EK-RA8P1@ULINKplus.ctrace-run.yml` against the selected + production profile and current ELF: resolve all enabled watches, preserve + requested ITM/PC/timestamp/sync sources, and require CPU0-only register + operations including `ctrace-disable`. Disabled CPU1 metadata does not make + CPU1 register accesses safe. Use the CMSIS structural validator when available; + its checks cover common structure rather than device behavior. +5. Re-read the files after extension watchers settle. A repeat without another + build or profile change must preserve the resulting configuration. Compare + before writing the template again and retain existing backups. + +Report preparation and hardware reception separately. Do not flash, reset, +start/stop debugging or open a live trace TCP service. A separately requested +hardware run uses CMSIS tools and normal file capture → automatic CSV conversion +on pause/end. The sequence rejects a conflicting running trace clock before +register writes; end trace and reset the device before changing its clock mode. + +Build, refresh or target changes can overwrite the generated description. +Repeat preparation after the last such operation and before Enter Debug. Remove +this skill and template once the native DFP/tool flow has been validated. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 37878c8..6fee3cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,5 +59,5 @@ jobs: - name: Check explicit RA8P1 debug preparation if: matrix.context == 'TraceDemo.Debug+EK-RA8P1' run: | - cmake -E copy_if_different Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml + cp Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml cmp Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml diff --git a/Board/EK-RA8P1/README.md b/Board/EK-RA8P1/README.md index a48a23e..7a6f6bd 100644 --- a/Board/EK-RA8P1/README.md +++ b/Board/EK-RA8P1/README.md @@ -43,13 +43,13 @@ cbuild Trace.csolution.yml --active 'EK-RA8P1@ULINKplus' --packs --frozen-packs The firmware build has no custom preparation step. After the final build or refresh, invoke `Use $prepare-ra8p1-trace` with an agent that can read this repository's [skill](../../.agents/skills/prepare-ra8p1-trace/SKILL.md). It copies -the temporary [debug-run.yml](debug-run.yml) using the existing CMake executable +the temporary [debug-run.yml](debug-run.yml) using its file tools and generates the normal trace runtime with the installed pyTS. Without an agent, run the same copy from the repository root: ```sh -cmake -E copy_if_different Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml +cp Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml ``` Then generate the trace runtime from the current ELF through the normal **Trace @@ -69,7 +69,10 @@ The unmodified DFP supplies no RA8P1 SWO sequences, processor/AP mapping or - CPU0 on AP0, with CPU0-only processor resources and trace configuration. - P209 SWO routing and the trace clock before CoreSight discovery and after reset. - PRCR access enables are preserved while setting TRCKCR to MOCO `/8`. + All PRCR access enables are preserved while setting TRCKCR to MOCO `/8`. + An already matching running trace clock is retained. A different running + source/divider is rejected before register writes; end trace and reset before + changing modes (Hardware Manual p.376). - Legacy pyOCD ITM/TPIU setup; full trace setup is not enabled. - The pinned DFP's programming algorithms and system descriptions, referenced through `${CMSIS_PACK_ROOT}`. Solution and ELF paths are relative to `out/`. @@ -81,6 +84,13 @@ remove the template and preparation skill together and verify the generated description. Installed packs and the reference project remain unchanged. +Preparation checks the production source profile before changing runtime files. +Active CPU1 settings and conflicting `~` preview profiles stop preparation; +disabled CPU1 placeholders require removal with a backup to prevent unwanted +CPU1 disable writes. Custom CPU0 sources remain intact. Both installed pyOCD +transport parsing and pyTS output must pass, including unresolved-symbol and +register-operation checks; successful conversion alone is insufficient. + SWD is 10 MHz. MOCO `/8` gives a **1 MHz trace input**, serialized at **1 Mbaud**; CPU0 timestamps use **8 MHz**. The profile watches `g_trace_sine` and `g_trace_noise`, enables ITM1, samples the PC every 8192 core cycles and requests diff --git a/Board/EK-RA8P1/debug-run.yml b/Board/EK-RA8P1/debug-run.yml index 9834d68..a29fc5c 100644 --- a/Board/EK-RA8P1/debug-run.yml +++ b/Board/EK-RA8P1/debug-run.yml @@ -133,18 +133,23 @@ cbuild-run: blocks: - execute: | __var saved_ap = __ap; + __Result = 0; __ap = 0; - Write32(0x4001B030, 0x00000009); // TRPORTCR: CPU0 SWO on P209. __var trace_clock = Read8(0x4001E03F); - - if: trace_clock != 0x83 + - if: "(trace_clock & 0x80) != 0 && (trace_clock & 0x1F) != 0x03" + execute: | + __ap = saved_ap; + __Result = -1; + Message(2, "RA8P1 TRCLK is running with a different source/divider; end trace and reset before changing it"); + - if: __Result == 0 blocks: - execute: | - __var saved_prcr = Read16(0x4001E3FA) & 0x000F; - Write16(0x4001E3FA, 0xA501 | saved_prcr); - - if: "(trace_clock & 0x80) != 0" + Write32(0x4001B030, 0x00000009); // TRPORTCR: CPU0 SWO on P209. + - if: "(trace_clock & 0x80) == 0" execute: | - Write8(0x4001E03F, trace_clock & 0x7F); - - execute: | + // Preserve PRC0, PRC1, PRC3, PRC4 and PRC5 (Hardware Manual pp.525-526). + __var saved_prcr = Read16(0x4001E3FA) & 0x003B; + Write16(0x4001E3FA, 0xA501 | saved_prcr); Write8(0x4001E03F, 0x03); // TRCK=/8 while stopped. Write8(0x4001E03F, 0x83); // 8 MHz MOCO /8 = 1 MHz trace input. Write16(0x4001E3FA, 0xA500 | saved_prcr); diff --git a/README.md b/README.md index a34e1f2..272e635 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Capture-start and pause/end recording issues remain; see [Validation](docs/VALID EK-RA8P1: after build/refresh, run `Use $prepare-ra8p1-trace` ([skill](.agents/skills/prepare-ra8p1-trace/SKILL.md)) or follow the [shell procedure](Board/EK-RA8P1/README.md#debug-and-trace-preparation). -This temporary RA_DFP 6.6.0 workaround uses CMake and bundled pyTS without a build +This temporary RA_DFP 6.6.0 workaround uses a file copy and bundled pyTS without a build hook or extra interpreter. SWO uses the standard automatic CSV workflow. Hardware results and open capture issues are listed in diff --git a/docs/BOARD_SUPPORT.md b/docs/BOARD_SUPPORT.md index 5948b7b..50b4e70 100644 --- a/docs/BOARD_SUPPORT.md +++ b/docs/BOARD_SUPPORT.md @@ -208,7 +208,7 @@ linker template. The Cortex-M33 CPU1 is not an application target. The original `Renesas::RA_DFP@6.6.0` remains unmodified. A documented local CPU0-only debug description supplies the missing CPU0/AP0 and SWO setup. The -explicit preparation skill or documented CMake command copies it after build/refresh; +explicit preparation skill or documented file-copy command copies it after build/refresh; standard pyTS generates trace settings from the current ELF. No `.dbgconf` defaults exist for this device in that DFP. The board README records Debug In jumpers, separate power, security prerequisites, diff --git a/docs/BUILD.md b/docs/BUILD.md index 488b57f..2a7fa43 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -136,7 +136,7 @@ build has no custom preparation step. After the final build/refresh, invoke versioned CPU0-only debug description explicitly: ```sh -cmake -E copy_if_different Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml +cp Board/EK-RA8P1/debug-run.yml out/Trace+EK-RA8P1.cbuild-run.yml ``` Generate the trace runtime from the current ELF with the normal Trace Generation @@ -146,4 +146,4 @@ to CSV on pause/end. This needs no additional interpreter or CMSIS tools export. The [board README](../Board/EK-RA8P1/README.md) explains the temporary DFP 6.6.0 workaround, clock baseline and hardware prerequisites. CI builds the firmware and -checks the explicit CMake copy separately; it does not require an AI agent. +checks the explicit file copy separately; it does not require an AI agent. diff --git a/docs/DEBUG_PROBES.md b/docs/DEBUG_PROBES.md index 666d60a..66f91c4 100644 --- a/docs/DEBUG_PROBES.md +++ b/docs/DEBUG_PROBES.md @@ -73,7 +73,7 @@ see the [file naming table](TRACE_APP.md#configuration-ownership). Use `EK-RA8P1@ULINKplus`, 10 MHz SWD, GDB port 3333 and 1 Mbaud SWO. After the final build/refresh, apply the versioned CPU0/AP0 description with the [preparation skill](../.agents/skills/prepare-ra8p1-trace/SKILL.md) or the explicit -CMake command in the [board procedure](../Board/EK-RA8P1/README.md#debug-and-trace-preparation). +file-copy command in the [board procedure](../Board/EK-RA8P1/README.md#debug-and-trace-preparation). Generate trace through the normal Trace Generation view or bundled pyTS before Enter Debug. SWO uses file capture with automatic RAW-to-CSV conversion on pause/end and no live trace TCP service. diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 3a75f1c..0903852 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -99,7 +99,7 @@ and would not generate the call to `app_main()`. EK-RA8P1 reuses the supplied Renesas RTOSDemo project's CMSIS-based CPU0 startup/header, while retaining this project's 8 MHz reset-clock baseline. Its DFP lacks CPU0/AP0 and SWO setup; the versioned CPU0 debug description and a -preparation skill with an explicit CMake command apply the run-description +preparation skill with an explicit file-copy command apply the run-description override workflow without changing installed Packs or adding an interpreter dependency. See the [board layer](../Board/EK-RA8P1/README.md). diff --git a/docs/TRACE_APP.md b/docs/TRACE_APP.md index fd6d4b1..bd4b867 100644 --- a/docs/TRACE_APP.md +++ b/docs/TRACE_APP.md @@ -153,12 +153,21 @@ Their development status and source/release links are recorded there. For EK-RA8P1, apply the versioned CPU0 debug description after the final build/refresh using the [preparation skill](../.agents/skills/prepare-ra8p1-trace/SKILL.md) -or CMake command in the [board procedure](../Board/EK-RA8P1/README.md#debug-and-trace-preparation). +or file-copy command in the [board procedure](../Board/EK-RA8P1/README.md#debug-and-trace-preparation). Trace generation then uses this description and the current ELF through the same view or pyTS command as the other targets. Repeat preparation after a subsequent build, refresh or target change. Capture uses the normal SWO file and automatic CSV workflow. +For this target, preflight the production profile before changing generated +files. Resolve preview-profile conflicts and active CPU1 settings first; +remove only disabled CPU1 placeholders with a backup. Require the installed +pyOCD transport parser to accept the SWO file source and inspect pyTS errors, +missing symbols and all register groups, including source-disable groups. +The UI converter uses `--allow-missing`, so its exit status alone is insufficient. +After extension watchers settle, re-read the output; repeated preparation +without input changes must preserve the configuration. + Equivalent offline generation with the bundled pyTS executable, for example: ```sh diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 266811e..c051be1 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -290,3 +290,28 @@ local documentation links and diff checks passed. The common CProject now matches `main`. The current debug session could not read the core and its server previously reported `No such device`; no new hardware capture is claimed for this preparation change. + +## EK-RA8P1 preparation corrections — 2026-11-18 + +The debug template now preserves all PRCR permissions (`0x003B`) and rejects a +conflicting running trace-clock source/divider before register writes. Matching +running clocks remain untouched. The skill preflights source/preview conflicts, +checks installed-consumer acceptance and all generated register groups, and +preserves custom CPU0 settings. Preparation uses a file copy without a custom +helper or build hook; vendor pack contents remain unchanged. + +**Offline PASS:** 337 host checks with the installed pyOCD YAML parser and +sequence interpreter cover both entry sequences, SWO disabled, stopped clocks, +all 32 PRCR permission combinations, matching and conflicting running clocks, +AP restoration and both throwing and log-only errors. No probe transport was +created. The installed trace consumer accepts file mode at 1 MHz/1 Mbaud. + +Bundled pyTS generated all six CPU0 references from the tracked production +profile and existing GCC ELF, resolving both DWT symbols without errors or CPU1 +accesses. A missing-symbol negative case was detected, including with +`--allow-missing`; normal regeneration restored identical run/profile/runtime/ELF +hashes. Skill, common YAML structure, documentation links and diff checks pass. + +Firmware sources did not change; no new hardware capture is claimed. The +November 17 hardware results above predate these sequence changes, and capture +integrity plus hardware acceptance of the revised sequences remain open.