Embedded chip debugging artifact-J-Link RTT detailed explanation

"  Real Time Transfer (RTT for short) is a tool for embedded system monitoring and interaction launched by Segger. It integrates SWO (debugging log output in SWD debugging technology) and other capabilities, and has extremely high performance. "

Real Time Transfer (RTT for short) is a tool for embedded system monitoring and interaction launched by Segger. It integrates SWO (debugging log output in SWD debugging technology) and other capabilities, and has extremely high performance. The technical characteristics of RTT are as follows:

  • Bi-directional communication capability with target embedded application

  • High-speed transfer rates that do not affect the real-time behavior of embedded applications

  • Use the debug channel for communication (equivalent to no need to occupy additional peripheral interfaces such as GPIO)

  • Does not require additional hardware or pins in the target embedded system

  • Any J-Link model is supported (J-Link model list and comparison can refer to https://www.segger.com/products/debug-probes/j-link/models/model-overview/)

  • Can be supported by ARM Cortex-A/R/M series chips, and supported by RISC-V and Renesas RX

  • Provide complete RTT implementation code

01

What is RTT

RTT can enable high-speed two-way communication without affecting the real-time behavior of embedded applications. It can output debugging information and input related control commands from the outside. RTT can support multiple channels in both transmission directions (output and input), and different channels can be used for different purposes.

A common implementation is to use one channel per transfer direction, for debug I/O:

By using the J-Link RTT Viewer tool on the PC, there can be multiple virtual terminals in the tool, which can be used to print different information (such as a window for standard output, a window for error message output, and a window for debug information output).

It is very easy to use RTT in the target application. The implementation code is free to download and can be integrated into any existing application.

With RTT communication, any J-Link can be used. An easy way to communicate via the terminal (channel 0) is to use a Telnet client or similar to create a connection to localhost:19021 while a connection to the J-Link is active (for example, via a debug session).

02

RTT related tools

The RTT tool is included in the J-Link software package, and the corresponding installation package can be downloaded according to the system needs (address: https://www.segger.com/downloads/jlink/). Both Windows and MAC are installed with a graphical interface. Very simple, here is a supplementary description of the installation details under the Linux system, taking the Raspberry Pi system as an example:

# First download the .tgz installation package, and then unzip it according to the following steps 
$ mkdir -p ~/opt/SEGGER 
$ cd ~/opt/SEGGER 
$ tar xf ~/Downloads/JLink_Linux_V684_arm64.tgz 
$ chmod aw ~/opt/SEGGER/ JLink_Linux_V684_arm64 
$ ls -l ~/opt/SEGGER/JLink_Linux_V684_arm64 

# Next is udev configuration 
$ sudo cp 99-jlink.rules /etc/udev/rules.d/ 

# Restart the system, or manually type the following command to trigger the new rules to take effect 
$ sudo udevadm control -R 
$ sudo udevadm trigger --action=remove --attr-match=idVendor=1366 --subsystem-match=usb 
$ sudo udevadm trigger --action=add --attr-match=idVendor=1366 - -subsystem-match=usb

J-Link RTT Viewer

J-Link RTT Viewer is the main Windows GUI application to use all the features of RTT debugging. RTT Viewer can be used alone, open a connection to J-Link, or use in parallel while running a debug session, RTT Viewer supports all RTT main functions:

  • Terminal output of channel 0

  • Input for channel 0

  • Support up to 16 virtual terminals on one target channel

  • Controllable character output: font color control, console message erasure

  • Logging data of channel 1, etc.

For detailed instructions on J-Link RTT Viewer, please refer to the J-Link User Guide Document (

https://wiki.segger.com/UM08001_J-Link_/_J-Trace_User_Guide#RTT)。

Regarding the multiple virtual terminals of J-Link RTT Viewer, the description is still relatively vague, and the corresponding examples are used here to illustrate.

  1. First open the J-Link RTT Viewer tool, and you will be prompted to select the corresponding device to connect. After connecting, you will see the RTT Viewer connected status

  1. Multiple virtual terminals can then be opened in RTT Viewer

  1. Debug log printing in embedded application code

#include "SEGGER_RTT.h" 

int main() 
{ 
    // Initialize RTT 
    SEGGER_RTT_Init(); 
    
    // Enter the main loop 
    while (1) { 
      // Set virtual port 0 and output logs. If not set, Terminal 0 will be used by default 
      SEGGER_RTT_SetTerminal(0); 
      SEGGER_RTT_printf(0, "Hello, SEGGER RTT Terminal 0!\r\n"); 
      // Set virtual port 1 and output log 
      SEGGER_RTT_SetTerminal(1); 
      SEGGER_RTT_printf(0, "Hello, SEGGER RTT Terminal 1 !\r\n"); 
      // Set virtual port 2, and output log 
      SEGGER_RTT_SetTerminal(2); 
      SEGGER_RTT_printf(0, "Hello, SEGGER RTT Terminal 2!\r\n"); 
      Delay_ms(1000); 
      // Other It can output logs with different colors in RTT Viewer, the color definition can refer to SEGGER_RTT.h 
      // The following is the log output in red font
      // SEGGER_RTT_printf(0, RTT_CTRL_TEXT_RED"Hello, SEGGER RTT Terminal 0!\r\n"); 
    } 
}

  1. Run on an embedded device and connect to the computer through J-Link, and view logs of different virtual terminals through the J-Link RTT Viewer tool

 

J-Link RTT Client

J-Link RTT Client is a Telnet Client that will automatically try to reconnect to the J-Link connection when the debugging session is closed. J-Link RTT Client is part of the J-Link software package.

J-Link RTT Logger

With J-Link RTT Logger, data from Up-Channel 1 can be read and recorded to a log file. This Channel can be used to send performance analysis data to the host. J-Link RTT Logger opens a channel to J -Link's dedicated connection that can be used alone without a debug session. This app is also part of the J-Link software package. The command list supported by J-Link RTT Logger is as follows:

03

How RTT works

The implementation of RTT uses the architecture of Control Block, which manages the reading and writing of data through memory on the target embedded system.

注:Up Buffer Descriptors: Target -> Host

Down Buffer Descriptors: Host -> Target

The gray part of the above figure indicates that there is data

The Control Block contains the ID, which is convenient for J-Link to search in the memory. Each available channel (the virtual terminal mentioned above) adopts the Ring Buffer architecture to describe the cache and status of the channel. The maximum number of available channels can be configured, and each Buffer can also be configured. Uplink and downlink Buffers are processed separately. Each channel can be configured as blocking mode or non-blocking mode.

In blocking mode, when the Buffer is full, the application will wait, which will cause the application to block, but ensure that the data will not be lost.

In non-blocking mode, only data that meets the buffer size is written, or no data is written at all, and the rest will be discarded. This method is suitable for real-time running of applications.

When RTT is activated, such as by connecting to an application using J-Link through RTT Viewer, J-Link will automatically search for the SEGGER RTT Control Block in known memory areas of the embedded target system. The specific address of the RAM area or Control Block can also be set by the host application to speed up the detection.

04

RTT performance

The following is a comparison of the rates of RTT, SWO, and Semihosting. The data is based on the actual measurement on STM32F407:

The following is a rate comparison of RTT with different J-Link models (the JTAG rate is different), and the size of the Control Block cache allocated to RTT on the embedded system:

The buffer of the RTT upstream channel can be relatively small, and the required minimum buffer size can be approximated by the amount of data written in one millisecond and the maximum amount of data written in one write operation. If the data is sent infrequently, then the buffer should have enough space to hold the data sent in one write. If data is sent more frequently, the buffer size should be sufficient for the maximum amount of data written in 1 millisecond. The graph below shows the minimum buffer size required when sending different amounts of data, evenly distributed, every 100 us and every 1 ms:

The RTT implementation code requires about 500 bytes of ROM space, and the RAM occupation is related to the number of Buffers in the Control Block, 24-byte ID + 24-byte single channel control block. Each channel requires memory for some buffers. Depending on the I/O load, the recommended size for the upstream channel is 1 kByte, and the recommended size for the downstream channel is 16 to 32 bytes.

05

RTT code implementation

SEGGER RTT code is written in ANSI C for easy integration into any embedded application. RTT can be used through a simple and easy-to-use API. It is even possible to override the standard printf() function to use RTT. Using RTT minimizes the time spent by printf() and allows debugging information to be printed to the host PC while the application is performing time-critical real-time tasks.

The SEGGER RTT implementation includes a simple implementation of printf() that can be used to write formatted strings over RTT. SEGGER_RTT_Printf() is smaller than most standard library printf implementations, and requires no heap, only a configurable amount of stack. By using Lock() and Unlock() to make reading and writing thread-safe, the number of buffers and the size of the terminal buffer can be set. The following are the interface functions provided by RTT for embedded integration:

References:

https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer/

https://wiki.segger.com/UM08001_J-Link_/_J-Trace_User_Guide#RTT

https://wiki.segger.com/RTT

Guess you like

Origin blog.csdn.net/suxiang198/article/details/126534730