|
| 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) |
0 commit comments