> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# SEGGER J-Trace

> Connect a SEGGER J-Trace over the CoreSight-20 trace cable for Arm ETM instruction trace and source coverage.

Use a J-Trace to see which instructions an Arm target executed, or which functions and source lines a test exercised. The target must support ETM. A plain J-Link handles debugging and RTT, but it can't capture ETM trace.

## Prepare the connection

1. Install the SEGGER **J-Link Software and Documentation Pack** on the computer running Inlay.
2. Connect the J-Trace to the target with the fine-pitch CoreSight-20 trace cable. The wide 0.1-inch debug ribbon carries no trace signals.
3. Confirm the board routes the target's ETM trace pins to that connector, and that the target drives `TRACECLK`.
4. Find the exact SEGGER device name for your MCU, such as `STM32F407VE`.
5. Build the firmware and keep the ELF of the build you'll run.

### Tell Inlay the device and clock

Every capture needs the SEGGER device name. The CPU clock is optional: it gives the instruction timeline an estimated time axis. Where Inlay reads them depends on how you start the capture:

| How you start | Device | CPU clock |
| - | - | - |
| Bounded capture or coverage run in the Monitor | The J-Link **Device** selected in the Monitor. If none is selected, `Target MCU` in [`INLAY.md`](/docs/core-concepts/inlay-md). | `cpu_freq` in `INLAY.md`, such as `cpu_freq = 168MHz`. If it isn't set, the **CPU** value in a Serial Monitor tab's ITM settings. |
| Stream in the Trace tab | The selected J-Link **Device** only | That **CPU** value only |
| Request in chat | The device you name in the request, or `Target MCU` | The clock you give in the request, or `cpu_freq` |

* Select the J-Link **Device** in a Serial Monitor tab's RTT settings or in the Trace tab's source settings. Captures from the Monitor connect over the **Interface** selected with it, SWD unless you choose JTAG.
* `Target MCU` must hold one exact SEGGER device name. Don't guess it. A wrong name makes the connection fail.
* The time axis is an estimate based on instruction count, not a measurement.

Use the ELF of the build that's running. Inlay resolves addresses as they arrive, so attaching an ELF afterward can't fix unresolved rows. If you don't choose one, a bounded capture or coverage run uses an ELF it finds in the project, so name the ELF when the project builds more than one.

## Capture instructions and coverage

> [!WARNING]
>
> Captures and coverage runs reset the target, run it for the set time, and then halt it. They also take the probe from RTT and any running debug server, which disconnects GDB sessions. Save paused-state evidence before you start one.

You can start each workflow from the Monitor or from chat:

| Workflow | In the Monitor | From chat |
| - | - | - |
| Bounded instruction capture | In the **Trace** tab, choose **Instructions (ETM)**, then select **Capture** | Run `/debug`, then ask for an ETM capture |
| Streamed instruction capture | In the **Trace** tab, choose **Instructions (ETM)**, then select **Stream** | Run `/debug`, then ask for a streamed capture |
| Source coverage | **Run coverage** in the **Coverage** tab | Run `/debug`, then ask for coverage |

For example:

```text theme={"theme":"css-variables"}
Use J-Trace to capture three seconds from build/firmware.elf. Open the result
in Trace and show the latest instructions with function and source names.
```

```text theme={"theme":"css-variables"}
Run five seconds of function and source-line coverage for build/firmware.elf
while the startup self-test runs. Show uncovered functions.
```

A bounded capture from the Trace tab keeps the most recent 65,536 instructions at most. Longer runs execute more instructions than that window holds. Coverage counts every instruction in the run, so coverage stays complete even when the trace window holds only the tail.

See [Coverage and trace](/docs/debug-mode/coverage-and-trace.md) for the step-by-step workflows, settings, and how to read the results.

## Choose a longer stream carefully

A streamed capture starts at reset and keeps a rolling window of recent instructions, so it can include startup that a bounded capture misses. To read the trace, it halts the target between short slices, and the firmware runs far slower than normal. Interrupts, timeouts, and handshakes can behave differently.

Use a logic analyzer, oscilloscope, or target timer for timing measurements. Instruction order and estimated time axes don't establish elapsed time.

## Script a custom capture

If the built-in captures don't fit your test, ask Inlay to write a [hardware script](/docs/debug-mode/hardware-scripts.md). Scripts can import the `jtrace` Python package for capture, coverage, and direct target control. Inlay makes it available to hardware scripts automatically, so there's nothing to install.

```python .inlay/hardware/coverage_check.py theme={"theme":"css-variables"}
from jtrace import capture_coverage

report_path, result = capture_coverage(
    "build/firmware.elf", "STM32F407VE", duration_ms=5000
)
totals = result.totals
print(f"{totals.functions_covered}/{totals.functions} functions covered")
```

Reports and captures from scripts appear in the Coverage and Trace tabs.

* Run scripts through Inlay's hardware-script runner. It holds the probe for the script so other hardware workflows don't compete for it.
* When a script controls the target directly, open the probe with `with JLink(...)` so it closes even when the script fails. A probe left open blocks later flashing, debugging, and RTT until it's closed.

## Troubleshoot

* **`SEGGER J-Link software not found`:** install the J-Link Software and Documentation Pack, then try again.
* **`No SEGGER probe detected`:** connect the J-Trace over the fine-pitch CoreSight-20 cable.
* **The message says a plain J-Link can't stream trace:** only a J-Link is connected. Use [GDB](/docs/debug-mode/gdb.md) or [RTT](/docs/debug-mode/rtt.md) with it, or connect a J-Trace for ETM.
* **`No target device configured`:** select the J-Link **Device** in a Serial Monitor tab, or add `Target MCU = <name>` to `INLAY.md`.
* **`No .elf firmware binary found in the project`:** build the firmware, or name the ELF in your request.
* **`Trace start failed`, or no instructions:** check the trace cable, target power, the device name, routed trace pins, and `TRACECLK`.
* **Function or source names are wrong:** capture again with the ELF of the build that's running.
* **Behavior changes during a capture:** a streamed capture slows the target. Compare with a bounded capture or an external measurement.
* **`Hardware is busy in another workflow.`:** Inlay or a hardware script holds the probe. Wait for it to finish or stop it.
* **The probe stays busy:** stop active captures and scripts, and disconnect unused debugger sessions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.