SystemView

Note

This article mainly introduces the SystemView visual analysis tool and how to use it to debug and analyze the system on RT-Thread.

As MCU performance becomes stronger and stronger, the functions of embedded products become more and more complex, which poses new challenges to system debugging and analysis. Debugging a function or problem usually requires a lot of effort. SystemView is a powerful tool to help users debug and analyze the system, which can significantly shorten the development and debugging time and improve development efficiency. The purpose of this article is to help you use the SystemView tool on RT-Thread to debug and analyze the system.

The materials prepared for this article are as follows:

SystemView is a tool for online debugging of embedded systems. It can analyze which interrupts and tasks have been executed, as well as the order of execution of these interrupts and tasks. It can also view the time points when some kernel objects are held and released, such as semaphores, mutexes, events, message queues, etc. This is especially effective when developing and processing complex systems with multiple threads and events.

SystemView consists of two parts:

  • The PC program collects and displays the data from the embedded end, and can also save the data locally for later analysis.

  • Embedded program collects the operating data of the embedded system and transmits them to the PC through the RTT module of J-Link

Note

Because SystemView uses J-Link's RTT technology for data transmission, SystemView can only be used when the development board is connected with J-Link.

The SystemView software package provided by RT-Thread is the embedded end program implementation of the SystemView tool. Its main functions include: configuring the specific parameters of SYSTEMVIEW and RTT, collecting and formatting monitoring data, and sending the data to the PC through J-Link, etc. You only need to use the Env tool launched by RT-Thread to enable the SystemView software package and perform simple configuration on it to complete the configuration of the embedded end program of SystemView.

Take the Zhengdian Atom RT1052 development board as an example

Step 1: Enter the menuconfig graphical configuration tool in the Env tool

Open the Env tool, use the command cd D:\rt-thread\bsp\imxrt1052-evkto switch to the imxrt1052-evk directory in the root directory of the RT-Thread source code BSP, and then enter the command menuconfigto configure the project.

Note

menuconfig is a graphical configuration tool that RT-Thread uses to configure and tailor the entire system.

Step 2: Enable the SystemView software package.

Use the up and down keys to select RT-Thread online packages, press Enter to enter the sub-menu, and then open SystemView in tools packages.

Step 3: Specific configuration.

Press the Enter key to enter the sub-menu and make specific configurations (enter? to display specific information of the options).

The following are two commonly used options. Other options can be configured as needed (refer to the last part of the parameter directory):

(1) Change the option circled in red in the figure below to the kernel corresponding to your development board, such as the M7 kernel for i.MX-RT1052

(2) Enter the SystemView buffer configuration submenu and turn off post-analysis mode

After enabling post-analysis mode, you need to call the function SEGGER_SYSVIEW_Start() in the project to start recording. System events will be continuously recorded and old events will be overwritten when the buffer is full. Therefore, when reading the buffer, only the latest events can be read.

Note

Post-mortem analysis can be useful when a system has been running for a long time and suddenly crashes. In this case, the most recent events can be read from the buffer in the target and SystemView can show what happened just before the system crashed.

After turning off the post-analysis mode, you will be in continuous recording mode. You can control the start and end of recording on the PC to continuously record the operation of the system. To analyze the operation of the following demo, you need to turn on the continuous recording mode.

After configuring the options, press ESC to return, exit and save the configuration. The enabling and related configuration of the SystemView software package is now complete.

Later we will use a specific demo to explain the use of the SystemView tool

Add the following code to the file main.c, and then call the demo initialization function in the main function demo_init();to run the demo.

/*
* 程序清单:systemview 演示代码
*
* 这个例子中将创建一个动态信号量(初始值为0)及两个动态线程,在这个两个动态线程中
* 线程2将试图采用永远等待方式去持有信号量,持有成功之后发送运行标志。
* 线程1将先发送正在运行标志,然后释放一次信号量,因线程2的优先级较高,线程2持有到信号量将线程1抢断。
* 然后线程2发送运行标志之后,获取不到信号量,被挂起,线程1继续运行
*/

#define THREAD_PRIORITY         25
#define THREAD_STACK_SIZE       512
#define THREAD_TIMESLICE        5
/* 指向信号量的指针 */
rt_sem_t sem_food;
/* 线程1入口 */
void thread1_entry(void* parameter)
{
    while (1)
    {
        /* 线程1第一次运行 */
        rt_kprintf("thread1 is run!\n");
        /* 释放一次信号量 */
        rt_sem_release(sem_food);
        /* 线程1第二次运行 */
        rt_kprintf("thread1 run again!\n");
        /* 线程1延时1秒 */
        rt_thread_delay(RT_TICK_PER_SECOND);
    }
}
/* 线程2入口 */
void thread2_entry(void* parameter)
{
    while (1)
    {
        /* 试图持有信号量,并永远等待直到持有到信号量 */
        rt_sem_take(sem_food, RT_WAITING_FOREVER);
        /* 线程2正在运行 */
        rt_kprintf("thread2 is run!\n");
    }
}
/* DEMO初始化函数 */
void demo_init(void)
{
    /* 指向线程控制块的指针 */
    rt_thread_t thread1_id, thread2_id;
    /* 创建一个信号量,初始值是0 */
    sem_food = rt_sem_create("sem_food", 0, RT_IPC_FLAG_PRIO);
    if (sem_food == RT_NULL)
    {
        rt_kprintf("sem created fail!\n");
        return ;
    }
    /* 创建线程1 */
    thread1_id = rt_thread_create("thread1",
                    thread1_entry, RT_NULL,/* 线程入口是thread1_entry, 参数RT_NULL */
                    THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
    if (thread1_id != RT_NULL)
        rt_thread_startup(thread1_id);
    /* 创建线程2 */
    thread2_id = rt_thread_create("thread2",
                    thread2_entry, RT_NULL,/* 线程入口是thread2_entry, 参数RT_NULL */
                    THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
    if (thread2_id != RT_NULL)
        rt_thread_startup(thread2_id);
}copymistakeCopy Success

Step 1: Download SystemView analysis tool download link

Step 2: Add a system description file for RT-Thread

First, find the packages directory under the development board directory, and then find the segger_debug-xxx directory under the packages directory. There is a SystemView_Description folder in this directory, and the description file of the RT-Thread system is in it. The specific directory structure is as follows:

bsp\\你自己的开发板\\packages\\segger_debug-xxx\\SystemView_Description\\SYSVIEW_RT-Thread.txt

Copy this file to the Description directory under the SystemView tool installation directory so that SystemView can recognize the RT-Thread system.

Step 3: Configure device information and start recording

Double-click to open the SystemView PC program. Below is an introduction to the functions of some commonly used buttons on the main interface.

When in continuous recording mode, click the Start Recording button and a window will pop up to configure the device information.

The address of the RTT control block in the figure has been printed out through the serial port. Just open the terminal software and copy the printed address above.

Click OK. Now SystemView starts recording system information in real time. Below is the real-time operation status of the system.

Step 4: End recording and analyze the system

Click the End Recording button to end the recording. Place the mouse in the timeline window and use the scroll wheel to zoom in on the event to a size suitable for analysis.

Using the SystemView tool, we can see that the system is running as we expected. Thread 1 starts running first, and then is interrupted by Thread 2 after releasing the semaphore. Thread 2 then runs, and then is suspended because it cannot obtain the semaphore, and Thread 1 continues to run. From the above event list, we can also see the specific time when each thread obtains or releases the semaphore.

Note

If the post-analysis mode is turned on, you cannot click the Start Recording button. Instead, you need to click the Read Recorded Data button. Other operations are the same as in the real-time analysis mode.

After reading this document, I believe you have learned how to use the SystemView analysis tool on RT-Thread.

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