SEGGER_RTT

  • During development, jlink's hardware debugger is often used for debugging ( ST-LINK 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.

The SEGGER_RTT software package is developed based on SEGGER's J-Link RTTJ-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 Transferthe abbreviation of .

The working principle of SEGGER_RTT is shown in the following figure:

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

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

  1. It should be noted that after selecting the software package, drv_rtt.c is equivalent to adding a serial device similar to UART, namedjlinkRtt

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 Objectshould also be set tojlinkRtt

#define RT_CONSOLE_DEVICE_NAME "jlinkRtt"
rt_hw_jlink_rtt_init();
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);copymistakeCopy Success
  1. Install a set of JLINK tools. After installation, open J-Link RTT Viewerthe tool and make the following settings to select the corresponding device.

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

  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. Of course, after flashing it to JLINK, your JLINK can only operate STM32 authorized devices, and devices from other manufacturers are not supported.

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 and SEGGER_RTT TOOL .

This software package refers to the SystemView software package , as well as some guidance and suggestions from BLE community partners.

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University