Skip to content

Commit bef2969

Browse files
committed
Initial commit
0 parents  commit bef2969

47 files changed

Lines changed: 54613 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
.vscode
3+
.idea

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
3+
project(OrbcodeLibtrace NONE)
4+
5+
option(ORBCODE_LIBTRACE_BUILD_TEST "Build tests" OFF)
6+
option(ORBCODE_LIBTRACE_DOCS "Build Doxygen documentation" OFF)
7+
8+
if(ORBCODE_LIBTRACE_BUILD_TEST)
9+
enable_language(C)
10+
enable_language(CXX)
11+
endif()
12+
13+
add_subdirectory(libs)
14+
15+
if(ORBCODE_LIBTRACE_BUILD_TEST)
16+
add_subdirectory(tests)
17+
endif()
18+
19+
if(ORBCODE_LIBTRACE_DOCS)
20+
add_subdirectory(docs)
21+
endif()

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Orbcode Trace functions library
2+
3+
## Overview
4+
This library provides C/C++ functions for configuring ARM Cortex-M trace components.
5+
6+
## Contents
7+
Following features are supported:
8+
* Trace Port Interface Unit
9+
* Configuring trace protocol
10+
* Instrumentation Trace Macrocell
11+
* Configuring ITM
12+
* Outputing data over stimulus ports
13+
* Data Watchpoint & Trace Unit
14+
* Configuring DWT including PC sampling, timestamp generations and counters
15+
* Setting up watchpoints
16+
17+
All functions are available as header-only library depending only on CMSIS `core_cmXX.h` header provided by MCU vendor. Once library is available (see Installation section below) it can be used in application code as follow:
18+
19+
```cpp
20+
#include "my_mcu_device.h" // Vendor-provided header that includes core_cmXX.h
21+
#include "orbcode/trace/tpiu.h"
22+
#include "orbcode/trace/itm.h"
23+
#include "orbcode/trace/dwt.h"
24+
25+
static void ConfigureTraceComponents()
26+
{
27+
TpiuOptions tpiu;
28+
// TODO: setup TPIU using by setting fields in tpiu variable
29+
ITMOptions itm;
30+
// TODO: setup ITM using by setting fields in itm variable
31+
DWTOptions dwt;
32+
// TODO: setup DWT using by setting fields in dwt variable
33+
34+
// Apply configuration as defined in structs
35+
TpiuSetup(&tpiu);
36+
ITMSetup(&itm);
37+
DWTSetup(&dwt);
38+
}
39+
40+
static void UseITM()
41+
{
42+
// Output data on ITM stimulus port
43+
ITMWrite8(4, 'H');
44+
ITMWrite8(4, 'E');
45+
ITMWrite8(4, 'L');
46+
ITMWrite8(4, 'L');
47+
ITMWrite8(4, 'O');
48+
}
49+
50+
int main()
51+
{
52+
ConfigureVendorSpecificOptionsRequiredForTracing(); // i.e. clock, GPIOs
53+
ConfigureTraceComponents();
54+
55+
UseITM();
56+
}
57+
```
58+
59+
Refer to documentation of each module for details how each component is configured and what functionalities are available.
60+
61+
**Warning:** Currently `libtrace` is optimistic when it comes to MCU capabilities. For devices with limited trace features it is possible for `libtrace` to generate invalid configuration. If that happens, please let us know by submitting issue and we will try to adapt library.
62+
63+
## Installation
64+
As library is header only it is straightforward to use with any build system.
65+
66+
### CMake + FetchContent
67+
For projects using CMake it is recommended to use `FetchContent` to download `libtrace` library and include it in build system automatically.
68+
69+
Fetch library:
70+
71+
```cmake
72+
include(FetchContent)
73+
74+
FetchContent_Declare(
75+
libtrace
76+
GIT_REPOSITORY <todo>
77+
GIT_TAG <todo>
78+
)
79+
FetchContent_MakeAvailable(libtrace)
80+
```
81+
82+
Include `Orbcode::Trace` as dependency:
83+
84+
```cmake
85+
target_link_libraries(MyApplication PUBLIC Orbcode::Trace)
86+
```
87+
88+
### Other build systems
89+
Other build system must download `libtrace` manually (git submodule, wget, etc) and add folder `libs/trace/include` to include directories in compiler command line:
90+
91+
```
92+
CFLAGS += -Idownloaded_libs/libtrace/libs/trace/include
93+
```
94+
95+
## Building
96+
Although for end-user this library can be treated as header-only with no build steps required, for development of library itself it is useful to be able to generate proper build system.
97+
98+
Simple command line for using Ninja generator:
99+
```
100+
cmake -G Ninja -S<libtrace source dir> -B<build directory> --toolchain <toolchain file for arm-none-eabi> -DORBCODE_LIBTRACE_BUILD_TEST=ON -DORBCODE_LIBTRACE_DOCS=ON
101+
ninja -C <build directory> # Compile test libraries
102+
ninja -C <build directory> docs # Generate Doxygen documentation in <build directory>/docs/html
103+
```
104+
105+
Following options are availble:
106+
* `ORBCODE_LIBTRACE_BUILD_TEST` (default: `OFF`) - compile simple test files to make sure that header files are correct (useful for detecting syntax errors). When this option is enable toolchain capable for compiling for ARM Cortex-M is required (e.g. arm-none-eabi-gcc with `-mmcu=cortex-m3`)
107+
* `ORBCODE_LIBTRACE_DOCS` (default: `OFF`) - build Doxygen documentation (requires Doxygen)

docs/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
find_package(Doxygen REQUIRED)
2+
3+
set(DOXYGEN_GENERATE_HTML YES)
4+
set(DOXYGEN_USE_MATHJAX YES)
5+
set(DOXYGEN_SORT_MEMBER_DOCS NO)
6+
set(DOXYGEN_EXTRACT_STATIC YES)
7+
set(DOXYGEN_IMAGE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/images)
8+
set(DOXYGEN_PROJECT_NAME "Orbcode Trace functions library")
9+
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${CMAKE_SOURCE_DIR}/README.md)
10+
11+
doxygen_add_docs(docs
12+
${CMAKE_SOURCE_DIR}/libs
13+
${CMAKE_SOURCE_DIR}/README.md
14+
)
15+
Lines changed: 4 additions & 0 deletions
Loading

libs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(trace)

libs/trace/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(NAME _orbcode_liborbtrace)
2+
3+
add_library(${NAME} INTERFACE)
4+
5+
target_include_directories(${NAME} INTERFACE include)
6+
7+
add_library(Orbcode::Trace ALIAS _orbcode_liborbtrace)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @defgroup trace ARM Cortex-M tracing functions
3+
*
4+
* This library provides set of low-level functions for setting up tracing components of ARM Cortex-M microcontrollers directly with code.
5+
*
6+
* Header files included in this library depend on CMSIS `core_cmXX.h` header files providing necessary type definitions and macros. They are however dependant on vendor specific information and cannot be used standalone (e.g. `IRQn_Type` is required to be defined before including `core_cmXX.h`). Therefore CMSIS headers are **not included** in this library and it is up to user to ensure proper include order:
7+
*
8+
* @code{.cpp}
9+
* #include <my_mcu_cm3.h> // Typically includes also core_cm3.h
10+
* #include "orbcode/trace/tpiu.h" // Now we can include Orbcode functions
11+
* @endcode
12+
*
13+
* Before trace components can be used, they need to be configured which invovles:
14+
* 1. Setting up MCU specific options (trace clock, GPIO alternate functions) - refer to vendor's documentation for details.
15+
* 2. Setting up TPIU responsible for pushing ITM and ETM data into physical layer (SWO or parallel trace) (See @ref tpiu).
16+
* 3. Configure ITM module (if needed) for outputing user-defined data by stimulus port or pass-through of DWT output (See @ref itm).
17+
* 4. Configure DWT module (if needed) for timestamping, PC sampling, watchpoints and various counters (See @ref dwt).
18+
* 5. Configure ETM module (if needed) for instruction-level tracing (not covered by this library yet).
19+
*
20+
* Once trace components are configured they can be used during normal program operations (e.g. outputing data via ITM stimulus ports) or will automatically output data (like DWT PC sampling, watchpoints or ETM instruction trace).
21+
*
22+
* Refer to individual modules for details how to configure and use each component.
23+
*/

0 commit comments

Comments
 (0)