RTT 主机侧

以下内容自动抽取自 sdk-headers/HFLinkDriver_rtt.h ,含 12 个公开函数及全部公开类型。函数指针回调类型不单独列出,见所属结构体成员说明。

枚举

RTT control commands (per SEGGER JLINKARM_RTTERMINAL_CMD_*)

Values:

Start RTT (locate the control block + register the background poll task); p = HFLink_RTT_START* or NULL

Stop RTT; p = HFLink_RTT_STOP* or NULL

Query the number of up/down buffers; p = HFLink_RTT_NUMBUF* (required)

Query buffer description (name/size/flags); p = HFLink_RTT_BUFDESC* (required)

Configure the telnet server (must be called before START); p = HFLink_RTT_TELNETCFG* (required)

结构体

START command parameters (per SEGGER JLINK_RTTERMINAL_START).

Public Members

Control block address; 0 = clear explicit address (Lua config / auto scan)

Reserved (must be 0)

Reserved (must be 0)

Reserved (must be 0)

STOP command parameters (per SEGGER JLINK_RTTERMINAL_STOP).

Public Members

If 1, write an invalid ID to the target control block (firmware re-initializes)

Reserved

Reserved (must be 0)

Reserved (must be 0)

Reserved (must be 0)

GETNUMBUF command parameters (per SEGGER: Direction in, NumBuffers out).

Public Members

In: HFLINK_RTT_DIRECTION_UP / HFLINK_RTT_DIRECTION_DOWN

Out: number of buffers (channels) in that direction

GETDESC command parameters (per SEGGER JLINK_RTTERMINAL_BUFDESC).

Public Members

In: buffer index within the direction (0-based)

In: HFLINK_RTT_DIRECTION_UP / HFLINK_RTT_DIRECTION_DOWN

Out: buffer name, NUL-terminated (target sName; empty if unnamed)

Out: buffer size in bytes (0 for unconfigured channels)

Out: target-side SEGGER_RTT_MODE_* flags

SETTELNETCFG command parameters: configure the telnet server (HFLinkSDK extension, no SEGGER equivalent)

The telnet server starts/stops automatically with RTT START/STOP (default 127.0.0.1:19021); this command must be called before START, and calling it while RTT is running returns HFLINK_ERR_BUSY. If the port is already in use, startup is silently skipped (no warning, START is unaffected; the condition is only observable via GetLastError), and the RTT API data plane is unaffected.

Public Members

In: 1 = enable (default); 0 = disable the telnet server

In: bind address (empty = default 127.0.0.1; "0.0.0.0" allows remote access)

In: port (0 = default 19021; range 1..65535)

Reserved (must be 0)

API

Execute an RTT control command (per SEGGER JLINK_RTTERMINAL_Control)

  • CMD_START: locate and validate the control block (first time), then register the poll task with the CoreSight polling scheduler; idempotent, returns 0 when already running. Returns HFLINK_ERR_NOT_INITIALIZED when no debug session is attached to the target.

  • CMD_STOP: unregister the poll task (in-flight callbacks have exited on return). Returns 0 if RTT was running, 1 if it was not (SEGGER semantics); negative values are errors.

  • CMD_GETNUMBUF / CMD_GETDESC: return HFLINK_ERR_NOT_INITIALIZED (-2) when RTT was not started, matching the -2 of SEGGER's "RTT Control Block not found yet".

参数:
  • cmd -- HFLINK_RTT_CMD_* command

  • p -- Pointer to the command parameter struct (see each command; START/STOP may be NULL)

返回:

>= 0 on success (CMD_STOP: 0/1 distinguishes the previous state); < 0 error code

Read up-channel data from the host-side buffer (per SEGGER JLINK_RTTERMINAL_Read)

Pure memory copy: data is moved from the target into the host buffer by the background poll task; this call never accesses the debug bus and never blocks. Data is consumed on read (same as SEGGER).

参数:
  • buffer_index -- up-channel index (0-based)

  • s_buffer -- Output buffer

  • buffer_size -- Output buffer capacity

返回:

>= 0 actual number of bytes read (0 if no new data); < 0 error code

Write data to a down channel (host -> target; per SEGGER JLINK_RTTERMINAL_Write)

Synchronous write into the target-side ring buffer; when space is insufficient, writing stops once the buffer is full and the actual number of bytes written is returned (same partial-write semantics as SEGGER). In M0/M0+ degraded mode, writes while the target is running return 0.

参数:
  • buffer_index -- down-channel index (0-based)

  • s_buffer -- Data to write

  • buffer_size -- Number of bytes to write

返回:

>= 0 actual number of bytes written; < 0 error code

Query the number of readable bytes in the host buffer (semantics of the newer SEGGER JLINK_RTTERMINAL_GetNumBytesOnBuffer)

Pure memory query; never touches the debug bus. The watermark only covers data already harvested into the host buffer; new data not yet harvested from the target is not counted.

参数:
  • buffer_index -- up-channel index (0-based)

  • num_bytes -- Outputs the number of readable bytes

返回:

HFLINK_OK; HFLINK_ERR_NOT_INITIALIZED if not started; HFLINK_ERR if the channel is invalid

Create an RTT session. If target is NULL, only configuration calls are allowed (START returns an error).

Destroy the session (unregisters the poll task and frees all resources automatically).

Set the automatic scan range (Method 1)

备注

If no range is set, an error is returned when the scan path is ultimately taken; the range also bounds structure validation of explicit addresses

Bind a Lua runtime (Method 2: the hf.rtt.set_control_block setting is read at START).

Set the background poll interval (milliseconds, default 2; range 1..1000)

备注

Takes effect immediately while RTT is running (implemented internally by unregistering + re-registering with the scheduler)

Query the located control block address (returns HFLINK_ERR_NOT_INITIALIZED if not located).

Query the most recent error description (outputs an empty string when there is no error).

Read the address configured via hf.rtt.set_control_block in the Lua runtime (Method 2)

返回:

HFLINK_OK with a valid *address; HFLINK_ERR if not configured