Home | Projects | Notes > Real-Time Operating Systems (RTOS) > SEGGER SystemView (Trace Tool) Integration

SEGGER SystemView (Trace Tool) Integration

 

SEGGER SystemView Download

Download the following tools from https://www.segger.com/

  1. SEGGER SystemView Software (host software) - V3.20

  2. SEGGER SystemView target source files (need to be integrated into our project and flashed to target) - V3.20

  3. SEGGER ST-Link Reflash untility (NOT used at this point)

  4. SEGGER J-Link software package V5.12b or later (NOT used at this point)

    • This is required to be able to use (3).

  5. SystemView user manual

 

SEGGER SystemView

 

segger-systemview-toolkit

 

SystemView Visualization Modes

  1. Real-time recording (Continuous recording)

    With a SEGGER J-Link and its Real-Time Transfer (RTT) technology SystemView can continuously record data and transfer them to the host so that we can analyze and visualize them in real-time.

    Real-time mode can be achieved via ST-Link instead of J-Link. To do that J-Link firmware has to be flashed on ST-Link circuitry of STM32 boards. More on this later.

    Application (main.c), RTOS (FreeRTOS), we need to include SystemView API and RTT API, RTT Buffer is an array that the events to be transferred get stored.

     

    systemview-realtime-recording

     

  2. Single-shot recording

    No J-Link or ST-Link debugger is required. When no J-Link is used, SEGGER SystemView can be used to record data until its target buffer is filled.

    In Single-shot mode the recording is started manually in the application, which allows recording only specific parts of our interest. The events will fill up the RTT Buffer in RAM, and at some point we can stop recording and dump the contents of the buffer to a file (.SVDat) to analyze them on the host PC.

     

    systemview-singleshot-recording

     

SystemView Window

systemview-window

 

 

SystemView Integration

  1. Add SEGGER SystemView target sources to the project.

    • Download SystemView target sources and extract it.

    • Create Project/ThirdParty/SEGGER folder and add to it Config/, OS/, Patch/, and SEGGER/ folders and import the following files from the downloaded target source folder. Make sure that Project/ThirdParty/SEGGER is not excluded from the build.

      • SEGGER_SYSVIEW_Config_FreeRTOS.c is located in the <Repository>/Downloads/SystemView_Src_V320/Sample/FreeRTOSV10/Config/Cortex-M/ directory.

      • SEGGER_SYSVIEW_FreeRTOS.c is located in the <Repository>/Downloads/SystemView_Src_V320/Sample/FreeRTOSV10/ directory.

      • FreeRTOSv202012.00_segger_cm4_v1.patch is provided by the lecture.

      • Copy all the contents inside the /Download/SystemView_Src_V320/SEGGER/ directory into Project/ThirdParty/SEGGER/SEGGER/ directory.

    • Inside the SEGGER/Syscalls/ directory, delete everything but GCC related file (SEGGER_RTT_Syscalls_GCC.c).

     

    segger-folder-setup

     

    • Update the "Include paths" so that the IDE can locate SEGGER include files.

  2. Patch FreeRTOS files

    • The patch file FreeRTOSv202012.00_segger_cm4_v1.patch contains the SEGGER trace tool related patches to the FreeRTOS source files. Now, we have to apply this patch to the FreeRTOS source files.

      ThirdParty Right click Team Apply patch Workspace Select the patch file Next ... Finish

       

      apply-patch

       

  3. FreeRTOSConfig.h settings

    • SEGGER_SYSVIEW_FreeRTOS.h header must be included at the end of FreeRTOSConfig.h file, or above every include of FreeRTOS.h. It defines the trace macros to create SYSTEMVIEW events.

    • In FreeRTOSConfig.h include the following macros:

      Enables code blocks in the real-time kernel to include these functionalities which are required by the SEGGER. If these are set to 0, then the FreeRTOS build will not contain the source code related to these functionalities.

  4. MCU and project specific settings

    • Specify the processor core your MCU is using in Project/ThirdParty/SEGGER/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h.

      L43: Set SEGGER_SYSVIEW_CORE to SEGGER_SYSVIEW_CORE_CM3.

    • Do SystemView buffer size configuration in SEGGER_SYSVIEW_ConfDefaults.h. (SEGGER_SYSVIEW_RTT_BUFFER_SIZE). This is the RTT Buffer in RAM used to collect and keep all the events to transfer to the host software. Set the buffer size according to your application's needs.

      1KB by default but, we'll make it 4 KB.

    • Configure the some of the application specific information in SEGGER_SYSVIEW_Config_FreeRTOS.c under /Project/ThirdParty/SEGGER/Config/.

      Just modify the values of the already existing macros.

  5. Enable the ARM Cortex-M3/M4 cycle counter

    • This is required to maintain the time stamp information of the target events in the host application. SystemView will use the cycle counter register value to keep the time stamp information of the events.

    • DWT_CYCCNT register of ARM Cortex-M3/M4 processor stores the number of clock cycles that has passed after the processor's reset. (DWT_CYCCNT gets incremented every clock cycle.)

      • DWT: Data Watchpoint Unit of the processor

    • By default, this register is disabled since not all processors use it.

    • Consult Cortex-M4 Technical Reference Manual to see how to enable this register. (Section "DWT Programmer Model")

      To enable DWT_CYCCNT register, you need to set SYCCNTENA (bit[0]; Cycle Counter Enable) of DWT_CTRL register.

  6. Start the recording of events

    • To start the recordings of your FreeRTOS application, call the following SEGGER APIs:

      • SEGGER_SYSVIEW_Conf(); - configures SEGGER target sources

      • SEGGER_SYSVIEW_Start(); - starts the recording

        (SEGGER_SYSVIEW_Stop(); - stops the recording)

      The SEGGER SystemView events recording starts only when SEGGER_SYSVIEW_Start() is called. This is called from main.c before calling any other FreeRTOS APIs.

  7. Compile and debug

    • Make sure that you've updated the Include paths.

       

      segger-include-paths

      segger-include-paths-assembler

       

    • Compile and flash your FreeRTOS + SystemView application.

      Check the following before building your project:

      Set to use preemption.

      Comment out taskYIELD()s.

    • Go to debugging mode using your IDE.

    • Hit run and then pause after a couple of seconds.

      At this step, there was a problem related to "Priority grouping". To solve this issue add the following code in the Project/Core/Src/stm32f4xx_hal_msp.c:

      Actually initialization of this variable is done in the scheduler (vTaskStartScheduler()) function, but in our main.c code, SEGGER_SYSVIEW_Start() which requires the initialization of this variable comes before the invocation of vTaskStartScheduler() and this is why we have to do this modification.

    • From the previous step, we have collected some events in the RTT Buffer.

  8. Collect the recorded data (RTT Buffer)

    You can do this via continuous recording or single-shot recording.

    • Single-shot recording:

      • Get the SystemView RTT buffer address and the number of bytes used. (Normally _SEGGER_RTT.aUp[1].pBuffer and _SEGGER_RTT.aUp[1].WrOff). User Expressions window, type in _SEGGER_RTT to search these.

         

        segger-rtt-expressions

        [!] Note: Copy the pBuffer address 0x200133e4, and look it up in the Memory Browser.

         

      • Take the memory dump to a file.

         

        exporting-memory

         

      • Save the file with the .SVdat extension and "Raw Binary" format.

      • Use the file to load into SystemView host software to analyze the events.

         

        systemview-file-loading

 

 

Note

 

 

References

Nayak, K. (2022). Mastering RTOS: Hands on FreeRTOS and STM32Fx with Debugging [Video file]. Retrieved from https://www.udemy.com/course/mastering-rtos-hands-on-with-freertos-arduino-and-stm32fx/