UM08027 SystemView PDF
UM08027 SystemView PDF
SystemView
User Guide
Document: UM08027
Software Version: 2.36
Revision: 0
Date: May 24, 2016
www.segger.com
Disclaimer
Specifications written in this document are believed to be accurate, but are not guaranteed
to be entirely free of error. The information in this manual is subject to change for
functional or performance improvements without notice. Please make sure your manual
is the latest edition. While the information herein is assumed to be accurate, SEGGER
Microcontroller GmbH & Co. KG (SEGGER) assumes no responsibility for any errors or
omissions. SEGGER makes and you receive no warranties or conditions, express, implied,
statutory or in any communication with you. SEGGER specifically disclaims any implied
warranty of merchantability or fitness for a particular purpose.
Copyright notice
You may not extract portions of this manual or modify the PDF file in any way without the
prior written permission of SEGGER. The software described in this document is furnished
under a license and may only be used or copied in accordance with the terms of such a
license.
2016 SEGGER Microcontroller GmbH & Co. KG, Hilden / Germany
Trademarks
Names mentioned in this manual may be trademarks of their respective companies.
Brand and product names are trademarks or registered trademarks of their respective
holders.
Contact address
SEGGER Microcontroller GmbH & Co. KG
In den Weiden 11
D-40721 Hilden
Germany
Tel.
Fax.
E-mail:
Internet:
+49 2103-2878-0
+49 2103-2878-28
support@segger.com
www.segger.com
Manual versions
This manual describes the current software version. If you find an error in the manual or a
problem in the software, please inform us and we will try to assist you as soon as possible.
Contact us for further information on topics or functions that are not yet documented.
Print date: May 24, 2016
Software Revision
Date
By
2.34
160524
JL
2.34
160401
JL
2.32
160322
JL
2.32
160310
JL
2.30
160127
JL
Description
Section
Section
Section
Section
Section
Section
Section
added.
Section
Section
Section
2.28
160114
JL
2.26
160106
JL
2.26
151223
JL
2.24
151216
JL
2.22
151214
JL
2.20
151119
JL
Screenshots updated.
Fixed defines in configuration.
2.20
151118
JL
2.10
151106
JL
2.09
151026
JL
Official Release.
Initial Pre-Release.
Assumptions
This document assumes that you already have a solid knowledge of the following:
The software tools used for building your application (assembler, linker, C compiler).
The C programming language.
The target processor.
DOS command line.
If you feel that your knowledge of C is not sufficient, we recommend The C Programming
Language by Kernighan and Richie (ISBN 0131103628), which describes the standard in C
programming and, in newer editions, also covers the ANSI C standard.
Used for
Body
Body text.
Keyword
Parameter
Sample
Sample comment
Reference
GUIElement
Emphasis
Table of contents
Overview .......................................................................................................................11
1.1
1.2
Introduction ..................................................................................................26
Timeline window ........................................................................................... 27
Events window ..............................................................................................28
Terminal Window ...........................................................................................29
CPU Load window ......................................................................................... 30
Contexts window ...........................................................................................31
System information ....................................................................................... 32
GUI controls ................................................................................................. 33
Prerequisites .................................................................................................44
5.1.1 SEGGER SystemView target implementation modules ............................. 44
Including SEGGER SystemView in the application .............................................. 45
Initializing SystemView .................................................................................. 46
Start and stop recording ................................................................................ 47
5.5
6.2
6.3
7.2
7.3
7.4
embOS .................................................................................................84
8.1.1 Configuring embOS for SystemView .............................................. 84
uC/OS-III ............................................................................................. 85
8.2.1 Configuring uC/OS-III for SystemView .......................................... 85
8.3
8.4
8.5
10
FreeRTOS ..................................................................................................... 86
8.3.1 Configuring FreeRTOS for SystemView .................................................. 86
Other OSes .................................................................................................. 87
No OS ......................................................................................................... 88
8.5.1 Configuring a system for SystemView ................................................... 88
11
10
11.1.18
11.1.19
11.1.20
11.1.21
11.1.22
11.1.23
11.1.24
11.1.25
11.1.26
11.1.27
11.1.28
11.1.29
11.1.30
11.1.31
11.1.32
11.1.33
11.1.34
11.1.35
11.1.36
11.1.37
11.1.38
11.1.39
11.1.40
11.1.41
11.1.42
11.1.43
11.1.44
11.1.45
11.1.46
11.1.47
11.1.48
11.1.49
11.1.50
11.1.51
11.1.52
11.1.53
12
11
Chapter 1
Overview
12
1.1
CHAPTER 1
13
On systems which are not supported by the RTT technology the buffer content can be read
manually when the system is halted, which allows single-shot recording until the buffer is
filled and post-mortem analysis to capture the latest recorded data. Single-shot and postmortem recording can be triggered by the system to be able to control when a recording
starts and stops.
14
CHAPTER 1
1.2
1.2.1
The SEGGER SystemView package is available for Windows, OS X and Linux as an installer
setup and a portable archive.
Download the latest package for your operation system from https://www.segger.com/
systemview.html.
In order to do live recording the current J-Link Software and Documentation Package needs
to be installed. Download and instructions are available at https://www.segger.com/jlinksoftware.html.
1.2.1.1 Windows
Installer
Download the latest setup from http://www.segger.com/systemview.html and execute it.
The setup wizard guides through the installation.
After installation the package content can be accessed through the Windows Start menu
or from the file explorer.
Portable zip
Download the latest zip from http://www.segger.com/systemview.html and extract it to any
directory on the file system.
No installation is required, after extraction the package content can be used directly.
1.2.1.2 OS X
Installation package
Download the latest pkg installer from http://www.segger.com/systemview.html and
execute it. The package installer guides through the installation.
After installation SystemViewer can be accessed through Launchpad.
Portable image
Download the latest dmg image from http://www.segger.com/systemview.html and copy
its content to any directory on the file system.
No installation is required, the package content can be used directly.
1.2.1.3 Linux
Requirements
To run SystemViewer on Linux the Qt V4.8 libraries have to be installed on the system.
Installer
Download the latest DEB or RPM installer for your Linux from http://www.segger.com/
systemview.html and execute it. The software installer guides through the installation.
Portable zip
Download the latest archive for your Linux from http://www.segger.com/systemview.html
and extract it to any directory on the file system.
No installation is required, after extraction the package content can be used directly.
15
1.2.2
Package content
The SEGGER SystemView package includes everything needed for application tracing the
host PC visualization tool SystemViewer and sample trace files for a quick and easy start.
The target sources to be included in the embedded application can be downloaded as an
additional package.
Additional sources to interface with SEGGER software, such as embOS are included for a
quick and easy start.
The following table lists the software package content.
SystemView package
File
Description
./SystemViewer.exe
./Doc/UM08027_SystemView.pdf
This documentation.
./Description/SYSVIEW_embOS.txt
./Description/SYSVIEW_FreeRTOS.txt
./Sample/OS_IP_WebServer.SVDat
./Sample/OS_Start_LEDBlink.SVDat
./Sample/uCOS_Start.SVDat
Description
./Src/Config/Global.h
./Src/Config/SEGGER_RTT_Conf.h
./Src/Config/SEGGER_SYSVIEW_Conf.h
./Src/Sample/Config/
SEGGER_SYSVIEW_Config_embOS.c
./Src/Sample/Config/
SEGGER_SYSVIEW_Config_embOS_CM0.c
./Src/Sample/Config/
SEGGER_SYSVIEW_Config_FreeRTOS.c
./Src/Sample/Config/
SEGGER_SYSVIEW_Config_NoOS.c
./Src/Sample/Config/
SEGGER_SYSVIEW_Config_uCOSIII.c
./Src/Sample/Config/os_cfg_trace.h
./Src/Sample/OS/
SEGGER_SYSVIEW_embOS.c
./Src/Sample/OS/
SEGGER_SYSVIEW_embOS.h
Interface header.
./Src/Sample/OS/
SEGGER_SYSVIEW_FreeRTOS.c
16
CHAPTER 1
File
Description
./Src/Sample/OS/
SEGGER_SYSVIEW_FreeRTOS.h
Interface header.
./Src/Sample/OS/os_trace.h
./Src/Sample/OS/
SEGGER_SYSVIEW_uCOSIII.c
./Src/Sample/Patch/
FreeRTOSV8.2.3_Core.patch
./Src/SEGGER/SEGGER.h
./Src/SEGGER/SEGGER_RTT.c
./Src/SEGGER/SEGGER_RTT.h
./Src/SEGGER/SEGGER_SYSVIEW.c
./Src/SEGGER/SEGGER_SYSVIEW.h
./Src/SEGGER/
SEGGER_SYSVIEW_ConfDefault.h
./Src/SEGGER/SEGGER_SYSVIEW_Int.h
17
Chapter 2
Getting started with SEGGER
SystemView
This section describes how to get started with SEGGER SystemView. It explains how to analyze
an application based on monitored data.
This chapter refers to the sample data file OS_IP_WebServer.SVDat which is part of the SEGGER
SystemView package.
The sample data file shows the behavior of a target system running the embOS RTOS, the embOS/
IP TCP/IP stack and a web server application.
We are going to analyze what the application is doing with the information from SEGGER
SystemView.
18
CHAPTER 2
2.1
SystemViewer loads and analyzes the data and should now look like this:
19
2.2
Timeline
The Timeline window shows the system activity by context (task, interrupt, scheduler and
idle) over the system time. Each row refers to one context item and we can see all items
which have been used in the application while it has been monitored. In the initial view we
can see system activity every millisecond.
Move the mouse over a context name to get more information about the context type and
run time information.
Zoom in to a timeline width of 2.0ms and double-click on the vertical line below +1000us
to center the item and zoom in further to see the active context. (Use the mouse wheel,
[Ctrl] + [+]/[-] keys or ViewZoom In, ViewZoom Out to zoom.) We see that the activity
every millisecond is the 1kHz SysTick interrupt.
Jump to the next interrupt with ViewForward (Keyboard shortcut: F) until we see more
activity than the SysTick interrupt. Zoom in or out to see all activity on the screen. We can
see the SysTick interrupt returned to the OS Scheduler, which makes the IP_Task ready,
indicated by the grey bar in the IP_Tasks row, and lets it run. IP_Tasks calls three embOS
API functions (OS_Use, OS_Unuse, OS_WaitEventTimed) and goes back to idle.
Move the mouse over the IP_Task context activity to get more information about the events
and the runtime of the activity.
Conclusion
We have got some first information about the monitored system. From the Timeline we
know which tasks and interrupts are used by the application, that it is controlled by the
1kHz SysTick interrupt, and the IP_Task is activated at least every 10ms.
20
2.3
CHAPTER 2
Events list
The Events list shows all events as they are sent from the system and displays their
information, including timestamp of the event, active context, type of event and event
details.
We have seen that every millisecond the SysTick ISR enters and exits and that it activates
the IP_Task every 10ms because its timeout occurred.
Go to event #5145 with ViewGo to Event (Keyboard shortcut: Ctrl+G). It is a call of
OS_WaitEventTimed with a timeout of 10ms from the IP_Task at 00:00:01.868.026. The
timeout would happen at 00:00:01.878.026.
Set a time reference on the event with ViewEventsToggle Reference (Keyboard
shortcut R). All following timestamps in the events list are measured from the latest
reference.
To now see whether the IP_Task runs because of the timeout or because of the event,
move the mouse over the label of the IP_Task row in the timeline and click on the right
arrow button to jump to the next activity of IP_Task. Alternatively select the Task Run event
(#5142) and select GoNext Task Run in IP_Task (Keyboard shortcut: Shift+N) to
jump to the next Task Run event of IP_Task.
The timestamp is 00:00:00.006.308, clearly before the 10ms timeout, so the task has been
activated by the event it waited for. We can see the ETH_Rx interrupt happened before and
called OS_SignalEvent, which marked the task as ready as indicated in the timeline. The
ETH_Rx interrupt returns to the Scheduler and IP_Task runs. We have received something
via Ethernet.
21
Conclusion
Going further through the events, we can see that the IP_Task is activated after the 10ms
timeout occurred or after we received something and the ETH_Rx interrupt occurred.
22
2.4
CHAPTER 2
23
2.4.1
Analysis conclusion
We analyzed what a system does without insight into the application code. With the
application source we can check with SEGGER SystemView that the system does what it
is supposed to do.
SEGGER SystemView can actively help developing applications, since it not only shows what
the system does, but also allows exact time measurement and visualizes the influence of
interrupts and events on the application flow. This provides advanced possibilities to find
problems and to improve the system.
24
CHAPTER 2
25
Chapter 3
Host application - SystemViewer
This section describes SystemViewer, the SystemView analysis and visualization tool.
26
3.1
CHAPTER 3
Introduction
Introduction
SystemViewer is the host PC visualization tool for SEGGER SystemView. It connects via
a J-Link to the target application, controls the application tracing and reads its data.
The monitored data is analyzed on runtime and visualized in the different windows of
SystemViewer. After tracing has stopped, the data can be saved to a file which allows later
analysis of the application trace.
To get started with SystemViewer please refer to the previous chapter.
SystemViewer provides different windows to visualize the execution in the system, measure
timing and analyze the CPU load. All windows are synchronized to always get all information
of the currently selected state.
For a description of the application windows please refer to the following sections.
SystemViewer allows going through the monitored data and keeping track of what happened
in the system at any time.
27
3.2
Timeline window
The Timeline window gathers all system information within one view. It shows the system
activity by context (task, interrupt, scheduler, timer and idle) over the system time. Each
row refers to one context item to show all context items which have been used in the
application while it has been monitored.
A mouse-over tooltip on the context items reveals more details and run time information
about the context.
A mouse-over tooltip on active context shows the details of the current event and the
currently active functions if available.
A ruler on the context marks the current activity span.
An existing task is marked with a light background from its first occurrence to its termination
to provide a quick overview which tasks exist at any time.
Switches between contexts are displayed as connection lines to easily identify which events
cause context switches and when they occurred.
Tasks which are marked ready for execution are displayed with a light grey bar until their
execution starts.
Contexts are ordered by priority. The first row displays all activity in a unified context.
Interrupts are top of the list, ordered by Id. Followed by the Scheduler and software timers,
if they are used in the system. Below the Scheduler (and timer) the tasks are ordered by
priority. The bottom context displays idle time, when no other context is active.
The Timeline is synchronized with the Events list. The event under the cursor (the blue line)
is the selected event in the list.
The cursor can be fixed at 10% to 90% of the window and update the selection in the list
when scrolling through the timeline.
An event can be dragged under the cursor to select the corresponding event in the events
list and vice-versa.
To get an overview of the whole system or to see the exact duration of an event the Timeline
view can be zoomed in or out.
To jump to the next or previous activity of a context, the labels include left and right buttons
on mouse-over.
28
CHAPTER 3
3.3
Events window
Events window
The Events window shows all events as they are sent by the system and displays their
information. Every event has the following items:
A timestamp in target time or recording time, which can be displayed with microsecond
or nanosecond resolution.
A context from which it has been created, i.e. the task which is running.
An event description, displayed with the type of event (IRS enter and exit, task activity,
API call).
Event details describing the parameters of the event, i.e. the API call parameters.
An ID to locate events in the list.
The Events window allows going through the list, jumping to the next or previous context, or
to the next or previous similar event. The Timeline and CPU Load windows are synchronized
to show the currently selected event.
The timestamp in the events list can be relative to the start of recording or the target
system time if it has been sent by the system. Events can be set as time reference for
following events to allow easy measurement of when an event occurred after another one.
SystemView include an event filter to select show or hide APIs, ISRs, System Information,
Messages, Tasks, and User Events.
29
3.4
Terminal Window
The Terminal window shows printf output from the target application alongside the task
context from which the output has been sent and the timestamp when the message has
been sent. Double-click on a message to show it with all information in the events list.
The Timeline window shows indicators for output, ordered by level - Errors are always on
top.The log level for which indicators are shown can be configured via View Message
Indicators.
SystemView printf output can be sent formatted by the application or unformatted with all
parameters and is formatted by SystemViewer.
30
3.5
CHAPTER 3
The CPU Load window displays the used CPU time of contexts for a period. The CPU Load is
measured over the width of a bin with the current resolution of the Timeline and is therefore
synchronized with the zoom level.
The number of bins can be selected to measure the load over a shorter or longer period.
With a single bin the CPU load is measured over the whole visible Timeline.
31
3.6
Contexts window
The Contexts window shows statistical information of the contexts (Tasks, Interrupts,
Scheduler, and Idle). Each context item can be identified by its Name and Type. The Type
includes the priority for tasks and the ID for interrupts. (i.e. The Cortex-M SysTick is
interrupt ID #15.)
The Contexts window information include following items:
The Contexts window is updated while the recording, the current context is indicated by
selection of the row.
32
CHAPTER 3
3.7
System information
System information
Information about the system, which has been sent by the application to identify it.
Recording properties, which can be set by the user.
Statistics about tasks, interrupts, SystemView events and recording throughput.
The System information includes the application name, the used OS, the target device, and
the timing information. Additional information about task switches and interrupt frequency
provides a quick overview of the system.
The recording properties can be set by the user to be stored with the record when it is
saved and allow identifying a record when it is loaded for later analysis.
33
3.8
GUI controls
SystemViewer can be controlled with mouse and keyboard, and via menus. The most
important controls are also accessible in the toolbar.
The following table describes the controls of SystemViewer.
Action
Menu
Shortcut
Recording data
Start recording on the target.
TargetStart Recording
F5
Stop recording.
TargetStop Recording
F9
Ctrl+F5
FileSave Data
Ctrl+S, F2
FileLoad Data
Ctrl+O, F3
FileRecent Files
none
FileSample Recordings
none
FileRecording Properties
Ctrl+Shift+R
View
Set/clear the current event as
time reference.
ViewToggle Reference
ViewClear References
Ctrl+Shift+R
None
None
ViewResolution: 1 us
None
ViewResolution: 100 ns
None
ViewResolution: 10 ns
None
ViewResolution: 1 ns
None
Zoom in.
ViewZoomZoom In
Ctrl++,
Scroll up
Zoom out.
ViewZoomZoom Out
Ctrl+-,
Scroll down
ViewZoom10us Window
None
ViewZoom20us Window
None
ViewZoom50us Window
None
ViewZoom100us Window
None
ViewZoom200us Window
None
ViewZoom500us Window
None
ViewZoom1ms Window
None
ViewZoom2ms Window
None
ViewZoom5ms Window
None
ViewZoom10ms Window
None
ViewZoom20ms Window
None
34
CHAPTER 3
Action
GUI controls
Menu
Shortcut
ViewZoom50ms Window
None
ViewZoom100ms Window
None
ViewZoom200ms Window
None
ViewZoom500ms Window
None
ViewZoom1s Window
None
ViewZoom2s Window
None
ViewZoom5s Window
None
ViewZoom10s Window
None
ViewZoom30s Window
None
ViewZoom60s Window
None
ViewZoomFull Recording
None
ViewCursorCursor at 10%
ViewCursorCursor at 20%
ViewCursorCursor at 30%
ViewCursorCursor at 40%
ViewCursorCursor at 50%
ViewCursorCursor at 60%
ViewCursorCursor at 70%
ViewCursorCursor at 80%
ViewCursorCursor at 90%
None
None
None
None
None
Shift+A
Shift+I
ViewEvent FilterShow
Messages
Shift+M
ViewEvent FilterShow
System Events
Shift+S
35
Action
Menu
Shortcut
Shift+T
Shift+U
Ctrl+Shift+A
Ctrl+Shift+I
Ctrl+Shift+M
ViewEvent FilterShow
System Events only
Ctrl+Shift+S
Ctrl+Shift+T
Ctrl+Shift+U
Ctrl+Shift
+Space
ViewAuto Scroll
None
ViewMessage Indicators
Ctrl+M
Go
Jump to the next context switch.
GoForward
GoBack
GoNext [Event]
GoPrevious [Event]
Shift+N
GoPrevious [Event] in
[Context]
Shift+P
GoGo to Event
Ctrl+G
GoGo to Timestamp
Ctrl+Shift+G
Scroll forward.
GoScroll Forward
Left, Ctrl
+Scroll up,
Click&Drag
GoScroll Back
Right, Ctrl
+Scroll
down,
Click&Drag
Scroll back.
Window
Show/hide the Events window.
WindowEvents View
WindowTime View
WindowContext View
36
CHAPTER 3
Action
GUI controls
Menu
Shortcut
WindowTerminal View
WindowSystem View
WindowLog View
None
None
ToolPreferences
Alt+,
Help
Open this SystemView Manual.
HelpSystemView Manual
F11
HelpAbout SystemViewer
F12
37
Chapter 4
Recording with SystemView
This section describes how to use SystemViewer for continuous recording and how to do manual
single-shot recording with a debugger.
38
4.1
CHAPTER 4
Continuous recording
Continuous recording
With a J-Link debug probe and the SEGGER Real Time Transfer technology (RTT),
SystemViewer can continuously record target execution in real time, while the target is
running. RTT requires the ability of reading memory via the debug interface during program
execution. This especially includes ARM Cortex-M0, M0+, M1, M3, M4 and M7 processors
as well as all Renesas RX devices.
Start recording
To start recording with SystemViewer, connect the J-Link and target and click
TargetStart Recording.
Enter or select the device name. The drop-down lists the most recently used devices. If the
current device is not part of the list, it can be entered manually. A list of supported device
names is available at https://www.segger.com/jlink_supported_devices.html.
Note: For RTT Control Block Auto Detection, as well as for some devices the exact device
has to be known. It is recommended to not only select a core.
If necessary configure the J-Link connection, when connecting to a specific J-Link or to a
J-Link, which is connected via TCP/IP.
Select the target interface and target interface speed for the connected device.
Configure the RTT Control Block Detection. In most cases Auto Detection can be used. If
the RTT Control Block can not be detected, select a Search Range in which the RTT Control
Block can be, or enter the exact Address directly.
Click OK to connect to the target and start recording.
Note: SystemViewer can be used parallel to a debugger. In this case recording can be done
while the debugger is running. Make sure all required configuration is done in the debugger.
SystemViewer will continuously read the recorded data form the target and update its
windows with the data while running.
39
Stop recording
To stop recording select TargetStop Recording.
SystemViewer is limited to 1000000 events and automatically stops afterwards.
40
CHAPTER 4
4.2
Single-shot recording
Single-shot recording
When the target device does not support RTT or 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, which are of interest.
As a usual application generates about 5 to 15 kByte recording data per second and peaks
only to higher rates at full load, even a small buffer in the internal RAM can be used to
record data for analysis of critical parts. When using external RAM SystemView can record
for a long time, even in single-shot mode.
With a J-Link SystemViewer can automatically read single-shot data from the target.
Without a J-Link or without SystemViewer the data can be read using following steps:
Halt the application in the debugger when the buffer is full or after recording has been
done.
Get the SystemView RTT buffer address and the number of bytes used (Normally
_SEGGER_RTT.aUp[1].pBuffer and _SEGGER_RTT.aUp[1].WrOff).
Save the number of bytes from the buffer to a file with .SVDat extension.
Open the file with SystemViewer.
To be able to record more than once, the buffer write offset (_SEGGER_RTT.aUp[1].WrOff)
can be set to 0 when the data has been read. To prevent SystemView overflow events to
happen, the application should be halted as soon as the buffer is filled and cannot hold
another SystemView event.
SEGGER SystemView User Guide
41
4.3
Post-mortem analysis
Post-mortem analysis is similar to single-shot recording, with one difference: SystemView
events are continuously recorded and the SystemView buffer wraps around to overwrite
older events when the buffer is filled. When reading out the buffer, the newest events are
available.
Post-mortem analysis can be useful when a system runs for a long time and suddenly
crashes. In this case the SystemView buffer can be read from the target and SystemViewer
can show what happened in the system immediately before the crash.
Note: Post-mortem analysis requires the debugger or debug probe to be able to connect
to the target system without resetting it or modifying the RAM.
To get as much useful data for analysis as possible it is recommended to use a large buffer
for SystemView, 8 kByte or more. External RAM can be used for the SystemView buffer.
To configure the target system for post-mortem mode, please refer to
SEGGER_SYSVIEW_POST_MORTEM_MODE and SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT in chapter
Target configuration on page 51.
With a J-Link SystemViewer can automatically read post-mortem data from the target.
Without a J-Link or without SystemViewer the data can be read using following steps:
Since the SystemView buffer is a ring buffer, the data might have to be read in two chunks
to start reading at the beginning and save as much data as possible.
42
4.4
CHAPTER 4
43
Chapter 5
Target implementation SYSTEMVIEW modules
This section describes the instrumentation of a target application to use SEGGER SystemView.
44
CHAPTER 5
5.1
Prerequisites
Prerequisites
To use SEGGER SystemView the target source modules of the SystemView package need
to be added to the application make file or project.
The SEGGER SystemView
systemview.html.
package
is
available
at
https://www.segger.com/
To use continuous real-time tracing the following additional items are required:
For an easy start it is recommended to use SEGGER embOS V4.12 or later, which already
includes the SystemView integration.
5.1.1
The following files are part of the SEGGER SystemView target implementation. We
recommend to copy all files into the application project and keep the given directory
structure.
File
Description
/Config/Global.h
/Config/SEGGER_RTT_Conf.h
/Config/SEGGER_SYSVIEW_Conf.h
/Config/
SEGGER_SYSVIEW_Config_[SYSTEM].c
/OS/SEGGER_SYSVIEW_[OS].c
/OS/SEGGER_SYSVIEW_[OS].h
Interface header.
/SEGGER/SEGGER.h
/SEGGER/SEGGER_RTT.c
/SEGGER/SEGGER_RTT.h
/SEGGER/SEGGER_SYSVIEW.c
/SEGGER/SEGGER_SYSVIEW.h
/SEGGER/SEGGER_SYSVIEW_ConfDefault.h
/SEGGER/SEGGER_SYSVIEW_Int.h
45
5.2
Example
For a system with embOS on a Cortex-M3 include SEGGER_SYSVIEW_Config_embOS.c,
SEGGER_SYSVIEW_embOS.c and SEGGER_SYSVIEW_embOS.h.
For a system with no OS or no
SEGGER_SYSVIEW_Config_NoOS.c only.
instrumented
OS
on
Cortex-M3
include
46
CHAPTER 5
5.3
Initializing SystemView
Initializing SystemView
The system information are sent by the application. This information can be configured via
defines in SEGGER_SYSVIEW_Config_[SYSTEM].c. Add a call to SEGGER_SYSVIEW_Conf() in
the main function to initialize SystemView.
#include "SEGGER_SYSVIEW.h"
/*********************************************************************
*
*
main()
*
* Function description
*
Application entry point
*/
int main(void) {
OS_IncDI();
/* Initially disable interrupts
OS_InitKern();
/* Initialize OS
OS_InitHW();
/* Initialize Hardware for OS
BSP_Init();
/* Initialize BSP module
SEGGER_SYSVIEW_Conf();
*/
*/
*/
*/
*/
*/
The generic part of SEGGER SystemView is now ready to monitor the application.
When using embOS V4.12 or later with profiling enabled, SystemView events for ISRs,
Task, and API calls are generated. When not using embOS, appropriate events must be
generated by the application.
Download the application to the target and let it run. As long as SystemViewer is not
connected, and SEGGER_SYSVIEW_Start() is not called, the application will not generate
SystemView events. When SystemViewer is connected or SEGGER_SYSVIEW_Start() is
called it will activate recording SystemView events.
47
5.4
48
5.5
CHAPTER 5
"Cortex-M4"
"I#15=SysTick"
as
Cortex-M cycle counter is used as SystemView timestamp. Must match SEGGER_SYSVIEW_Conf.h
USE_CYCCNT_TIMESTAMP
USE_CYCCNT_TIMESTAMP
1
SYSVIEW_SYSDESC1
49
// #define SYSVIEW_SYSDESC1
//#endif
//#ifndef
SYSVIEW_SYSDESC2
// #define SYSVIEW_SYSDESC2
//#endif
""
""
/*********************************************************************
*
*
Defines, fixed
*
**********************************************************************
*/
#define DWT_CTRL
(*(volatile OS_U32*) (0xE0001000uL))
// DWT Control Register
#define NOCYCCNT_BIT
(1uL << 25)
// Cycle counter support bit
#define CYCCNTENA_BIT
(1uL << 0)
// Cycle counter enable bit
/*********************************************************************
*
*
_cbSendSystemDesc()
*
* Function description
*
Sends SystemView description strings.
*/
static void _cbSendSystemDesc(void) {
SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",O=embOS,D="SYSVIEW_DEVICE_NAME);
#ifdef SYSVIEW_SYSDESC0
SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC0);
#endif
#ifdef SYSVIEW_SYSDESC1
SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC1);
#endif
#ifdef SYSVIEW_SYSDESC2
SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC2);
#endif
}
/*********************************************************************
*
*
Global functions
*
**********************************************************************
*/
void SEGGER_SYSVIEW_Conf(void) {
#if USE_CYCCNT_TIMESTAMP
//
// The cycle counter must be activated in order
// to use time related functions.
//
if ((DWT_CTRL & NOCYCCNT_BIT) == 0) {
// Cycle counter supported?
if ((DWT_CTRL & CYCCNTENA_BIT) == 0) {
// Cycle counter not enabled?
DWT_CTRL |= CYCCNTENA_BIT;
// Enable Cycle counter
}
}
#endif
SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ,
&SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc);
SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
OS_SetTraceAPI(&embOS_TraceAPI_SYSVIEW);
// Configure embOS to use SYSVIEW.
}
/*************************** End of file ****************************/
50
CHAPTER 5
51
Chapter 6
Target configuration
SEGGER SystemView is configurable to match the target device and application. The default
compile-time configuration flags are preconfigured with valid values, to match the requirements
of most systems and normally do not require modification.
The default configuration of SystemView can be changed via compile-time flags which can be
added to SEGGER_SYSVIEW_Conf.h.
52
CHAPTER 6
6.1
System-specific configuration
System-specific configuration
The following compile-time configuration is required to match the target system. The
sample configuration in SEGGER_SYSVIEW_Conf.h defines the configuration to match most
systems (i.e. Cortex-M devices with Embedded Studio, GCC, IAR or Keil ARM). If the
sample configuration does not include the used system, the configuration has to be adapted
accordingly.
For a detailed description of the system-specific configuration, refer to Supported CPUs on
page 61.
6.1.1
SEGGER_SYSVIEW_GET_TIMESTAMP()
6.1.2
of
the
system
timestamp
has
to
be
provided
in
SEGGER_SYSVIEW_TIMESTAMP_BITS
6.1.3
SEGGER_SYSVIEW_GET_INTERRUPT_ID()
53
6.1.4
SEGGER_SYSVIEW_LOCK()
Function macro to recursively lock SystemView transfers from being interrupted. I.e. disable
interrupts.
SEGGER_SYSVIEW_LOCK() must preserve the previous lock state to be restored in
SEGGER_SYSVIEW_UNLOCK().
Recording a SystemView event must not be interrupted by recording another
event. Therefore all interrupts which are recorded by SystemView (call
SEGGER_SYSVIEW_RecordEnterISR() / SEGGER_SYSVIEW_RecordExitISR()), call an
instrumented function (i.e. an OS API function), cause an immediate context switch, or
possibly create any other SystemView event have to be disabled.
SEGGER_SYSVIEW_LOCK() can use the same locking mechanism as SEGGER_RTT_LOCK().
Default: SEGGER_RTT_LOCK()
SEGGER_RTT_LOCK() is defined for most systems (i.e. Cortex-M devices with Embedded
Studio, GCC, IAR or Keil ARM) in SEGGER_RTT_Conf.h. If the macro is not defined, or empty,
it has to be provided to match the target system.
6.1.5
SEGGER_SYSVIEW_UNLOCK()
Function macro to recursively unlock SystemView transfers from being interrupted. I.e.
restore previous interrupt state.
SEGGER_SYSVIEW_UNLOCK()
SEGGER_RTT_UNLOCK().
can
use
the
same
locking
mechanism
as
Default: SEGGER_RTT_UNLOCK()
SEGGER_RTT_UNLOCK() is defined for most systems (i.e. Cortex-M devices with Embedded
Studio, GCC, IAR or Keil ARM) in SEGGER_RTT_Conf.h. If the macro is not defined, or empty,
it has to be provided to match the target system.
54
CHAPTER 6
6.2
Generic configuration
Generic configuration
The following compile-time flags can be used to tune or change how SystemView events
are recorded.
The default compile-time configuration flags are preconfigured with valid values, to match
the requirements of most systems and normally do not require modification.
6.2.1
SEGGER_SYSVIEW_RTT_BUFFER_SIZE
6.2.2
SEGGER_SYSVIEW_RTT_CHANNEL
The RTT Channel used for SystemView event recording and communication. 0: Auto
selection
Note: SEGGER_RTT_MAX_NUM_UP_BUFFERS, defined in SEGGER_RTT_Conf.h has to be greater
than SEGGER_SYSVIEW_RTT_CHANNEL.
Default: 0
6.2.3
SEGGER_SYSVIEW_USE_STATIC_BUFFER
If set to 1 SystemView uses a static buffer to create SystemView events. This in general
saves space, since only one buffer is required and task stacks can be as small as possible.
When a static buffer is used, critical code executed between SystemView locking invocations
takes slightly longer.
If set to 0 SystemView events are created on the stack. Make sure all task stacks, as well
as the C stack for interrupts are large enough to hold the largest SystemView events (~228
bytes). SystemView locks only while transferring the stack buffer into the RTT buffer.
Default: 1
6.2.4
SEGGER_SYSVIEW_POST_MORTEM_MODE
55
6.2.5
SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT
Configure how often Sync and System Info events are sent in post-mortem mode. Make
sure at least one sync is available in the SystemView buffer.
The recommended sync frequency is Buffer Size / 16
Default: 8 = Sync every 256 Packets
6.2.6
SEGGER_SYSVIEW_ID_BASE
6.2.7
SEGGER_SYSVIEW_ID_SHIFT
6.2.8
SEGGER_SYSVIEW_MAX_STRING_LEN
56
CHAPTER 6
6.2.9
Generic configuration
SEGGER_SYSVIEW_MAX_ARGUMENTS
6.2.10 SEGGER_SYSVIEW_BUFFER_SECTION
The SystemView RTT Buffer may be placed into a dedicated section, instead of the default
data section. This allows placing the buffer into external memory or at a given address.
When SEGGER_SYSVIEW_BUFFER_SECTION is defined, the section has to be defined in the
linker script.
Default: SEGGER_RTT_SECTION or not defined
6.2.11.1 BUFFER_SIZE_UP
Number of bytes to be used for the RTT Terminal output channel.
RTT can be used for printf terminal output without modification. BUFFER_SIZE_UP defines
how many bytes can be buffered for this.
If RTT Terminal output is not used, define BUFFER_SIZE_UP to its minimum of 4.
Default: 1024Bytes
6.2.11.2 BUFFER_SIZE_DOWN
Number of bytes to be used for the RTT Terminal input channel.
RTT can receive input from the host on the terminal input channel. BUFFER_SIZE_DOWN
defines how many bytes can be buffered and therefore sent at once from the host.
If RTT Terminal input is not used, define BUFFER_SIZE_DOWN to its minimum of 4.
Default: 16Bytes
6.2.11.3 SEGGER_RTT_MAX_NUM_UP_BUFFERS
Maximum number of RTT up (to host) buffers. Buffer 0 is always used for RTT terminal
output, so to use it with SystemView SEGGER_RTT_MAX_NUM_UP_BUFFERS has to be at least 2.
57
Default: 2
6.2.11.4 SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
Maximum number of RTT down (to target) buffers. Buffer 0 is always used for RTT terminal
input, so to use it with SystemView SEGGER_RTT_MAX_NUM_UP_BUFFERS has to be at least 2.
Default: 2
6.2.11.5 SEGGER_RTT_MODE_DEFAULT
Mode for pre-initialized RTT terminal channel (buffer 0).
Default: SEGGER_RTT_MODE_NO_BLOCK_SKIP
6.2.11.6 SEGGER_RTT_PRINTF_BUFFER_SIZE
Size of buffer for RTT printf to bulk-send chars via RTT. Can be defined as 0 if
SEGGER_RTT_Printf is not used.
Default: 64
6.2.11.7 SEGGER_RTT_SECTION
The RTT Control Block may be placed into a dedicated section, instead of the default data
section. This allows placing it at a known address to be able to use the J-Link auto-detection
or easily specify a search range.
When SEGGER_RTT_SECTION is defined, the application has to make sure the section
is valid, either by initializing it with 0 in the startup code or explicitly calling
SEGGER_RTT_Init() at the start of the application. SEGGER_RTT_Init() is implicitly called
by SEGGER_SYSVIEW_Init().
Default: not defined
6.2.11.8 SEGGER_RTT_BUFFER_SECTION
The RTT terminal buffer may be placed into a dedicated section, instead of the default data
section. This allows placing the buffer into external memory or at a given address.
Default: SEGGER_RTT_SECTION or not defined
58
CHAPTER 6
6.3
Optimizing SystemView
Optimizing SystemView
In order to get the most precise run-time information from a target system, the recording
instrumentation code needs to be fast, least intrusive, small, and efficient. The SystemView
code is written to be efficient and least intrusive. Speed and size of SystemView are a
matter of target and compiler configuration. The following sections describe how to optimize
SystemView.
6.3.1
Compiler optimization
6.3.2
Recording optimization
SystemView uses a variable-length encoding to store and transfer events, which enables
saving buffer space and bandwidth on the debug interface.
The size of some event parameters can be optimized via compile-time configuration.
Shrink IDs
IDs are pointers to a symbol in RAM, i.e. a Task ID is a pointer to the task control block.
To minimize the length of recorded IDs they can be shrunken.
SEGGER_SYSVIEW_ID_BASE is subtracted from a pointer to get its ID. It can be set to
subtract the base RAM address from pointers, which still results in unique, but smaller IDs.
For example if the RAM range is 0x20000000 to 0x20001000 it is recommended to define
SEGGER_SYSVIEW_ID_BASE as 0x20000000, which results in the pointer 0x20000100 to have
the ID 0x100 and requires two instead of four bits to store it.
SEGGER_SYSVIEW_ID_SHIFT is the number of bits a pointer is shifted right to get its ID. If
all recorded pointers are 4 byte aligned, SEGGER_SYSVIEW_ID_SHIFT can be defined as 2.
A pointer 0x20000100 would then have the ID 0x8000040 or with the previous subtraction
of SEGGER_SYSVIEW_ID_BASE as 0x20000000 the ID would be 0x40, requiring only one byte
to be recorded.
Timestamp source
Event timestamps in SystemView are recorded as the difference of the timestamp to the
previous event. This saves buffer space per se.
While it is recommended to use a timestamp source with the CPU clock frequency for highest
time resolution, a lower timestamp frequency might save additional buffer space as the
timestamp delta is lower.
With a CPU clock frequency of 160 MHz the timestamp might be shifted by 4, resulting in
a timestamp frequency of 10MHz (100ns resolution), and 4 bits less to be encoded.
When the timestamp size is not 32-bit any more, i.e. it wraps around before 0xFFFFFFFF,
SEGGER_SYSVIEW_TIMESTAMP_BITS has to be defined as the timestamp size, e.g. as 28
when shifting a 32-bit timestamp by 4.
6.3.3
Buffer configuration
The recording and communication buffer size for SystemView and RTT can be set in the
target configuration.
For continuous recording a small buffer of 1 to 4kByte is sufficient in most cases and allows
using SystemView even with a small internal RAM.
59
For single-shot and post-mortem mode a larger buffer can be desirable. In this case
SEGGER_SYSVIEW_RTT_BUFFER_SIZE can be set to a larger value. To place the SystemView
recording buffer into external RAM a SEGGER_SYSVIEW_BUFFER_SECTION can be defined and
the linker script adapted accordingly.
If only SystemView is used and no terminal output with RTT, BUFFER_SIZE_UP in
SEGGER_RTT_Conf.h can be set to a smaller value to save memory.
60
CHAPTER 6
Optimizing SystemView
61
Chapter 7
Supported CPUs
This section describes how to set up and configure the SystemView modules for different target
CPUs.
SEGGER SystemView virtually supports any target CPU, however, continuous recording is only
possible with CPUs, which support background memory access - ARM Cortex-M and Renesas RX.
On other CPUs SystemView can be used in single-shot or post-mortem analysis mode. Refer to
Single-shot recording on page 40.
In order for SystemView to run properly, some target specific configuration needs to be done.
This configuration is described for some CPUs below.
62
CHAPTER 7
7.1
Cortex-M3 / Cortex-M4
Cortex-M3 / Cortex-M4
Recording mode
Supported?
Continuous recording
Yes
Single-shot recording
Yes
Post-mortem analysis
Yes
7.1.1
Event timestamp
The timestamp source on Cortex-M3 / Cortex-M4 can be the cycle counter, which allows
cycle-accurate event recording.
In order to save bandwith when recording events, the cycle counter can optionally be rightshifted, i.e. by 4 bits, which results in a timestamp frequency of core speed devided by 16.
Configuration:
//
// Use full cycle counter for higher precision
//
#define SEGGER_SYSVIEW_GET_TIMESTAMP() (*(U32 *)(0xE0001004))
#define SEGGER_SYSVIEW_TIMESTAMP_BITS
(32)
//
// Use cycle counter devided by 16 for smaller size / bandwidth
//
#define SEGGER_SYSVIEW_GET_TIMESTAMP() ((*(U32 *)(0xE0001004)) >> 4)
#define SEGGER_SYSVIEW_TIMESTAMP_BITS
(28)
7.1.2
Interrupt ID
The currently active interrupt can be directly identified by reading the Cortex-M ICSR[8:0],
which is the active vector field in the interrupt controller status register (ICSR).
Configuration:
//
// Get the interrupt Id by reading the Cortex-M ICSR[8:0]
//
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID()
((*(U32 *)(0xE000ED04)) & 0x1FF)
7.1.3
Locking and unlocking SystemView to prevent transferring records from being interrupted
can be done by disabling interrupts. On Cortex-M3 / Cortex-M4 not all interrupts need to
be disabled, only those which might itself generate SystemView events or cause a task
switch in the OS.
By default the priority mask is set to 32, disabling all interrupts with a priority of 32 or
lower (higher numerical value).
Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events,
or cause task switches. When high-priority interrupts must not be masked while sending RTT
data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly. (Higher
priority = lower priority number)
Default value for embOS: 128u
Default
configuration
in
FreeRTOS:
configMAX_SYSCALL_INTERRUPT_PRIORITY:
( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
In case of doubt mask all interrupts: 0u
Lock and unlock for SystemView and RTT can be the same.
Configuration:
//
SEGGER SystemView User Guide
63
// RTT locking for GCC toolchains in SEGGER_RTT_Conf.h
//
#define SEGGER_RTT_LOCK()
{
unsigned int LockState;
__asm volatile ("mrs
%0, basepri \n\t"
"mov
r1, $32
\n\t"
"msr
basepri, r1 \n\t"
: "=r" (LockState)
:
: "r1"
);
#define SEGGER_RTT_UNLOCK()
\n\t"
\
\
\
\
\
\
\
\
\
\
\
\
\
}
//
// Define SystemView locking in SEGGER_SYSVIEW_Conf.h
//
#define SEGGER_SYSVIEW_LOCK()
SEGGER_RTT_LOCK()
#define SEGGER_SYSVIEW_UNLOCK() SEGGER_RTT_UNLOCK()
7.1.4
Sample configuration
SEGGER_SYSVIEW_Conf.h
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
*/
: SEGGER_SYSVIEW_Conf.h
: SEGGER SysView configuration for Cortex-M3 / Cortex-M4.
#ifndef SEGGER_SYSVIEW_CONF_H
#define SEGGER_SYSVIEW_CONF_H
/*********************************************************************
*
*
SysView timestamp configuration
*/
// Cortex-M cycle counter. Shifted by 4 to save bandwith.
#define SEGGER_SYSVIEW_GET_TIMESTAMP()
((*(U32 *)(0xE0001004)))
// Number of valid bits low-order delivered as timestamp.
#define SEGGER_SYSVIEW_TIMESTAMP_BITS
32
/*********************************************************************
*
*
SysView Id configuration
*/
// Default value for the lowest Id reported by the application.
// Can be overridden by the application via SEGGER_SYSVIEW_SetRAMBase().
#define SEGGER_SYSVIEW_ID_BASE
0x20000000
// Number of bits to shift the Id to save bandwidth.
// (i.e. 2 when all reported Ids (pointers) are 4 byte aligned)
#define SEGGER_SYSVIEW_ID_SHIFT
0
/*********************************************************************
*
*
SysView interrupt configuration
*/
// Get the currently active interrupt Id. (read Cortex-M ICSR[8:0] = active vector)
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID()
((*(U32 *)(0xE000ED04)) & 0x1FF)
/*********************************************************************
SEGGER SystemView User Guide
64
CHAPTER 7
*
*
SysView locking
*/
// Lock SysView (nestable)
#define SEGGER_SYSVIEW_LOCK()
// Unlock SysView (nestable)
#define SEGGER_SYSVIEW_UNLOCK()
Cortex-M3 / Cortex-M4
SEGGER_RTT_LOCK()
SEGGER_RTT_UNLOCK()
#endif
/*************************** End of file ****************************/
SEGGER_SYSVIEW_Config_NoOS_CM3.c
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
: SEGGER_SYSVIEW_Config_NoOS_CM3.c
: Sample setup configuration of SystemView without an OS
for ARM Cortex-M3 and Cortex-M4 targets.
*/
#include "SEGGER_SYSVIEW.h"
// SystemcoreClock can be used in most CMSIS compatible projects.
// In non-CMSIS projects define SYSVIEW_CPU_FREQ below.
extern unsigned int SystemCoreClock;
/*********************************************************************
*
*
Defines, configurable
*
**********************************************************************
*/
// The application name to be displayed in SystemViewer
#define SYSVIEW_APP_NAME
"Demo Application"
// The target device name
#define SYSVIEW_DEVICE_NAME
"Cortex-M4"
65
*/
void SEGGER_SYSVIEW_Conf(void) {
SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ,
0, _cbSendSystemDesc);
SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
}
/*************************** End of file ****************************/
66
CHAPTER 7
7.2
Supported?
Continuous recording
Yes
Single-shot recording
Yes
Post-mortem analysis
Yes
7.2.1
Cortex-M0, Cortex-M0+ and Cortex-M1 do not have a cycle count register. the event
timestamp has to be provided by an application clock source, i.e. the system timer, SysTick.
SEGGER_SYSVIEW_X_GetTimestamp() can be used to implement the functionality.
When the SysTick interrupt is used in the application, i.e. by the RTOS, the SysTick handler
should increment SEGGER_SYSVIEW_TickCnt, otherwise a SysTick handler has to be added
to the application and configured accordingly.
Configuration:
//
// SEGGER_SYSVIEW_TickCnt has to be defined in the module which
// handles the SysTick and must be incremented in the SysTick
// handler before any SYSVIEW event is generated.
//
// Example in embOS RTOSInit.c:
//
// unsigned int SEGGER_SYSVIEW_TickCnt; // <<-- Define SEGGER_SYSVIEW_TickCnt.
// void SysTick_Handler(void) {
// #if OS_PROFILE
//
SEGGER_SYSVIEW_TickCnt++; // <<-- Increment SEGGER_SYSVIEW_TickCnt asap.
// #endif
//
OS_EnterNestableInterrupt();
//
OS_TICK_Handle();
//
OS_LeaveNestableInterrupt();
// }
//
extern unsigned int SEGGER_SYSVIEW_TickCnt;
/*********************************************************************
*
*
Defines, fixed
*
**********************************************************************
*/
#define SCB_ICSR
(*(volatile U32*) (0xE000ED04uL)) // Interrupt Control State Register
#define SCB_ICSR_PENDSTSET_MASK
(1UL << 26)
// SysTick pending bit
#define SYST_RVR
(*(volatile U32*) (0xE000E014uL)) // SysTick Reload Value Register
#define SYST_CVR
(*(volatile U32*) (0xE000E018uL)) // SysTick Current Value Register
/*********************************************************************
*
*
SEGGER_SYSVIEW_X_GetTimestamp()
*
* Function description
*
Returns the current timestamp in ticks using the system tick
*
count and the SysTick counter.
*
All parameters of the SysTick have to be known and are set via
*
configuration defines on top of the file.
*
* Return value
*
The current timestamp.
*
* Additional information
67
*
SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are
*
disabled. Therefore locking here is not required.
*/
U32 SEGGER_SYSVIEW_X_GetTimestamp(void) {
U32 TickCount;
U32 Cycles;
U32 CyclesPerTick;
//
// Get the cycles of the current system tick.
// SysTick is down-counting, subtract the current value from the number of cycles per ti
//
CyclesPerTick = SYST_RVR + 1;
Cycles = (CyclesPerTick - SYST_CVR);
//
// Get the system tick count.
//
TickCount = SEGGER_SYSVIEW_TickCnt;
//
// If a SysTick interrupt is pending increment the TickCount
//
if ((SCB_ICSR & SCB_ICSR_PENDSTSET_MASK) != 0) {
TickCount++;
}
Cycles += TickCount * CyclesPerTick;
return Cycles;
}
7.2.2
Cortex-M0 Interrupt ID
The currently active interrupt can be directly identified by reading the Cortex-M ICSR[5:0],
which is the active vector field in the interrupt controller status register (ICSR).
Configuration:
//
// Get the interrupt Id by reading the Cortex-M ICSR[5:0]
//
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID()
((*(U32 *)(0xE000ED04)) & 0x3F)
7.2.3
Locking and unlocking SystemView to prevent transferring records from being interrupted
can be done by disabling interrupts.
Lock and unlock for SystemView and RTT can be the same.
Configuration:
//
// RTT locking for GCC toolchains in SEGGER_RTT_Conf.h
//
#define SEGGER_RTT_LOCK()
{
unsigned int LockState;
__asm volatile ("mrs
%0, primask \n\t"
"mov
r1, $1
\n\t"
"msr
primask, r1 \n\t"
: "=r" (LockState)
:
: "r1"
);
#define SEGGER_RTT_UNLOCK()
\n\t"
\
\
\
\
\
\
\
\
\
\
\
\
\
68
CHAPTER 7
//
// Define SystemView locking in SEGGER_SYSVIEW_Conf.h
//
#define SEGGER_SYSVIEW_LOCK()
SEGGER_RTT_LOCK()
#define SEGGER_SYSVIEW_UNLOCK() SEGGER_RTT_UNLOCK()
7.2.4
SEGGER_SYSVIEW_Conf.h
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
: SEGGER_SYSVIEW_Conf.h
: SEGGER SysView configuration for Cortex-M0, Cortex-M0+,
and Cortex-M1
*/
#ifndef SEGGER_SYSVIEW_CONF_H
#define SEGGER_SYSVIEW_CONF_H
/*********************************************************************
*
*
SysView timestamp configuration
*/
// Retrieve a system timestamp via user-defined function
#define SEGGER_SYSVIEW_GET_TIMESTAMP()
SEGGER_SYSVIEW_X_GetTimestamp()
// number of valid bits low-order delivered by SEGGER_SYSVIEW_X_GetTimestamp()
#define SEGGER_SYSVIEW_TIMESTAMP_BITS
32
/*********************************************************************
*
*
SysView Id configuration
*/
// Default value for the lowest Id reported by the application.
// Can be overridden by the application via SEGGER_SYSVIEW_SetRAMBase().
#define SEGGER_SYSVIEW_ID_BASE
0x20000000
// Number of bits to shift the Id to save bandwidth.
// (i.e. 2 when all reported Ids (pointers) are 4 byte aligned)
#define SEGGER_SYSVIEW_ID_SHIFT
0
/*********************************************************************
*
*
SysView interrupt configuration
*/
// Get the currently active interrupt Id. (read Cortex-M ICSR[8:0] = active vector)
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID()
((*(U32 *)(0xE000ED04)) & 0x3F)
/*********************************************************************
*
*
SysView locking
*/
// Lock SysView (nestable)
#define SEGGER_SYSVIEW_LOCK()
SEGGER_RTT_LOCK()
// Unlock SysView (nestable)
#define SEGGER_SYSVIEW_UNLOCK()
SEGGER_RTT_UNLOCK()
#endif
/*************************** End of file ****************************/
SEGGER_SYSVIEW_Config_NoOS_CM0.c
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
69
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
: SEGGER_SYSVIEW_Config_NoOS_CM3.c
: Sample setup configuration of SystemView without an OS
for ARM Cortex-M0, Cortex-M0+ and Cortex-M1 targets.
*/
#include "SEGGER_SYSVIEW.h"
// SystemcoreClock can be used in most CMSIS compatible projects.
// In non-CMSIS projects define SYSVIEW_CPU_FREQ below.
extern unsigned int SystemCoreClock;
/*********************************************************************
*
*
Defines, configurable
*
**********************************************************************
*/
// The application name to be displayed in SystemViewer
#define SYSVIEW_APP_NAME
"Demo Application"
// The target device name
#define SYSVIEW_DEVICE_NAME
"Cortex-M0"
70
CHAPTER 7
*
SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are
*
disabled. Therefore locking here is not required.
*/
U32 SEGGER_SYSVIEW_X_GetTimestamp(void) {
U32 TickCount;
U32 Cycles;
U32 CyclesPerTick;
//
// Get the cycles of the current system tick.
// SysTick is down-counting, subtract the current value from the number of cycles per tick.
//
CyclesPerTick = SYST_RVR + 1;
Cycles = (CyclesPerTick - SYST_CVR);
//
// Get the system tick count.
//
TickCount = SEGGER_SYSVIEW_TickCnt;
//
// If a SysTick interrupt is pending increment the TickCount
//
if ((SCB_ICSR & SCB_ICSR_PENDSTSET_MASK) != 0) {
TickCount++;
}
Cycles += TickCount * CyclesPerTick;
return Cycles;
}
void SEGGER_SYSVIEW_Conf(void) {
SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ,
0, _cbSendSystemDesc);
SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
}
/*************************** End of file ****************************/
71
7.3
Cortex-A / Cortex-R
Recording mode
Supported?
Continuous recording
Yes/NO
Single-shot recording
Yes
Post-mortem analysis
Yes
Continuous recording is only supported on Cortex-A / Cortex-R devices, which support RTT
via background memory access via the AHB-AP. For more information please refer to the
J-Link User Manual and website.
7.3.1
The Cortex-A and Cortex-R cycle counter is implemented only as part of the Performance
Monitor Extension and might not always be accessible. Cortex-A and Cortex-R do not have
a generic system timer source, like the Cortex-M SysTick, either.
For an example on how to initialize the Performance counter, refer to TI AM3358 CortexA8 sample configuration on page 77.
Otherwise the event timestamp has to be provided by an application clock source. Refer to
Renesas RZA1 Cortex-A9 sample configuration on page 74.
For the clock source any suitable timer can be used. It is recommended to use the OS system
timer if possible, since it normally saves additional configuration and resource usage. If
no timer is used in the application, a suitable timer has to be configured to be used with
SystemView.
Some OSes implement API functions to get the OS time in cycles. If such a function
is available it can be used directly or wrapped by SEGGER_SYSVIEW_X_GetTimestamp()
If the OS does not provide functionality to retrieve the OS time in cycles,
SEGGER_SYSVIEW_X_GetTimestamp() has to be implemented to get the timestamp from
the timer.
Dummy configuration:
//
// SEGGER_SYSVIEW_TickCnt has to be defined in the module which
// handles interrupts and must be incremented in the interrupt
// handler as soon as the timer interrupt is acknowledged and
// before any SYSVIEW event is generated.
//
// Example:
//
// unsigned int SEGGER_SYSVIEW_TickCnt; // <<-- Define SEGGER_SYSVIEW_TickCnt.
// void OS_irq_handler(void) {
//
U32 InterruptId;
//
InterruptId = INTC_ICCIAR & 0x3FF; // read and extract the interrupt ID
//
if (InterruptId == TIMER_TICK_ID) {
//
SEGGER_SYSVIEW_TickCnt++; // <<-- Increment SEGGER_SYSVIEW_TickCnt asap.
//
}
//
SEGGER_SYSVIEW_InterruptId
= InterruptId; // Save active interrupt for SystemView event
//
SEGGER_SYSVIEW_RecordEnterISR();
//
//
//
// Handle interrupt, call ISR
//
//
//
SEGGER_SYSVIEW_RecordExitISR();
// }
//
extern unsigned int SEGGER_SYSVIEW_TickCnt;
72
CHAPTER 7
Cortex-A / Cortex-R
/*********************************************************************
*
*
Defines, fixed
*
**********************************************************************
*/
//
// Define the required timer registers here.
//
#define TIMER_RELOAD_VALUE
/* as value which is used to initialize and
reload the timer */
#define TIMER_COUNT
/* as timer register which holds the current
counter value */
#define TIMER_INTERRUPT_PENDING() /* as check if a timer interrupt is pending */
/*********************************************************************
*
*
SEGGER_SYSVIEW_X_GetTimestamp()
*
* Function description
*
Returns the current timestamp in ticks using the system tick
*
count and the SysTick counter.
*
All parameters of the SysTick have to be known and are set via
*
configuration defines on top of the file.
*
* Return value
*
The current timestamp.
*
* Additional information
*
SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are
*
disabled. Therefore locking here is not required.
*/
U32 SEGGER_SYSVIEW_X_GetTimestamp(void) {
U32 TickCount;
U32 Cycles;
U32 CyclesPerTick;
//
// Get the cycles of the current system tick.
// Sample timer is down-counting,
// subtract the current value from the number of cycles per tick.
//
CyclesPerTick = TIMER_RELOAD_VALUE + 1;
Cycles = (CyclesPerTick - TIMER_COUNT);
//
// Get the system tick count.
//
TickCount = SEGGER_SYSVIEW_TickCnt;
//
// Check if a timer interrupt is pending
//
if (TIMER_INTERRUPT_PENDING()) {
TickCount++;
Cycles = (CyclesPerTick - TIMER_COUNT);
}
Cycles += TickCount * CyclesPerTick;
return Cycles;
}
7.3.2
Cortex-A/R Interrupt ID
As the Cortex-A and Cortex-R core does not have an internal interrupt controller, retrieving
the currently active interrrupt Id depends on the interrupt controller, which is used on the
target device. SEGGER_SYSVIEW_GET_INTERRUPT_ID() needs to be implemented to match
this interrupt controller.
73
The configuration below shows how to get the interrupt Id on devices, which include the
ARM Generic Interrupt Controller (GIC).
For other interrupt controllers the operation may vary. Refer to TI AM3358 Cortex-A8 sample
configuration on page 77.
Since the active interrupt Id can only be retrieved from the GIC in connection with an
acknowledge of the interrupt it can only be read once. Therefore the Id has to be stored in
a variable when acknowledging it in the generic interrupt handler.
Dummy configuration:
//
// SEGGER_SYSVIEW_InterruptId has to be defined in the module which
// handles the interrupts and must be set to the acknowledged interrupt Id.
//
// Example:
//
// #define GIC_BASE_ADDR
/* as base address of the GIC on the device */
// #define GICC_BASE_ADDR (GIC_BASE_ADDR + 0x2000u)
// #define GICC_IAR
(*(volatile unsigned*)(GICC_BASE_ADDR + 0x000C))
//
// unsigned int SEGGER_SYSVIEW_InterruptId; //
<<-- Define SEGGER_SYSVIEW_InterruptId.
// void OS_irq_handler(void) {
//
//
int_id = GICC_IAR & 0x03FF; // Read interrupt ID, acknowledge interrupt
//
SEGGER_SYSVIEW_InterruptId = iar_val;
//
OS_EnterInterrupt();
// Inform OS that interrupt handler is running
//
pISR();
// Call interrupt service routine
//
OS_LeaveInterrupt();
// Leave interrupt, perform task switch if required
// }
//
extern unsigned int SEGGER_SYSVIEW_InterruptId;
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID()
7.3.3
(SEGGER_SYSVIEW_InterruptId)
As the Cortex-A and Cortex-R core does not have an internal interrupt controller, locking
and unlocking SystemView to prevent transferring records from being interrupted can
be done generic by disabling FIQ and IRQ completely, or by using interrupt controller
specific methods. The configuration below shows how to disable all interrupts for RTT and
SystemView.
Lock and unlock for SystemView and RTT can be the same.
Configuration:
//
// RTT locking for GCC toolchains in SEGGER_RTT_Conf.h
// Set and restore IRQ and FIQ mask bits.
//
#define SEGGER_RTT_LOCK()
{
unsigned int LockState;
__asm volatile ("mrs r1, CPSR
"mov %0, r1
"orr r1, r1, #0xC0
"msr CPSR_c, r1
: "=r" (LockState)
:
: "r1"
);
#define SEGGER_RTT_UNLOCK()
r0,
r1,
r1,
r0,
%0
CPSR
r1, #0xC0
r0, #0xC0
\n\t"
\n\t"
\n\t"
\n\t"
\n\t"
\n\t"
\n\t"
\n\t"
\
\
\
\
\
\
\
\
\
\
\
\
\
74
CHAPTER 7
Cortex-A / Cortex-R
"orr r1, r1, r0
"msr CPSR_c, r1
:
: "r" (LockState)
: "r0", "r1"
);
\n\t"
\n\t"
\
\
\
\
\
\
}
//
// Define SystemView locking in SEGGER_SYSVIEW_Conf.h
//
#define SEGGER_SYSVIEW_LOCK()
SEGGER_RTT_LOCK()
#define SEGGER_SYSVIEW_UNLOCK() SEGGER_RTT_UNLOCK()
7.3.4
This sample configuration for the Renesas RZA1 (R7S72100) retrieves the currently active
interrupt and the system tick counter from embOS.
It uses the OS Timer for timestamp generation. The RZA1 includes a GIC.
SEGGER_SYSVIEW_Conf.h
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
: SEGGER_SYSVIEW_Conf.h
: SEGGER SysView configuration for Renesas RZA1 Cortex-A9
with SEGGER embOS.
*/
#ifndef SEGGER_SYSVIEW_CONF_H
#define SEGGER_SYSVIEW_CONF_H
/*********************************************************************
*
*
SysView buffer configuration
*/
// Number of bytes that SysView uses for the buffer.
// Should be large enough for single-shot recording.
#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE
1024 * 1024
// The RTT channel that SysView will use.
#define SEGGER_SYSVIEW_RTT_CHANNEL
1
/*********************************************************************
*
*
SysView timestamp configuration
*/
// Retrieve a system timestamp via OS-specific function
#define SEGGER_SYSVIEW_GET_TIMESTAMP()
SEGGER_SYSVIEW_X_GetTimestamp()
// number of valid bits low-order delivered by SEGGER_SYSVIEW_X_GetTimestamp()
#define SEGGER_SYSVIEW_TIMESTAMP_BITS
32
/*********************************************************************
*
*
SysView interrupt configuration
*/
//
// SEGGER_SYSVIEW_InterruptId has to be defined in the module which
// handles the interrupts and must be set to the acknowledged interrupt Id.
//
// Example:
//
// #define GIC_BASE_ADDR
/* as base address of the GIC on the device */
// #define GICC_BASE_ADDR (GIC_BASE_ADDR + 0x2000u)
// #define GICC_IAR
(*(volatile unsigned*)(GICC_BASE_ADDR + 0x000C))
75
//
// unsigned int SEGGER_SYSVIEW_InterruptId; //
<<-- Define SEGGER_SYSVIEW_InterruptId.
// void OS_irq_handler(void) {
//
//
int_id = GICC_IAR & 0x03FF; // Read interrupt ID, acknowledge interrupt
//
SEGGER_SYSVIEW_InterruptId = iar_val;
//
OS_EnterInterrupt();
// Inform OS that interrupt handler is running
//
pISR();
// Call interrupt service routine
//
OS_LeaveInterrupt();
// Leave interrupt, perform task switch if required
// }
//
extern unsigned int SEGGER_SYSVIEW_InterruptId;
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID()
(SEGGER_SYSVIEW_InterruptId)
/*********************************************************************
*
*
SysView locking
*/
// Lock SysView (nestable)
#define SEGGER_SYSVIEW_LOCK()
SEGGER_RTT_LOCK()
// Unlock SysView (nestable)
#define SEGGER_SYSVIEW_UNLOCK()
SEGGER_RTT_UNLOCK()
#endif
/*************************** End of file ****************************/
SEGGER_SYSVIEW_Config_embOS_RZA1.c
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
: SEGGER_SYSVIEW_Config_embOS_RZA1.c
: Sample setup configuration of SystemView with embOS
for Renesas RZA1 Cortex-A9.
*/
#include "RTOS.h"
#include "SEGGER_SYSVIEW.h"
#include "SEGGER_SYSVIEW_embOS.h"
// SystemcoreClock can be used in most CMSIS compatible projects.
// In non-CMSIS projects define SYSVIEW_CPU_FREQ below.
extern unsigned int SystemCoreClock;
/*********************************************************************
*
*
Defines, configurable
*
**********************************************************************
*/
// The application name to be displayed in SystemViewer
#define SYSVIEW_APP_NAME
"embOS Demo Application"
// The target device name
#define SYSVIEW_DEVICE_NAME
"R7S72100"
76
CHAPTER 7
Cortex-A / Cortex-R
/*********************************************************************
*
*
_cbSendSystemDesc()
*
* Function description
*
Sends SystemView description strings.
*/
static void _cbSendSystemDesc(void) {
SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME);
}
/*********************************************************************
*
*
Global functions
*
**********************************************************************
*/
void SEGGER_SYSVIEW_Conf(void) {
SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ,
&SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc);
SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
OS_SetTraceAPI(&embOS_TraceAPI_SYSVIEW);
// Configure embOS to use SYSVIEW.
}
/*********************************************************************
*
*
SEGGER_SYSVIEW_X_GetTimestamp()
*
* Function description
*
Returns the current timestamp in ticks using the system tick
*
count and the SysTick counter.
*
All parameters of the SysTick have to be known and are set via
*
configuration defines on top of the file.
*
* Return value
*
The current timestamp.
*
* Additional information
*
SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are
*
disabled. Therefore locking here is not required.
*/
U32 SEGGER_SYSVIEW_X_GetTimestamp(void) {
U32 TickCount;
U32 Cycles;
U32 CyclesPerTick;
//
// Get the cycles of the current system tick.
// Sample timer is down-counting,
// subtract the current value from the number of cycles per tick.
//
CyclesPerTick = 33249 + 1;
Cycles = (CyclesPerTick - OSTM_CNT);
//
// Get the system tick count.
//
TickCount = SEGGER_SYSVIEW_TickCnt;
//
// Check if a timer interrupt is pending
//
if (TIMER_INTERRUPT_PENDING()) {
TickCount++;
SEGGER SystemView User Guide
77
Cycles = (CyclesPerTick - OSTM_CNT);
}
Cycles += TickCount * CyclesPerTick;
return Cycles;
}
/*************************** End of file ****************************/
7.3.5
This sample configuration for the TI AM3358 retrieves the currently active interrupt directly.
It initializes and uses the Cortex-A performance counter for timestamp generation.
The SystemView timestmap generation can be used for other Cortex-A devices, which
include the performance counter unit.
SEGGER_SYSVIEW_Conf.h
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
: SEGGER_SYSVIEW_Conf.h
: Generic SEGGER SysView configuration for non-Cortex-M
devices.
*/
#ifndef SEGGER_SYSVIEW_CONF_H
#define SEGGER_SYSVIEW_CONF_H
/*********************************************************************
*
*
SysView timestamp configuration
*/
// Retrieve a system timestamp via user-defined function
#define SEGGER_SYSVIEW_GET_TIMESTAMP()
SEGGER_SYSVIEW_X_GetTimestamp()
// number of valid bits low-order delivered by SEGGER_SYSVIEW_X_GetTimestamp()
#define SEGGER_SYSVIEW_TIMESTAMP_BITS
32
/*********************************************************************
*
*
SysView Id configuration
*/
// Default value for the lowest Id reported by the application.
// Can be overridden by the application via SEGGER_SYSVIEW_SetRAMBase().
#define SEGGER_SYSVIEW_ID_BASE
0
// Number of bits to shift the Id to save bandwidth.
// (i.e. 2 when all reported Ids (pointers) are 4 byte aligned)
#define SEGGER_SYSVIEW_ID_SHIFT
0
/*********************************************************************
*
*
SysView interrupt configuration
*/
#define SEGGER_SYSVIEW_GET_INTERRUPT_ID()
SEGGER_SYSVIEW_X_GetInterruptId()
/*********************************************************************
*
*
SysView locking
*/
// Lock SysView (nestable)
#define SEGGER_SYSVIEW_LOCK()
SEGGER_RTT_LOCK()
// Unlock SysView (nestable)
#define SEGGER_SYSVIEW_UNLOCK()
SEGGER_RTT_UNLOCK()
#endif
78
CHAPTER 7
Cortex-A / Cortex-R
SEGGER_SYSVIEW_Config_embOS_AM3358.c
/*********************************************************************
*
(c) SEGGER Microcontroller GmbH & Co. KG
*
**********************************************************************
-------------------------- END-OF-HEADER ----------------------------File
Purpose
: SEGGER_SYSVIEW_Config_embOS_RZA1.c
: Sample setup configuration of SystemView with embOS
for TI AM3358 Cortex-A8.
*/
#include "RTOS.h"
#include "SEGGER_SYSVIEW.h"
#include "SEGGER_SYSVIEW_embOS.h"
//
// SystemcoreClock can be used in most CMSIS compatible projects.
// In non-CMSIS projects define SYSVIEW_CPU_FREQ directly.
//
extern unsigned int SystemCoreClock;
/*********************************************************************
*
*
Defines, configurable
*
**********************************************************************
*/
// The application name to be displayed in SystemViewer
#ifndef
SYSVIEW_APP_NAME
#define SYSVIEW_APP_NAME
"embOS start project"
#endif
// The target device name
#ifndef
SYSVIEW_DEVICE_NAME
#define SYSVIEW_DEVICE_NAME
#endif
"AM3358"
"I#67=SysTick,I#18=USB,I#17=USBSS,I#36=LCDC"
#define INTC_BASE
#define INTC_SIR_IRQ
(0x48200000uL)
(*(volatile U32*) (INTC_BASE + 0x40uL))
/*********************************************************************
*
*
Local functions
*
**********************************************************************
*/
/*********************************************************************
*
SEGGER SystemView User Guide
79
*
_cbSendSystemDesc()
*
* Function description
*
Sends SystemView description strings.
*/
static void _cbSendSystemDesc(void) {
SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",O=embOS,D="SYSVIEW_DEVICE_NAME);
#ifdef SYSVIEW_SYSDESC0
SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC0);
#endif
#ifdef SYSVIEW_SYSDESC1
SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC1);
#endif
#ifdef SYSVIEW_SYSDESC2
SEGGER_SYSVIEW_SendSysDesc(SYSVIEW_SYSDESC2);
#endif
}
/*********************************************************************
*
*
_InitPerformanceCounter
*
* Function description
*
Initialize the internal Cortex-A Performance counter.
*
The function will work for Cortex-A8, Cortex-A9.
*
Please check whether this also suites for your core.
*/
static void _InitPerformanceCounter(U32 PerformReset, I32 UseDivider) {
//
// in general enable all counters (including cycle counter)
//
I32 Value = 1;
//
// Peform reset:
//
if (PerformReset) {
Value |= 2;
// reset all counters to zero.
Value |= 4;
// reset cycle counter to zero.
}
if (UseDivider) {
Value |= 8;
// enable "by 64" divider for CCNT.
}
Value |= 16;
// program the performance-counter control-register:
__asm volatile ("MCR p15, 0, %0, c9, c12, 0\t\n"
:
// Output result
: "r"(Value)
// Input
:
// Clobbered list
);
//
// Enable all counters
//
__asm volatile ("MCR p15, 0, %0, c9, c12, 1\t\n"
:
// Output result
: "r"(0x8000000f) // Input
:
// Clobbered list
);
//
// Clear overflows
//
__asm volatile ("MCR p15, 0, %0, c9, c12, 3\t\n"
:
// Output result
: "r"(0x8000000f) // Input
:
// Clobbered list
);
SEGGER SystemView User Guide
80
CHAPTER 7
Cortex-A / Cortex-R
}
/*********************************************************************
*
*
Global functions
*
**********************************************************************
*/
/*********************************************************************
*
*
SEGGER_SYSVIEW_Conf
*
* Function description
*
Configures SYSVIEW.
*
*
Please check whether this also suites for your core.
*/
void SEGGER_SYSVIEW_Conf(void) {
//
// Write USEREN Register
//
__asm volatile ("MCR p15, 0, %0, C9, C14, 0\n\t"
:
// Output result
: "r"(1)
// Input
:
// Clobbered list
);
//
// Disable counter overflow interrupts
//
__asm volatile ("MCR p15, 0, %0, C9, C14, 2\n\t"
:
// Output result
: "r"(0x8000000f) // Input
:
// Clobbered list
);
_InitPerformanceCounter(1, 0);
SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ,
&SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc);
SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
OS_SetTraceAPI(&embOS_TraceAPI_SYSVIEW);
// Configure embOS to use SYSVIEW.
}
/*********************************************************************
*
*
SEGGER_SYSVIEW_X_GetTimestamp()
*
* Function description
*
Returns the current timestamp in ticks using the performance counter.
*
* Return value
*
The current timestamp.
*
* Additional information
*
SEGGER_SYSVIEW_X_GetTimestamp is always called when interrupts are
*
disabled. Therefore locking here is not required.
*/
U32 SEGGER_SYSVIEW_X_GetTimestamp(void) {
register U32 r = 0;
//
// Read CCNT Register
//
__asm volatile ("MRC p15, 0, %0, c9, c13, 0"
: "+r"(r)
// Output result
:
// Inputs
: );
// Clobbered list
return r;
}
SEGGER SystemView User Guide
81
/*********************************************************************
*
*
SEGGER_SYSVIEW_X_GetInterruptId()
*
* Function description
*
Return the currently active IRQ interrupt number
*
from the INTC_SIR_IRQ.
*/
U32 SEGGER_SYSVIEW_X_GetInterruptId(void) {
return (INTC_SIR_IRQ & (0x7Fu)); // INTC_SIR_IRQ[6:0]: ActiveIRQ
}
82
CHAPTER 7
7.4
Other CPUs
Other CPUs
Recording mode
Supported?
Continuous recording
No
Single-shot recording
Yes
Post-mortem analysis
Yes
On CPUs, which are not covered by the sections above SystemView can be used in singleshot mode, too.
To properly run SystemView the same items have to be configured:
83
Chapter 8
Supported OSes
The following chapter describes which (RT)OSes are already instrumented to use SystemView
and how to configure them.
84
CHAPTER 8
8.1
embOS
embOS
SEGGER embOS (V4.12a and later) can generate trace events for SystemView and other
recording implementations when profiling is enabled.
8.1.1
target
is
initialized,
Now, when the application is running, SystemViewer can connect to the target and start
recording events. All task, interrupt, and OS Scheduler activity, as well as embOS API
calls are recorded when SystemViewer is connected or SEGGER_SYSVIEW_Start() has been
called.
85
8.2
uC/OS-III
SystemView can be used with Micriums uC/OS-III to record task, interrupt, and scheduler
activity.
8.2.1
In addition to the SYSTEMVIEW and RTT core module the following files have to be included
in the application project:
SEGGER_SYSVIEW_Config_uCOSIII.c provides additionally required functions for
SystemView and allows configuration to fit the target system, like defines for the application
name, the target device and the target core frequency. The example configuration file,
shipped with the SystemView package is configured to be used with most Cortex-M3,
Cortex-M4, and Cortex-M7 targets. For an example configuration, refer to The SystemView
system information config on page 48.
SEGGER_SYSVIEW_uCOSIII.c and os_trace.h provide the interface between uC/OS-III and
SystemView. They usually do not need to be modified.
os_cfg_trace.h is the minimal uc/OS-III Trace configuration file required for SystemView.
If the project already includes this file, make sure the content fits the application. This file
includes two defines to configure the maximum number of tasks and the maximum number
of resources to be managed and named in the SystemView recording.
#define
#define
TRACE_CFG_MAX_TASK
TRACE_CFG_MAX_RESOURCES
16u
16u
Enable recording
Recording of uC/OS-III events can be configured in os_cfg.h.
Define OS_CFG_TRACE_EN as 1u to enable basic recording.
When OS_CFG_TRACE_API_ENTER_EN is defined as 1u, API function calls will be recorded,
too.
To also record when an API function exits, define OS_CFG_TRACE_API_EXIT_EN as 1u as well.
Call TRACE_INIT() at the beginning of the application, after the system has been initialized:
[...]
BSP_Init(); /* Initialize BSP functions
*/
CPU_Init(); /* Initialize the uC/CPU services */
#if (defined(OS_CFG_TRACE_EN) && (OS_CFG_TRACE_EN > 0u))
/* Initialize uC/OS-III Trace. Should be called after initializing the system.
*/
TRACE_INIT();
#endif
[...]
86
CHAPTER 8
8.3
FreeRTOS
FreeRTOS
FreeRTOS can also generate trace events for SystemView and allows basic but useful
analysis without modification.
For more detailed analysis, like Scheduler activity and interrupts, the FreeRTOS source and
the used port have to be slightly modified.
8.3.1
In
addition
to
the
SYSTEMVIEW
and
RTT
core
module,
SEGGER_SYSVIEW_Config_FreeRTOS.c needs to be included in the application. This file
provides additionally required functions for SystemView and allows configuration to fit the
target system, like defines for the application name, the target device and the target core
frequency. For an example configuration, refer to The SystemView system information
config on page 48.
The SEGGER_SYSVIEW_FreeRTOS.h header has to be included at the end of
FreeRTOSConfig.h or above every include of FreeRTOS.h. It defines the trace macros to
create SYSTEMVIEW events..
To
get
the
best
results
INCLUDE_xTaskGetIdleTaskHandle
INCLUDE_pxTaskGetStackStart should be defined as 1 in FreeRTOSConfig.h.
and
The patch file Sample.2.3_Core.patch shows the required modifications of the FreeRTOS
8.2.3 source and the GCC/ARM_CM4F port. It can be used as a reference when using
another version or port of FreeRTOS. I.e. if another port than GCC/ARM_CM4F is used, the
traceISR_ENTER(), traceISR_EXIT(), and traceISR_EXIT_TO_SCHEDULER() calls have to
be added accordingly.
87
8.4
Other OSes
Other OSes are not officially instrumented, yet.
If you want to use SystemView with an other OS, get it touch with SEGGER or the OS
Vendor. The OS instrumentation can also be done with the guide in the following chapter.
88
CHAPTER 8
8.5
No OS
No OS
SystemView can be used without any instrumented OS at all, to record interrupt activity
and user events.
8.5.1
89
Chapter 9
Performance and resource usage
This chapter covers the performance and resource usage of SystemView. It contains information
about the memory requirements in typical systems which can be used to obtain sufficient
estimates for most target systems.
90
CHAPTER 9
9.1
Memory requirements
Memory requirements
The memory requirements may differ, depending on the used OS integration, the target
configuration and the compiler optimizations.
To achieve a balanced result of performance and memory usage, it is recommended to set
the compiler optimization level for the SystemView and RTT module accordingly. Compiler
optimizations should always be switched on for the SystemView and RTT module - even
in Debug configuration builds.
9.1.1
ROM usage
The following table lists the ROM usage of SystemView by component. With a smart linker
only the used functions will be included in the application.
Description
ROM
~920Byte
~380Byte
~360Byte
~120Byte
~1.8KByte
The following table list the ROM usage of SystemView with different configurations.
Description
Configuration
ROM
SystemView Module
~1.8KByte
SystemView Module
~2.1KByte
SystemView Module
~1.4KByte
SystemView Module
~1.7KByte
RTT Module
Balanced optimization
~0.5KByte
9.1.2
The following table list the static RAM usage of SystemView with different configurations.
Description
Configuration
RAM
SystemView Module
No static buffer
~70Byte +
Channel Buffer
SystemView Module
Static buffer
~280Byte +
Channel Buffer
SystemView Module
~60Byte +
Channel Buffer
SystemView Module
~180Byte +
Channel Buffer
RTT Module
9.1.3
~30Byte +
Channel Buffer
SystemView requires stack to record events in every context, which might record events in
the application. This typically includes the system stack used by the scheduler, the interrupt
stack and the task stacks.
91
Since SystemView handles incoming requests for the system description and task
information, there must be enough free space on the stack to record an event and to send
the system description, which is recording another event.
SystemView can be configured to select between lower stack usage or less static RAM use.
Description
Maximum Stack
~230 Bytes
~510 Bytes
~150 Bytes
~280 Bytes
92
CHAPTER 9
Memory requirements
93
Chapter 10
Integration guide
This section describes how to integrate SEGGER SystemView into an OS or middleware module
to be able to record its execution.
94
CHAPTER 10
For integration into other OSes, contact the OS distributor or do the integration following
the instructions in this sections.
The examples in this section are pseudo-code to illustrate when to call specific SystemView
functions. To allow general integration of trace instrumentation tools calls to these functions
can also be integrated as function macros or via a configurable trace API.
Description
SystemView API
Task Create
SEGGER_SYSVIEW_OnTaskCreate on
page 123
A task is marked as
ready to start or resume
execution.
SEGGER_SYSVIEW_OnTaskStartReady
on page 125
SEGGER_SYSVIEW_OnTaskStartExec
on page 124
A task is blocked or
suspended.
SEGGER_SYSVIEW_OnTaskStopReady
on page 127
A task terminates.
SEGGER_SYSVIEW_OnTaskStopExec
on page 126
System Idle
95
Example
void OS_CreateTask(TaskFunc* pF, unsigned Prio, const char* sName, void* pStack) {
SEGGER_SYSVIEW_TASKINFO Info;
OS_TASK*
pTask; // Pseudo struct to be replaced
[OS specific code ...]
SEGGER_SYSVIEW_OnTaskCreate((unsigned)pTask);
memset(&Info, 0, sizeof(Info));
//
// Fill elements with current task information
//
Info.TaskID
= (U32)pTask;
Info.sName
= pTask->Name;
Info.Prio
= pTask->Priority;
Info.StackBase = (U32)pTask->pStack;
Info.StackSize = pTask->StackSize;
SEGGER_SYSVIEW_SendTaskInfo(&Info);
}
Example
int OS_HandleTick(void) {
int TaskReady = 0;
// Pseudo variable indicating a task is ready
[OS specific code ...]
if (TaskReady) {
SEGGER_SYSVIEW_OnTaskStartReady((unsigned)pTask);
}
}
Example
void OS_Switch(void) {
[OS specific code ...]
//
// If a task is activated
//
SEGGER_SYSVIEW_OnTaskStartExec((unsigned)pTask);
//
// Else no task activated, go into idle state
//
SEGGER_SYSVIEW_OnIdle()
}
96
CHAPTER 10
Example
void OS_Delay(unsigned NumTicks) {
[OS specific code ...]
SEGGER_SYSVIEW_OnTaskStopReady(OS_Global.pCurrentTask, OS_CAUSE_WAITING);
}
Example
void OS_TerminateTask(void) {
[OS specific code ...]
SEGGER_SYSVIEW_OnTaskStopExec();
}
Example
void OS_Switch(void) {
[OS specific code ...]
//
// If a task is activated
//
SEGGER_SYSVIEW_OnTaskStartExec((unsigned)pTask);
//
// Else no task activated, go into idle state
//
SEGGER_SYSVIEW_OnIdle()
}
97
ID
in
Example
void OS_EnterInterrupt(void) {
[OS specific code ...]
SEGGER_SYSVIEW_RecordEnterISR();
}
Example
void OS_ExitInterrupt(void) {
[OS specific code ...]
//
// If the interrupt will switch to the Scheduler
//
SEGGER_SYSVIEW_RecordExitISRToScheduler();
//
// Otherwise
//
SEGGER_SYSVIEW_RecordExitISR();
}
98
CHAPTER 10
OS_EnterInterrupt();
//
// Interrupt functionality could be here
//
APP_TimerCnt++;
//
// Inform OS about end of interrupt execution
// (records SystemView Exit Interrupt event).
//
OS_ExitInterrupt();
}
but
is
recommended
to
allow
SEGGER_SYSVIEW_OS_API
typedef struct {
U64 (*pfGetTime)
(void);
void (*pfSendTaskList) (void);
} SEGGER_SYSVIEW_OS_API;
Parameters
Parameter
Description
pfGetTime
pfSendTaskList
10.1.3.1 pfGetTime
Description
Get the system time, i.e. the time since starting the system in microseconds.
If pfGetTime is NULL SystemViewer can show timestamps relative to the start of recording
only.
Prototype
U64 (*pfGetTime) (void);
99
10.1.3.2 pfSendTaskList
Description
Record the entire task list via SEGGER_SYSVIEW_SendTaskInfo().
If pfSendTaskList is NULL SystemViewer might only get task information of tasks which are
newly created while recording. pfSendTaskList is called periodically when SystemViewer is
connected to keep track on the current task list.
Prototype
void (*pfSendTaskList) (void);
Example
void cbSendTaskList(void) {
SEGGER_SYSVIEW_TASKINFO Info;
OS_TASK*
pTask;
OS_EnterRegion(); // Disable scheduling to make sure the task list does not change.
for (pTask = OS_Global.pTask; pTask; pTask = pTask->pNext) {
//
// Fill all elements with 0 to allow extending the structure
// in future version without breaking the code.
//
memset(&Info, 0, sizeof(Info));
//
// Fill elements with current task information
//
Info.TaskID
= (U32)pTask;
Info.sName
= pTask->Name;
Info.Prio
= pTask->Priority;
Info.StackBase = (U32)pTask->pStackBot;
Info.StackSize = pTask->StackSize;
//
// Record current task information
//
SEGGER_SYSVIEW_SendTaskInfo(&Info);
}
OS_LeaveRegion(); // Enable scheduling again.
}
Example
/*********************************************************************
*
*
OS_malloc()
*
* Function description
*
API function to allocate memory on the heap.
*/
void OS_malloc(unsigned Size) {
SEGGER_SYSVIEW_RecordU32(ID_OS_MALLOC, // Id of OS_malloc (>= 32)
Size
// First parameter
);
[OS specific code...]
}
100
CHAPTER 10
To record how long the execution of an API function takes and to record
its return value, the return of an API function can be instrumented, too
by calling SEGGER_SYSVIEW_RecordEndCall() to only record the return or
SEGGER_SYSVIEW_RecordEndCallReturnValue() to record the return and its return value.
<EventId> is the Id which is recorded for the API function. It can be in the range of 32
to 511.
<FunctionName> is the name of the API function, displayed in the Event column of
SystemViewer. It may not contain spaces.
<ParameterDescription> is the description string of the parameters which are recorded
with the API function.
<ReturnValueDescription> is the description string of the return value which can be
recorded with SystemView. The ReturnValueDescription is optional.
The parameter display can be configured by a set of modifiers:
Example
The following example shows a part of SYSVIEW_embOS.txt
35
42
43
44
45
46
OS_CheckTimer
OS_Delay
OS_DelayUntil
OS_setPriority
OS_WakeTask
OS_CreateTask
pGlobal=%p
Delay=%u
Time=%u
Task=%t Pri=%u
Task=%t
Task=%t Pri=%u Stack=%p Size=%u
In addition to the default modifiers the description file can define NamedTypes to map
numerical values to strings, which can for example be useful to display the textual value
of enums or error codes.
NamedTypes have following format:
NamedType <TypeName> <Key>=<Value> [<Key1>=<Value1> ...]
Example
#
# Types for parameter formatters
#
NamedType OSErr 0=OS_ERR_NONE
NamedType OSErr 10000=OS_ERR_A 10001=OS_ERR_ACCEPT_ISR
NamedType OSErr 12000=OS_ERR_C 12001=OS_ERR_CREATE_ISR
NamedType OSErr 13000=OS_ERR_D 13001=OS_ERR_DEL_ISR
101
NamedType OSFlag 0=FLAG_NONE 1=FLAG_READ 2=FLAG_WRITE 3=FLAG_READ_WRITE
#
# API Functions
#
34
OSFunc Param=%OSFlag | Returns %OSErr
Example
#
# Task States
#
TaskState 0xFF 0=Ready, 1=Delayed or Timeout, 2=Pending, 3=Pending with Timeout,
4=Suspended, 5=Suspended with Timeout, 6=Suspended and Pending, 7=Suspended and
Pending with Timeout, 255=Deleted
102
CHAPTER 10
Info.StackBase = (U32)pTask->pStack;
Info.StackSize = pTask->StackSize;
SEGGER_SYSVIEW_SendTaskInfo(&Info);
}
/*********************************************************************
*
*
OS_TerminateTask()
*
* Function description
*
Terminate a task and remove it from the system.
*/
void OS_TerminateTask(void) {
[OS specific code ...]
SEGGER_SYSVIEW_OnTaskStopExec();
}
/*********************************************************************
*
*
OS_Delay()
*
* Function description
*
Delay and suspend a task for the given time.
*/
void OS_Delay(unsigned NumTicks) {
[OS specific code ...]
SEGGER_SYSVIEW_OnTaskStopReady(OS_Global.pCurrentTask, OS_CAUSE_WAITING);
}
/*********************************************************************
*
*
OS_HandleTick()
*
* Function description
*
OS System Tick handler.
*/
int OS_HandleTick(void) {
int TaskReady = 0;
// Pseudo variable indicating a task is ready
[OS specific code ...]
if (TaskReady) {
SEGGER_SYSVIEW_OnTaskStartReady((unsigned)pTask);
}
}
/*********************************************************************
*
*
OS_Switch()
*
* Function description
*
Switch to the next ready task or go to idle.
*/
void OS_Switch(void) {
[OS specific code ...]
//
// If a task is activated
//
SEGGER_SYSVIEW_OnTaskStartExec((unsigned)pTask);
//
// Else no task activated, go into idle state
//
SEGGER SystemView User Guide
103
SEGGER_SYSVIEW_OnIdle()
}
/*********************************************************************
*
*
OS_EnterInterrupt()
*
* Function description
*
Inform the OS about start of interrupt execution.
*/
void OS_EnterInterrupt(void) {
[OS specific code ...]
SEGGER_SYSVIEW_RecordEnterISR();
}
/*********************************************************************
*
*
OS_ExitInterrupt()
*
* Function description
*
Inform the OS about end of interrupt execution and switch to
*
Scheduler if necessary.
*/
void OS_ExitInterrupt(void) {
[OS specific code ...]
//
// If the interrupt will switch to the Scheduler
//
SEGGER_SYSVIEW_RecordExitISRToScheduler();
//
// Otherwise
//
SEGGER_SYSVIEW_RecordExitISR();
}
104
CHAPTER 10
SEGGER_SYSVIEW_MODULE
struct SEGGER_SYSVIEW_MODULE {
const char*
U32
U32
void
SEGGER_SYSVIEW_MODULE*
};
sModule;
NumEvents;
EventOffset;
(*pfSendModuleDesc)(void);
pNext;
Parameters
Parameter
Description
sModule
NumEvents
EventOffset
pfSendModuleDesc
pNext
Example
SEGGER_SYSVIEW_MODULE IPModule = {
"M=embOSIP, " \
"0 SendPacket IFace=%u NumBytes=%u, " \
"1 ReceivePacket Iface=%d NumBytes=%u", // sModule
2,
// NumEvents
0,
// EventOffset, Set by SEGGER_SYSVIEW_RegisterModule()
NULL,
// pfSendModuleDesc, NULL: No additional module description
NULL,
// pNext, Set by SEGGER_SYSVIEW_RegisterModule()
};
105
static void _IPTraceConfig(void) {
//
// Register embOS/IP at SystemView.
// SystemView has to be initialized before.
//
SEGGER_SYSVIEW_RegisterModule(&IPModule);
}
Example
int SendPacket(IP_PACKET *pPacket) {
//
// The IP stack sends a packet.
// Record it according to the module description of SendPacket.
//
SEGGER_SYSVIEW_RecordU32x2(
// Id of SendPacket (0) + Offset for the registered module
ID_SENDPACKET + IPModule.EventOffset,
// First parameter (displayed as event parameter IFace)
pPacket->Interface,
// Second parameter (displayed as event parameter NumBytes)
pPacket->NumBytes
);
[Module specific code...]
}
For more information refer to Recording OS API calls on page 99 and the API reference
on page 107.
As with OSes, the middleware module description can be made available in a description
file with the name of the module (Value of M=). Refer to OS description file on page 100.
Identifier
Example
Module name
M=embOSIP
Module token
T=IP
Description
S=embOS/IP V12.09
Module event
<ID> <Event>
<Parameter>
0 SendPacket IFace=%u
NumBytes=%u
106
CHAPTER 10
Example
static void _cbSendIPModuleDesc(void) {
SEGGER_SYSVIEW_NameResource((U32)&(RxPacketFifo), "Rx FIFO");
SEGGER_SYSVIEW_NameResource((U32)&(TxPacketFifo), "Tx FIFO");
SEGGER_SYSVIEW_RecordModuleDescription(&IPModule, "T=IP, S='embOS/IP V12.09'");
}
SEGGER_SYSVIEW_MODULE IPModule = {
"M=embOSIP, " \
"0 SendPacket IFace=%u NumBytes=%u, " \
"1 ReceivePacket Iface=%d NumBytes=%u",
2,
0,
_cbSendIPModuleDesc,
NULL,
};
//
//
//
//
//
sModule
NumEvents
EventOffset, Set by RegisterModule()
pfSendModuleDesc
pNext, Set by RegisterModule()
107
Chapter 11
API reference
108
CHAPTER 11
Description
Control and initialization functions
SEGGER_SYSVIEW_Init()
SEGGER_SYSVIEW_SetRAMBase()
SEGGER_SYSVIEW_Start()
SEGGER_SYSVIEW_Stop()
SEGGER_SYSVIEW_GetSysDesc()
SEGGER_SYSVIEW_SendTaskList()
SEGGER_SYSVIEW_SendTaskInfo()
SEGGER_SYSVIEW_SendSysDesc()
SEGGER_SYSVIEW_RecordU32()
SEGGER_SYSVIEW_RecordU32x2()
SEGGER_SYSVIEW_RecordU32x3()
SEGGER_SYSVIEW_RecordSystime()
SEGGER_SYSVIEW_RecordEnterISR()
SEGGER_SYSVIEW_RecordExitISR()
SEGGER_SYSVIEW_RecordExitTimer()
SEGGER_SYSVIEW_RecordEndCall()
SEGGER_SYSVIEW_OnIdle()
SEGGER_SYSVIEW_OnTaskCreate()
SEGGER_SYSVIEW_OnTaskStartExec()
SEGGER_SYSVIEW_OnTaskStopExec()
SEGGER_SYSVIEW_OnTaskStartReady()
109
Function
Description
SEGGER_SYSVIEW_OnTaskStopReady()
SEGGER_SYSVIEW_OnUserStart()
SEGGER_SYSVIEW_OnUserStop()
SEGGER_SYSVIEW_NameResource()
SEGGER_SYSVIEW_EncodeData()
SEGGER_SYSVIEW_EncodeString()
SEGGER_SYSVIEW_EncodeId()
SEGGER_SYSVIEW_ShrinkId()
SEGGER_SYSVIEW_SendModule()
printf-Style functions
SEGGER_SYSVIEW_PrintfHostEx()
SEGGER_SYSVIEW_PrintfTargetEx()
SEGGER_SYSVIEW_PrintfHost()
SEGGER_SYSVIEW_PrintfTarget()
SEGGER_SYSVIEW_Print()
SEGGER_SYSVIEW_WarnfHost()
SEGGER_SYSVIEW_WarnfTarget()
SEGGER_SYSVIEW_Warn()
SEGGER_SYSVIEW_ErrorfHost()
SEGGER_SYSVIEW_ErrorfTarget()
110
CHAPTER 11
Function
Description
Print an error string to the host.
SEGGER_SYSVIEW_Error()
Application-provided functions
SEGGER_SYSVIEW_Conf()
SEGGER_SYSVIEW_X_GetTimestamp()
111
11.1.1 SEGGER_SYSVIEW_Conf()
Description
Can be used with OS integration to allow easier initialization of SystemView and the OS
SystemView interface.
This function is usually provided in the SEGGER_SYSVIEW_Config_<OS>.c configuration file
of the used OS.
Prototype
void SEGGER_SYSVIEW_Conf(void);
Example implementation
void SEGGER_SYSVIEW_Conf(void) {
//
// Initialize SystemView
//
SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ,
// Frequency of the timestamp.
SYSVIEW_CPU_FREQ,
// Frequency of the system.
&SYSVIEW_X_OS_TraceAPI,
// OS-specific SEGGER_SYSVIEW_OS_API
_cbSendSystemDesc
// Callback for application-specific description
);
SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
// Explicitly set the RAM base address.
OS_SetTraceAPI(&embOS_TraceAPI_SYSVIEW);
// Configure embOS to use SystemView via the Trace-API.
}
112
CHAPTER 11
11.1.2 SEGGER_SYSVIEW_EncodeData()
Description
Encode a byte buffer in variable-length format.
Prototype
U8 *SEGGER_SYSVIEW_EncodeData(
U8
* pPayload,
const char
* pSrc,
unsigned
NumBytes);
Parameters
Parameter
Description
pPayload
pSrc
NumBytes
Return value
Pointer to the byte following the value, i.e. the first free byte in the payload and the next
position to store payload content.
Additional information
The data is encoded as a count byte followed by the contents of the data buffer. Make sure
NumBytes + 1 bytes are free for the payload.
113
11.1.3 SEGGER_SYSVIEW_EncodeId()
Description
Encode a 32-bit Id in shrunken variable-length format.
Prototype
U8 *SEGGER_SYSVIEW_EncodeId(U8
* pPayload,
unsigned
Id);
Parameters
Parameter
Description
pPayload
Id
Return value
Pointer to the byte following the value, i.e. the first free byte in the payload and the next
position to store payload content.
Additional information
The parameters to shrink an Id can be configured in SEGGER_SYSVIEW_Conf.h and
via SEGGER_SYSVIEW_SetRAMBase(). SEGGER_SYSVIEW_ID_BASE: Lowest Id reported
by the application. (i.e. 0x20000000 when all Ids are an address in this RAM)
SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to save bandwidth. (i.e. 2
when Ids are 4 byte aligned)
114
CHAPTER 11
11.1.4 SEGGER_SYSVIEW_EncodeString()
Description
Encode a string in variable-length format.
Prototype
U8 *SEGGER_SYSVIEW_EncodeString(
U8
* pPayload,
const char
* s,
unsigned
MaxLen);
Parameters
Parameter
Description
pPayload
String to encode.
MaxLen
Return value
Pointer to the byte following the value, i.e. the first free byte in the payload and the next
position to store payload content.
Additional information
The string is encoded as a count byte followed by the contents of the string. No more than
1 + MaxLen bytes will be encoded to the payload.
115
11.1.5 SEGGER_SYSVIEW_EncodeU32()
Description
Encode a U32 in variable-length format.
Prototype
U8 *SEGGER_SYSVIEW_EncodeU32(U8
* pPayload,
unsigned
Value);
Parameters
Parameter
Description
pPayload
Value
Return value
Pointer to the byte following the value, i.e. the first free byte in the payload and the next
position to store payload content.
116
CHAPTER 11
11.1.6 SEGGER_SYSVIEW_Error()
Description
Print an error string to the host.
Prototype
void SEGGER_SYSVIEW_Error(const char * s);
Parameters
Parameter
s
Description
String to sent.
117
11.1.7 SEGGER_SYSVIEW_ErrorfHost()
Description
Print an error string which is formatted on the host by SystemViewer.
Prototype
void SEGGER_SYSVIEW_ErrorfHost(const char * s,
...);
Parameters
Parameter
s
Description
String to be formatted.
Additional information
All format arguments are treated as 32-bit scalar values.
118
CHAPTER 11
11.1.8 SEGGER_SYSVIEW_ErrorfTarget()
Description
Print an error string which is formatted on the target before sent to the host.
Prototype
void SEGGER_SYSVIEW_ErrorfTarget(const char * s,
...);
Parameters
Parameter
s
Description
String to be formatted.
119
11.1.9 SEGGER_SYSVIEW_GetSysDesc()
Description
Triggers a send of the system information and description.
Prototype
void SEGGER_SYSVIEW_GetSysDesc();
120
CHAPTER 11
11.1.10 SEGGER_SYSVIEW_Init()
Description
Initializes the SYSVIEW module. Must be called before SystemViewer attaches to the
system.
Prototype
void SEGGER_SYSVIEW_Init(
U32
SysFreq,
U32
CPUFreq,
const SEGGER_SYSVIEW_OS_API
* pOSAPI,
SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC
pfSendSysDesc);
Parameters
Parameter
Description
SysFreq
CPUFreq
pOSAPI
pfSendSysDesc
Additional information
This function initializes the RTT channel used to transport SEGGER SystemView packets.
The channel is assigned the label SysView for client software to identify the SystemView
channel.
121
11.1.11 SEGGER_SYSVIEW_NameResource()
Description
Send the name of a resource to be displayed in SysViewer.
Prototype
void SEGGER_SYSVIEW_NameResource(
U32
ResourceId,
const char * sName);
Parameters
Parameter
Description
ResourceId
sName
122
CHAPTER 11
11.1.12 SEGGER_SYSVIEW_OnIdle()
Description
Record an Idle event.
Prototype
void SEGGER_SYSVIEW_OnIdle();
123
11.1.13 SEGGER_SYSVIEW_OnTaskCreate()
Description
Record a Task Create event. The Task Create event corresponds to creating a task in the OS.
Prototype
void SEGGER_SYSVIEW_OnTaskCreate(unsigned TaskId);
Parameters
Parameter
TaskId
Description
Task ID of created task.
124
CHAPTER 11
11.1.14 SEGGER_SYSVIEW_OnTaskStartExec()
Description
Record a Task Start Execution event. The Task Start event corresponds to when a task has
started to execute rather than when it is ready to execute.
Prototype
void SEGGER_SYSVIEW_OnTaskStartExec(unsigned TaskId);
Parameters
Parameter
TaskId
Description
Task ID of task that started to execute.
125
11.1.15 SEGGER_SYSVIEW_OnTaskStartReady()
Description
Record a Task Start Ready event.
Prototype
void SEGGER_SYSVIEW_OnTaskStartReady(unsigned TaskId);
Parameters
Parameter
TaskId
Description
Task ID of task that started to execute.
126
CHAPTER 11
11.1.16 SEGGER_SYSVIEW_OnTaskStopExec()
Description
Record a Task Stop Execution event. The Task Stop event corresponds to when a task stops
executing.
Prototype
void SEGGER_SYSVIEW_OnTaskStopExec();
127
11.1.17 SEGGER_SYSVIEW_OnTaskStopReady()
Description
Record a Task Stop Ready event.
Prototype
void SEGGER_SYSVIEW_OnTaskStopReady(unsigned TaskId,
unsigned Cause);
Parameters
Parameter
Description
TaskId
Cause
128
CHAPTER 11
11.1.18 SEGGER_SYSVIEW_OnUserStart()
Description
Send a user event start, such as start of a subroutine for profiling.
Prototype
void SEGGER_SYSVIEW_OnUserStart(unsigned UserId);
Parameters
Parameter
UserId
Description
User defined ID for the event.
129
11.1.19 SEGGER_SYSVIEW_OnUserStop()
Description
Send a user event stop, such as return of a subroutine for profiling.
Prototype
void SEGGER_SYSVIEW_OnUserStop(unsigned UserId);
Parameters
Parameter
UserId
Description
User defined ID for the event.
130
CHAPTER 11
11.1.20 SEGGER_SYSVIEW_Print()
Description
Print a string to the host.
Prototype
void SEGGER_SYSVIEW_Print(const char * s);
Parameters
Parameter
s
Description
String to sent.
131
11.1.21 SEGGER_SYSVIEW_PrintfHost()
Description
Print a string which is formatted on the host by SystemViewer.
Prototype
void SEGGER_SYSVIEW_PrintfHost(const char * s,
...);
Parameters
Parameter
s
Description
String to be formatted.
Additional information
All format arguments are treated as 32-bit scalar values.
132
CHAPTER 11
11.1.22 SEGGER_SYSVIEW_PrintfHostEx()
Description
Print a string which is formatted on the host by SystemViewer with Additional information.
Prototype
void SEGGER_SYSVIEW_PrintfHostEx(const char * s,
U32
Options,
...);
Parameters
Parameter
Description
String to be formatted.
Options
Additional information
All format arguments are treated as 32-bit scalar values.
133
11.1.23 SEGGER_SYSVIEW_PrintfTarget()
Description
Print a string which is formatted on the target before sent to the host.
Prototype
void SEGGER_SYSVIEW_PrintfTarget(const char * s,
...);
Parameters
Parameter
s
Description
String to be formatted.
134
CHAPTER 11
11.1.24 SEGGER_SYSVIEW_PrintfTargetEx()
Description
Print a string which is formatted on the target before sent to the host with Additional
information.
Prototype
void SEGGER_SYSVIEW_PrintfTargetEx(const char * s,
U32
Options,
...);
Parameters
Parameter
Description
String to be formatted.
Options
135
11.1.25 SEGGER_SYSVIEW_RecordEnterISR()
Description
Format and send an ISR entry event.
Prototype
void SEGGER_SYSVIEW_RecordEnterISR();
Additional information
Example packets sent 02 0F 50 // ISR(15) Enter. Timestamp is 80 (0x50)
136
CHAPTER 11
11.1.26 SEGGER_SYSVIEW_RecordEnterTimer()
Description
Format and send a Timer entry event.
Prototype
void SEGGER_SYSVIEW_RecordEnterTimer(U32 TimerId);
Parameters
Parameter
TimerId
Description
Id of the timer which starts.
137
11.1.27 SEGGER_SYSVIEW_RecordExitISR()
Description
Format and send an ISR exit event.
Prototype
void SEGGER_SYSVIEW_RecordExitISR();
Additional information
Format as follows: 03 <TimeStamp> // Max. packet len is 6
Example packets sent 03 20 // ISR Exit. Timestamp is 32 (0x20)
138
CHAPTER 11
11.1.28 SEGGER_SYSVIEW_RecordExitISRToScheduler()
Description
Format and send an ISR exit into scheduler event.
Prototype
void SEGGER_SYSVIEW_RecordExitISRToScheduler();
Additional information
Format as follows: 18 <TimeStamp> // Max. packet len is 6
Example packets sent 18 20 // ISR Exit to Scheduler. Timestamp is 32 (0x20)
139
11.1.29 SEGGER_SYSVIEW_RecordExitTimer()
Description
Format and send a Timer exit event.
Prototype
void SEGGER_SYSVIEW_RecordExitTimer();
140
CHAPTER 11
11.1.30 SEGGER_SYSVIEW_RecordEndCall()
Description
Format and send an End API Call event without return value.
Prototype
void SEGGER_SYSVIEW_RecordEndCall(unsigned EventID);
Parameters
Parameter
EventID
Description
Id of API function which ends.
141
11.1.31 SEGGER_SYSVIEW_RecordEndCallReturnValue()
Description
Format and send an End API Call event with return value.
Prototype
void SEGGER_SYSVIEW_RecordEndCallReturnValue(unsigned EventID,
unsigned ReturnValue);
Parameters
Parameter
Description
EventID
ReturnValue
142
CHAPTER 11
11.1.32 SEGGER_SYSVIEW_RecordModuleDescription()
Description
Sends detailed information of a registered module to the host.
Prototype
void SEGGER_SYSVIEW_RecordModuleDescription(const SEGGER_SYSVIEW_MODULE * pModule,
const char
* sDescription);
Parameters
Parameter
Description
pModule
sDescription
143
11.1.33 SEGGER_SYSVIEW_RecordSystime()
Description
Formats and sends a SystemView Systime containing a single U64 or U32 parameter
payload.
Prototype
void SEGGER_SYSVIEW_RecordSystime();
144
CHAPTER 11
11.1.34 SEGGER_SYSVIEW_RecordU32()
Description
Formats and sends a SystemView packet containing a single U32 parameter payload.
Prototype
void SEGGER_SYSVIEW_RecordU32(unsigned EventID,
U32
Value);
Parameters
Parameter
Description
EventID
Value
145
11.1.35 SEGGER_SYSVIEW_RecordU32x2()
Description
Formats and sends a SystemView packet containing 2 U32 parameter payload.
Prototype
void SEGGER_SYSVIEW_RecordU32x2(unsigned EventID,
U32
Para0,
U32
Para1);
Parameters
Parameter
Description
EventID
Para0
Para1
146
CHAPTER 11
11.1.36 SEGGER_SYSVIEW_RecordU32x3()
Description
Formats and sends a SystemView packet containing 3 U32 parameter payload.
Prototype
void SEGGER_SYSVIEW_RecordU32x3(unsigned
U32
U32
U32
EventID,
Para0,
Para1,
Para2);
Parameters
Parameter
Description
EventID
Para0
Para1
Para2
147
11.1.37 SEGGER_SYSVIEW_RecordVoid()
Description
Formats and sends a SystemView packet with an empty payload.
Prototype
void SEGGER_SYSVIEW_RecordVoid(unsigned EventID);
Parameters
Parameter
EventID
Description
SystemView event ID.
148
CHAPTER 11
11.1.38 SEGGER_SYSVIEW_RegisterModule()
Description
Register a middleware module for recording its events.
Prototype
void SEGGER_SYSVIEW_RegisterModule(SEGGER_SYSVIEW_MODULE * pModule);
Parameters
Parameter
pModule
Description
The middleware module information.
Additional information
SEGGER_SYSVIEW_MODULE elements: sDescription - Pointer to a string containing the
module name and optionally the module event description. NumEvents - Number of events
the module wants to register. EventOffset - Offset to be added to the event Ids. Out
parameter, set by this function. Do not modify after calling this function. pfSendModuleDesc
- Callback function pointer to send more detailed module description to SystemViewer.
pNext - Pointer to next registered module. Out parameter, set by this function. Do not
modify after calling this function.
149
11.1.39 SEGGER_SYSVIEW_SendModule()
Description
Sends the information of a registered module to the host.
Prototype
void SEGGER_SYSVIEW_SendModule(U8 ModuleId);
Parameters
Parameter
ModuleId
Description
Id of the requested module.
150
CHAPTER 11
11.1.40 SEGGER_SYSVIEW_SendModuleDescription()
Description
Triggers a send of the registered module descriptions.
Prototype
void SEGGER_SYSVIEW_SendModuleDescription();
151
11.1.41 SEGGER_SYSVIEW_SendNumModules()
Description
Send the number of registered modules to the host.
Prototype
void SEGGER_SYSVIEW_SendNumModules();
152
CHAPTER 11
11.1.42 SEGGER_SYSVIEW_SendPacket()
Description
Send an event packet.
Prototype
int SEGGER_SYSVIEW_SendPacket(U8
* pPacket,
U8
* pPayloadEnd,
unsigned
EventId);
Parameters
Parameter
Description
pPacket
pPayloadEnd
EventId
Return value
0
=0
153
11.1.43 SEGGER_SYSVIEW_SendSysDesc()
Description
Send the system description string to the host. The system description is used by SysViewer
to identify the current application and handle events accordingly.
Prototype
void SEGGER_SYSVIEW_SendSysDesc(const char * sSysDesc);
Parameters
Parameter
Description
Pointer to the 0-terminated system description string.
sSysDesc
Additional information
One system description string may not exceed SEGGER_SYSVIEW_MAX_STRING_LEN
characters.
The Following items can be described in a system description string. Each item is identified
by its identifier, followed by = and the value. Items are separated by ,.
Item
Identifier
Example
Application name
N=Test Application
Operating system
O=embOS
Additional module
M=embOS/IP
Target device
D=MK66FN2M0xxx18
Target core
C=Cortex-M4
Interrupt
I#<InterruptID>
I#15=SysTick
Example strings
N=Test Application,O=embOS,D=MK66FN2M0xxx18
I#15=SysTick,I#99=ETH_Tx,I#100=ETH_Rx
154
CHAPTER 11
11.1.44 SEGGER_SYSVIEW_SendTaskInfo()
Description
Send a Task Info Packet, containing TaskId for identification, task priority and task name.
Prototype
void SEGGER_SYSVIEW_SendTaskInfo(const SEGGER_SYSVIEW_TASKINFO * pInfo);
Parameters
Parameter
pInfo
Description
Pointer to task information to send.
155
11.1.45 SEGGER_SYSVIEW_SendTaskList()
Description
Send all tasks descriptors to the host.
Prototype
void SEGGER_SYSVIEW_SendTaskList();
156
CHAPTER 11
11.1.46 SEGGER_SYSVIEW_SetRAMBase()
Description
Sets the RAM base address, which is subtracted from IDs in order to save bandwidth.
Prototype
void SEGGER_SYSVIEW_SetRAMBase(U32 RAMBaseAddress);
Parameters
Parameter
RAMBaseAddress
Description
Lowest RAM Address. (i.e. 0x20000000 on most Cortex-M)
157
11.1.47 SEGGER_SYSVIEW_ShrinkId()
Description
Get
the
shrunken
value
of
SEGGER_SYSVIEW_NameResource().
an
Id
for
further
processing
like
in
Prototype
U32 SEGGER_SYSVIEW_ShrinkId(U32 Id);
Parameters
Parameter
Id
Description
The 32-bit value to be shrunken.
Return value
Shrunken Id.
Additional information
The parameters to shrink an Id can be configured in SEGGER_SYSVIEW_Conf.h and
via SEGGER_SYSVIEW_SetRAMBase(). SEGGER_SYSVIEW_ID_BASE: Lowest Id reported
by the application. (i.e. 0x20000000 when all Ids are an address in this RAM)
SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to save bandwidth. (i.e. 2
when Ids are 4 byte aligned)
158
CHAPTER 11
11.1.48 SEGGER_SYSVIEW_Start()
Description
Start recording SystemView events. This function is triggered by the host application.
Prototype
void SEGGER_SYSVIEW_Start();
Additional information
This function enables transmission of SystemView packets recorded by subsequent trace
calls and records a SystemView Start event.
As part of start, a SystemView Init packet is sent, containing the system frequency. The list
of current tasks, the current system time and the system description string is sent, too.
159
11.1.49 SEGGER_SYSVIEW_Stop()
Description
Stop recording SystemView events.
Prototype
void SEGGER_SYSVIEW_Stop();
Additional information
This function disables transmission of SystemView packets recorded by subsequent trace
calls. If transmission is enabled when this function is called, a single SystemView Stop event
is recorded to the trace, send, and then trace transmission is halted.
160
CHAPTER 11
11.1.50 SEGGER_SYSVIEW_Warn()
Description
Print a warning string to the host.
Prototype
void SEGGER_SYSVIEW_Warn(const char * s);
Parameters
Parameter
s
Description
String to sent.
161
11.1.51 SEGGER_SYSVIEW_WarnfHost()
Description
Print a warnin string which is formatted on the host by SystemViewer.
Prototype
void SEGGER_SYSVIEW_WarnfHost(const char * s,
...);
Parameters
Parameter
s
Description
String to be formatted.
Additional information
All format arguments are treated as 32-bit scalar values.
162
CHAPTER 11
11.1.52 SEGGER_SYSVIEW_WarnfTarget()
Description
Print a warning string which is formatted on the target before sent to the host.
Prototype
void SEGGER_SYSVIEW_WarnfTarget(const char * s,
...);
Parameters
Parameter
Description
String to be formatted.
11.1.53 SEGGER_SYSVIEW_X_GetTimestamp()
Description
This function needs to be implemented when SEGGER_SYSVIEW_GET_TIMESTAMP() is
configured to call it. By default this is done on all non-Cortex-M3/4 targets.
Prototype
U32 SEGGER_SYSVIEW_X_GetTimestamp(void);
Return value
Returns the current system timestamp in timestamp cycles. On Cortex-M3 and Cortex-M4
this is the cycle counter.
Example implementation
U32 SEGGER_SYSVIEW_X_GetTimestamp(void) {
U32 TickCount;
U32 Cycles;
U32 CyclesPerTick;
//
// Get the cycles of the current system tick.
// SysTick is down-counting, subtract the current value from the number of cycles per tick.
//
CyclesPerTick = SYST_RVR + 1;
Cycles = (CyclesPerTick - SYST_CVR);
//
// Get the system tick count.
//
TickCount = SEGGER_SYSVIEW_TickCnt; // SEGGER_SYSVIEW_TickCnt is incremented by the system tick ha
//
// If a SysTick interrupt is pending increment the TickCount
//
if ((SCB_ICSR & SCB_ICSR_PENDSTSET_MASK) != 0) {
TickCount++;
}
Cycles += TickCount * CyclesPerTick;
return Cycles;
}
163
Chapter 12
Frequently asked questions
Minimize the interactions of the debugger with J-Link while the target is running. (i.e. disable
live watches)
Select a higher interface speed in all instances connected to J-Link. (i.e. The debugger and
SystemViewer)
Choose a larger buffer for SystemView. (1 - 4 kByte)
Run SystemViewer stand-alone without a debugger.
Q: SystemViewer cannot find the RTT Control Block, how can I configure it?
A: Auto-detection of the RTT Control Block can only be done in a known RAM address range
after it is initialized. Make sure the application startup has ran when starting to record. If the
RTT Control Block is outside the known range for the selected device, either select Address
and enter the exact address of the RTT Control Block or select Address Range and enter an
address range in which the RTT Control Block will be.
Q: Do I have to select a Target Device to start recording?
164
CHAPTER 12
A: Yes. J-Link needs to now which target device is connected. The drop-down lists the most
recently used devices. To select another device simply enter its name. A list of supported
devices can be found here.
Q: My question is not listed above. Where can I get more information?
A: For more information and help please ask your question in the SEGGER forum https://
forum.segger.com