What Is Jlink RTT and Why Use It?

Produced by 21ic Forum xyz549040622

Website: bbs.21ic.com

1. What is Jlink RTT? The full name is SEGGER’s Real-Time Transfer (RTT), a technology based on SEGGER’s JLink debugger for interactive user I/O. As the name suggests, it is a technology that interacts with the user based on JLink, which can intuitively display information from the debug chip and allow users to interact with the debug chip. 2. Why use Jlink RTT? 1> No additional pins or hardware configuration are required, supporting SWD mode, and can be used with just two wires. 2> Fast speed, can be used in parallel with debug and run, with an average output of one line of text in one microsecond or less. The official has provided a speed comparison chart.What Is Jlink RTT and Why Use It?3> Communication via RTT can be accomplished through different applications, can be integrated into custom applications using SDK, and can be connected locally or remotely. Based on these three advantages, if you are still foolishly using USART for user interaction when debugging ARM chips, that is indeed very inefficient. 3. Preparation for using Jlink RTT 1> Jlink software packagehttps://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPackWhat Is Jlink RTT and Why Use It?2> One Jlink emulator; I couldn’t find which version of the Jlink officially starts supporting RTT, but I saw online that V9 is supported. I am using Jlink V11 emulator here. HW: V11.00 dll: V6.98c 4. Porting RTT SDK code to MDK work 1> Find the RTT SDK package in the installation path of the Jlink software; I installed it on drive D. D:\Program Files (x86)\SEGGER\JLink\Samples\RTT\RTTWhat Is Jlink RTT and Why Use It?2> Create a new RTT folder under the MDK project, copy the following four files to the RTT directory, and add these files to the MDK project.What Is Jlink RTT and Why Use It?Add the code to the projectWhat Is Jlink RTT and Why Use It?Header file includesWhat Is Jlink RTT and Why Use It?5. Three software that support RTT Jlink provides three software: RTT Viewer, RTT Client, and RTT Logger. These three software can be found in the SEGGER directory:What Is Jlink RTT and Why Use It?6. Some concepts to understand before using RTT. Using RTT requires understanding two concepts, namely channel and terminal. Here I have only provided an explanation based on my current understanding, which may not be appropriate. Since there is no detailed explanation of the internal operating mechanism of RTT, I understand channel and terminals as software concepts. The RTT SDK defaults to support 2 channels, namely 0 and 1. Each channel supports 16 terminals, respectively 0-F. Based on these two concepts, I have created a comparison table for the three software: RTT Viewer, RTT Client, and RTT Logger. Understanding the table below will help you better use and configure RTT.What Is Jlink RTT and Why Use It?

192066059fc21abc0a.png (19.17 KB, download times: 0)

Download attachment Save to album

Uploaded on 2021-3-23 22:33

7. Code writing in MDK 1> Header file reference #include “SEGGER_RTT.h” 2> RTT initialization function SEGGER_RTT_Init(); The above two items are common code, and below is the use of channel 0 to output a segment of debugging information using RTT Viewer and RTT Client.

/**********************************************************************************************************                                                Main program*********************************************************************************************************/int main (void)                                                                                 {

  FLASH_ReadOutProtection(DISABLE);                                   //Read protection

    SystemInit();                                                                            //CPU clock initialization    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);        //Use priority group 4 (4:4 structure)
    SEGGER_RTT_Init();   
    #ifdef DEBUG_MODE                                                        //Debug mode    SEGGER_RTT_printf(0,"Demo Init!\r\n");    #endif   

while(1){        SEGGER_RTT_SetTerminal(0);             SEGGER_RTT_printf(0,"Demo Run Terminal 0!\r\n");           SEGGER_RTT_SetTerminal(1);             SEGGER_RTT_printf(0,"Demo Run Terminal 1!\r\n");         }


  return (0);}
The above code outputs debugging information using terminal 0 of channel 0. The parameters of channel 0 have been configured in the RTT SDK by default, so when we use channel 0, we can directly use the print function. The above code compiles without errors after editing, and then downloads. After opening RTT Viewer, it displays as follows, and after configuring the parameters according to the actual situation, click OK.What Is Jlink RTT and Why Use It?You can see that the control window has output debugging information. The number before > is the current terminal ID being used.What Is Jlink RTT and Why Use It?After opening RTT Client, it displays as follows:What Is Jlink RTT and Why Use It?At this point, you will find that there is no data output. Don’t worry, the key point is coming. 1) First close RTT Client and click the Debug button in MDK to enter Debug mode.What Is Jlink RTT and Why Use It?2) Reopen RTT Client, it displays as follows:What Is Jlink RTT and Why Use It?3) Click MDK’s Run to run at full speed. The console starts to output debugging information.What Is Jlink RTT and Why Use It?Next, continue using channel 1 to output debugging information in the log file using RTT Logger. Since RTT Logger uses channel 1, the RTT SDK does not allocate a buffer and name for channel 1, and manual settings must be made. Also, note that channels 0 and 1 are parallel, and the output debugging information from both does not conflict. The code for using channel 1 is as follows:
uint8_t _UpBufferCH1[64] = {0};uint8_t _DownBufferCH1[64] = {0};

/**********************************************************************************************************                                                Main program*********************************************************************************************************/int main (void)                                                                                 {

  FLASH_ReadOutProtection(DISABLE);                                   //Read protection

    SystemInit();                                                                            //CPU clock initialization    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);        //Use priority group 4 (4:4 structure)
    SEGGER_RTT_Init();   

    /* Configure channel 1, uplink configuration (STM32->RTT Viewer software) */    SEGGER_RTT_ConfigUpBuffer(1, "RTTUP", _UpBufferCH1, 64, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
    /* Configure channel 1, downlink configuration (RTT Viewer software->STM32) */       SEGGER_RTT_ConfigDownBuffer(1, "RTTDOWN", _DownBufferCH1, 64, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
    #ifdef DEBUG_MODE                                                        //Debug mode    SEGGER_RTT_printf(0,"Demo Init!\r\n");    #endif   

while(1){        SEGGER_RTT_SetTerminal(0);             SEGGER_RTT_printf(1,"Demo Run Terminal 0!\r\n");           SEGGER_RTT_SetTerminal(1);             SEGGER_RTT_printf(1,"Demo Run Terminal 1!\r\n");         }


  return (0);}
The above code compiles without errors after editing, and then downloads. After opening RTT Logger, it displays as follows:What Is Jlink RTT and Why Use It?Here it should be noted that in RTT Logger, you can freely input the parameters indicated after > and confirm by pressing the Enter key. Without input, press the Enter key to skip.
Continuously pressing the Enter key, if the program is correctly configured for channel 1, the following image will appear, continuously writing data to the log file.
Note: If the program does not configure channel 1, RTT Logger will automatically close if it does not detect channel 1.
The correct display screen of RTT Logger is as follows:What Is Jlink RTT and Why Use It?Open the .log file in the above path, and the content is as follows, which indicates that the log file has been successfully generated.What Is Jlink RTT and Why Use It?As long as you understand the above content, you can smoothly use RTT to output debugging information. Generally, we only need to use the RTT Viewer software. It can also set display colors, format output, etc. The specific function descriptions can be found in the user manual in section 16.4.1 of the Jlink installation directory. The manual path is as follows: D:\Program Files (x86)\SEGGER\JLink\Doc\Manuals.What Is Jlink RTT and Why Use It?
This article is original by 21ic forum user xyz549040622. Please click “Read Original” to download the materials.
Copyright belongs to the original author. If there is any infringement, please contact to delete.

Leave a Comment