# RTT Transport

SEGGER Real-Time Transfer (RTT) transport for TraxProbe. Uses J-Link for high-speed trace output.

## Setup

This transport uses the **official SEGGER RTT v8.56a** from: https://github.com/SEGGERMicro/RTT

### Directory Structure

```
transports/RTT/
├── SEGGER_RTT.c              ← Official SEGGER RTT (add to build)
├── trax_transport_rtt.c      ← TraxProbe transport (add to build)
├── README.md
├── include/
│   ├── SEGGER_RTT.h          ← Official SEGGER header
│   └── SEGGER_RTT_Conf.h     ← TraxProbe-customized config
└── config/
    └── trax_transport_config.h  ← Buffer size configuration
```

### Include Paths

Add to your build system:

```
Third_Party/TraxProbe/transports/RTT/include
```

### Source Files

Add to your build:
- `Third_Party/TraxProbe/transports/RTT/SEGGER_RTT.c`
- `Third_Party/TraxProbe/transports/RTT/trax_transport_rtt.c`

## Architecture

TraxProbe uses a **buffered architecture** for optimal real-time performance:

```
┌──────────────────────────────────────────────────────────────────┐
│                         MCU                                       │
│                                                                   │
│  ┌─────────────┐    ┌──────────────────┐    ┌─────────────────┐  │
│  │ ISR / Task  │───►│ Internal Buffer  │───►│ trax_transfer() │  │
│  │ (critical)  │    │ (contiguous)     │    │ (background)    │  │
│  └─────────────┘    └──────────────────┘    └────────┬────────┘  │
│        │                                              │           │
│        │ ~1-2µs                                       │ bulk      │
│        │ per frame                                    │ transfer  │
│                                                       ▼           │
│                                              ┌─────────────────┐  │
│                                              │    RTT Buffer   │  │
│                                              └────────┬────────┘  │
└──────────────────────────────────────────────────────┼───────────┘
                                                       │
                                                       ▼ J-Link
                                              ┌─────────────────┐
                                              │   Traxcope      │
                                              └─────────────────┘
```

## Configuration

**Single source of truth:** `config/trax_transport_config.h`.

### RTT Channel (must match Traxcope)

```c
#define TRAX_RTT_UP_CHANNEL    (1)   /* Trace: Target → Host */
#define TRAX_RTT_DOWN_CHANNEL  (1)   /* Commands: Host → Target */
```

### RTT Buffer Size

```c
#define TRAX_RTT_BUFFER_SIZE_UP     (16384)  /* MCU → Host (trace) */
#define TRAX_RTT_BUFFER_SIZE_DOWN   (64)     /* Host → MCU (commands) */
```

## Important: Initialization Timing

The SEGGER RTT uses **runtime initialization**. Connect Traxcope/J-Link RTT Viewer **after** `trax_transport_rtt_init()` runs (invoked by `trax_init()` via the `TRAX_TRANSPORT_INIT` selector).

## Files

| File | Description |
|------|-------------|
| `SEGGER_RTT.c` | Official SEGGER RTT v8.56a |
| `trax_transport_rtt.c` | TraxProbe transport implementation |
| `include/SEGGER_RTT.h` | Official SEGGER RTT header |
| `include/SEGGER_RTT_Conf.h` | TraxProbe-customized RTT configuration |
| `config/trax_transport_config.h` | RTT buffer sizes and channel config |

## Performance

| Metric | Value |
|--------|-------|
| Frame write (ISR) | ~1-2µs |
| RTT transfer (background) | ~0.5µs per 32 bytes |
| Max throughput | >1 MB/s (depends on J-Link) |

*Measured on ARM Cortex-M4 @ 72MHz*

## Updating SEGGER RTT

To update to a newer version of SEGGER RTT:
1. Download from https://github.com/SEGGERMicro/RTT
2. Replace `SEGGER_RTT.c` and `include/SEGGER_RTT.h`
3. Keep `include/SEGGER_RTT_Conf.h` (TraxProbe-customized)
