# SEGGER\_RTT

### [Target audience of this article](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/segger_rtt?id=%e6%9c%ac%e6%96%87%e7%9b%ae%e6%a0%87%e4%ba%ba%e7%be%a4) <a href="#ben-wen-mu-biao-ren-qun" id="ben-wen-mu-biao-ren-qun"></a>

* During development, jlink's hardware debugger is often used for debugging ( [ST-LINK](https://www.rt-thread.org/document/site/\[https://www.segger.com/jlink-st-link.html]\(https://www.segger.com/jlink-st-link.html%EF%BC%89\)) can also be flashed to JLINK).
* Sometimes you want to print some information in an interrupt, but printf cannot print in an interrupt.
* In the early stage of porting RT-Thread, the UART driver was not fully ready, and I wanted to use rt\_kprintf for printing.
* The MCU being developed does not want the console to monopolize one UART.

### [Introduction](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/segger_rtt?id=%e7%ae%80%e4%bb%8b) <a href="#jian-jie" id="jian-jie"></a>

[The SEGGER\_RTT](https://github.com/supperthomas/RTTHREAD_SEGGER_TOOL.git) software package is developed based on SEGGER's [J-Link RTT](https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer/)`J-Link RTT` . It transmits the console port of RT-Thread through , so as to achieve a more convenient interaction through the console port, which can be completely used to replace the UART port. Here RTT is `Real Time Transfer`the abbreviation of .

The working principle of SEGGER\_RTT is shown in the following figure:

![jlink](https://www.rt-thread.org/document/site/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/images/jlink.png)

J-LINK can query the value of a specific variable by querying the variable. The SEGGER\_RTT tool also uses this principle.

The features of the SEGGER\_RTT package are summarized as follows:

* Can print in interrupt
* Can cache boot log
* Can receive finsh commands
* Multi-platform support
* Independent of the operating system, a single bare metal machine can run SEGGER\_printf
* Can support the use of multiple terminal ports and print different logs
* Can be used directly without initialization

### [How to use](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/segger_rtt?id=%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8) <a href="#ru-he-shi-yong" id="ru-he-shi-yong"></a>

1. Select the corresponding software package in menuconfig to download the software package

![menuconfig](https://www.rt-thread.org/document/site/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/images/menuconfig.png)

2. It should be noted that after selecting the software package, drv\_rtt.c is equivalent to adding a serial device similar to UART, named`jlinkRtt`

If you want to replace it with the console port, you need to find the following two codes and modify them:

* rt\_hw\_jlink\_rtt\_init must `rt_console_set_device(RT_CONSOLE_DEVICE_NAME);`be called before initialization
* The console in menuconfig `RT-Thread Kernel → Kernel Device Object`should also be set to`jlinkRtt`

```
#define RT_CONSOLE_DEVICE_NAME "jlinkRtt"
rt_hw_jlink_rtt_init();
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);copymistakeCopy Success
```

3. Install a set of [JLINK](https://www.segger.com/downloads/jlink/) tools. After installation, open `J-Link RTT Viewer`the tool and make the following settings to select the corresponding device.

![RTT\_Viewer](https://www.rt-thread.org/document/site/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/images/RTT_Viewer.png)

What needs to be noted here is the option at the bottom, which refers to the address of the variable &\_SEGGER\_RTT in the code. Some chips support automatic address recognition, while some chips do not. You can view the address of the variable through debug, or you can set the RAM search range according to your MCU to let JLINK poll the address in RAM. For example, STM32 can set the RAM address search range

```
0x20000000 0x1000copymistakeCopy Success
```

### [Operation effect](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/segger_rtt?id=%e8%bf%90%e8%a1%8c%e6%95%88%e6%9e%9c) <a href="#yun-xing-xiao-guo" id="yun-xing-xiao-guo"></a>

![seggerRTT\_console](https://www.rt-thread.org/document/site/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/images/seggerRTT_console.png)

### [Precautions](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/segger_rtt?id=%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9) <a href="#zhu-yi-shi-xiang" id="zhu-yi-shi-xiang"></a>

1. You need a JLINK connection. It can be used for testing on STM32 or Nordic development boards. Other JLINKs should also be universal, which saves the occupation of the debugging UART serial port. You can use this port to print logs or console debugging.
2. As long as your development board can use JLINK to debug and view variables, you can use this package. RTT is essentially just polling the global variable \_SEGGER\_RTT. So it is not particularly sensitive to the architecture, as long as your board can be debugged with JLINK.
3. If you have STLINK, you can choose to flash it to JLINK. Reference connection [segger st-link.](https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/) Of course, after flashing it to JLINK, your JLINK can only operate STM32 authorized devices, and devices from other manufacturers are not supported.

### [Summarize](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/segger_rtt?id=%e6%80%bb%e7%bb%93) <a href="#zong-jie" id="zong-jie"></a>

I think that when developing a chip that can be debugged with JLINK, it is a relatively quick thing to use console debugging through segger\_rtt in the early stage. For example, when making a new BSP, you can first use the RTT method for console debugging. Similarly, this kind of console can print the corresponding log in the interrupt, which is also a relatively convenient thing. In short, I feel that there are still many places where it is needed, so I recommend it to everyone. Of course, the functions of SEGGER\_RTT are not limited to this. In fact, there are still many functions that have not been fully developed, such as some color printing and terminal multiplexing. You are welcome to give comments and requirements on the software package. If you have any suggestions, you can mention them in the issue of the software package. If you are interested in the SEGGER\_RTT software package, you can refer to [SEGGER\_RTT Exploration](https://supperthomas-wiki.readthedocs.io/en/latest/DEBUG/01_SEGGER_RTT/SEGGER_RTT.html#id1) and [SEGGER\_RTT TOOL](https://github.com/supperthomas/RTTHREAD_SEGGER_TOOL) .

### [Special Thanks](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/application-note/debug/seggerRTT/segger_rtt?id=%e7%89%b9%e5%88%ab%e6%84%9f%e8%b0%a2) <a href="#te-bie-gan-xie" id="te-bie-gan-xie"></a>

This software package refers to the [SystemView](https://github.com/RT-Thread-packages/SEGGER_SystemView) software package , as well as some guidance and suggestions from BLE community partners.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/recommended_by_aic/rt-thread-university-program/components/software-packages/tools/segger_rtt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
