External LLVM for TriCore™ applications

Please ensure that you make all the necessary changes to the project before running it. Running the project without implementing all the changes can result in a corrupt build and may require starting the entire project from scratch. To avoid any issues, thoroughly review and implement all the proposed modifications before proceeding with the execution of the project. Please pay special attention to the C/C++ Indexer, see further down for more information.

Import existing project

To test if the LLVM HighTec compiler works correctly, let’s import one of the existing Infineon projects.

Select File  Import  Infineon  AURIX™ Development Studio Project and click Next.

import project
Fig. 1. Import Infineon example

Then select Infineon TC4xx Code Examples Repository, select an example of your choice (we will test the "blinky" example for STD Kit TC499) and click Finish.

Update iLLD

Update project libraries to the latest version and back up the current.
Right-click on the project, select Project updater  Update iLLD and click Finish.

update illd
Fig. 2. Update iLLD

The latest version of the iLLD will also generate the correct linker script.

notmissing LS
Fig. 3. Linker script

When the iLLD is updated, ADS executes the C/C++ Indexer. It needs to be finished before starting the build. Otherwise, there is a significant risk of the build failing.

c c++ indexer
Fig. 4. C/C++ Indexer execution in the lower-right corner

Manage build configuration

To create a new HighTec LLVM toolchain configuration, right-click on the project and select Build Configuration  Manage.

build manage
Fig. 5. Setting the manage build configuration

The Manage Configurations tab will be opened.

manage configuration tab
Fig. 6. Manage configuration tab

Select New and give a name to the new configuration. Then select Import predefined, choose TriCore Application  External LLVM  Debug and click OK.

buildconfig new
Fig. 7. New configuration

Activate build configuration

To select a new active configuration, right-click on the project and select Build Configuration  Set Active  HighTec (name of the new configuration created).

set active
Fig. 8. Setting the active build configuration

Import linker script

After the iLLD update, the project linker script is replaced by a default one for the iLLD base project. If the linker script is not present after creating a new configuration, it is possible to get it from the latest version of the iLLD package and manually copy it into the project:

Target Latest iLLD

TC3xx

iLLD_TC3xx_V1_0_1_17_0 _Package

TC4xx

iLLD_TC4xx_2_0_1_2_19_Package

Infineon Low-Level Drivers are available upon request from Infineon and contain a standardized linker script for LLVM toolchains.

The base TC49x linker script Lcf_Hightec_Tricore_Tc.lsl, and specialized linker scripts for the PPU and DMA examples, can also be downloaded via this link: HighTec Linker Scripts.

notmissing LS
Fig. 9. Imported Linker File

Build settings

The build settings must be updated for the active build configuration. To access the settings, right-click on the project and select Properties  C/C++ Build  Settings.

Apply toolchain

Under the Tool Settings  Settings tab, change the Prefix and Path fields:

  • The Prefix is always "empty" for the LLVM toolchain.

  • The Path must be set to the "bin" folder of the LLVM toolchain.

After the change is done, click Apply and Close.

buildsettings path
Fig. 10. Setting the prefix and path to the HighTec LLVM compiler

When the new toolchain is set, ADS executes the C/C++ Indexer. It needs to be finished before starting the build. Otherwise, there is a considerable risk of the build failing.

c c++ indexer
Fig. 11. C/C++ Indexer execution in the lower-right corner

Clang driver options

The C/C++ compiler driver clang is a complete control program for a large part of the toolchain. It can orchestrate the entire build of an executable with a single command-line invocation.

In ADS, the compiling and linking steps are done separately. For this reason, the following options must be used in both: LLVM C Compiler options and LLVM Linker options.

Architecture: -march=<arch>

In compilation, it affects the available instructions to emit. In linking, it affects the selection of target libraries. Allowed values are:

<arch> Device

tc161

AURIX™ platform 1st generation (TC2xx)

tc162

AURIX™ platform 2nd generation (TC3xx)

tc18

AURIX™ platform 3rd generation (TC4xx)

This option is set under "TriCore options" and the variable -march= is preset. For TC4 examples, the value tc18 is also preset. This is valid for both the Compiler and the Linker settings.

tricore options
Fig. 12. Compiler settings
tricoreoptions linker
Fig. 13. Linker settings
Errata: -merrata=<bug>

Some derivatives contain silicon bugs, also known as errata. In such cases, the workaround has to be applied to avoid triggering them. This option also affects the selection of target libraries during the linking. Allowed values:

<bug> Description

cpu141

[CPU_TC.141] Instructions not implemented in TC49A derivative [1]

Please refer to the Errata chapter in [2] for more details.

For compilation, extend the Other flags field in LLVM Compiler  Miscellaneous, i.e., -merrata=cpu141.
For the linking, extend the Other flags field in LLVM Linker  Miscellaneous, i.e., -merrata=cpu141.

buildsettings merrata
Fig. 14. Compiler settings
linker merrata
Fig. 15. Linker settings
Floating point strategy: mfloat-abi=<float-abi>

Select the floating point handling strategy for code generation: software function calls or hardware FPU instructions. The <float-abi> keyword has the following pattern:
<float-strategy><double-strategy><size-of-double> , i.e., hs64.
The letters represent the handling strategy for float and double floating-point types. The number is the size of the double type in bits. The possible combinations can be selected from the following table according to the -march=<arch>

<float-abi> float strategy double strategy double size Supported archs Default for

ss32

function calls

function calls

32

tc18

hh32

FPU instructions

FPU instructions

32

tc161, tc162, tc18

ss64

function calls

function calls

64

tc18

hs64

FPU instructions

function calls

64

tc161, tc162, tc18

tc161, tc162

hh64

FPU instructions

FPU instructions

64

tc18

tc18

For more details, please refer to the Multilib variants chapter in [2].

For compilation, extend the Other flags field in LLVM Compiler  Miscellaneous, i.e., -mfloat-abi=hh64.
For the linking, extend the Other flags field in LLVM Linker  Miscellaneous, i.e., -mfloat-abi=hh64.

Exceptions: -f[no-]exceptions

Enable or disable the support for C++ exception handling. This flag also controls which libraries are linked. By default, exceptions are enabled.

For compilation, extend the Other flags field in LLVM Compiler  Miscellaneous, i.e., -fno-exceptions.
For the linking, extend the Other flags field in LLVM Linker  Miscellaneous, i.e., -fno-exceptions.

The exhaustive list of the compiler driver options can be found in the Compiler Driver chapter in [2].

Compiler-specific options

  • The Command is pre-set to clang in LLVM C Compiler.

    Optimizations: -O<level>

    The compiler accepts the following optimization options: -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og

    Choose from the offered options or set the Other optimization flags field in LLVM Compiler  Optimization. In the second case, there are two optimization options in the build command, and the compiler will use the last one in the sequence, i.e., in clang -O0 -Ofast, -Ofast will be used.

comp opts
Fig. 16. AURIX™ LLVM C Compiler Options

The exhaustive list of the compiler options can be found in the Compiler chapter of [2].

Linker-specific options

  • The Command is pre-set to clang in LLVM Linker.

  • Although clang understands and forwards most of the common linker options, some need to be passed directly to the linker. To pass an option to the linker, you should prefix the option with -Xlinker or -Wl,.

For example, option --gc-sections should be passed to the linker as -Xlinker --gc-sections or -Wl,--gc-sections.

Linker script: -T<linker-script>

We use the linker script containing the Hightec keyword. The information on how to select and import it is described in chapter Linker script.

Set the field Linker Script in LLVM Linker  General, i.e., ../Lcf_Hightec_Tricore_Tc.lsl.

Libraries
Internal libraries

When using the clang compiler driver, the library paths are chosen based on the -march, -merrata, -mfloat-abi, and -f[no-]exceptions options. The libraries like C standard library, or C++ library, are automatically linked from these paths. Some functions from the C standard library reference the file IO functions. To prevent the linker error: ld.lld: error: undefined symbol, the libhtcos.a library has to be linked as well.

Add the option -htcos in LLVM Linker  Miscellaneous  Add.

External libraries

When linking external libraries, it is necessary to pass the library name with -l prefix: -l<lib> as well as the library path with -L prefix: -L<libpath>. To link, e.g., the "C:\tricore\libs\libbsp.a" library, the following parameters have to be passed to the linker: -lbsp and -LC:\tricore\libs.

Add options -l<lib> and -L<libpath> in LLVM Linker  Libraries  Add to link an external library.

htcos linkeroptions
Fig. 17. External library

An exhaustive list of linker options can be found in the Linker chapter of [2].

LLVM Object Copy options

  • llvm-objcopy is pre-set.

An exhaustive list of Binutils options can be found in the Binutils chapter of [2].

copyOpts
Fig. 18. LLVM Object Copy Options

LLVM Create Listing options

  • llvm-objdump is pre-set.

dumpObjs
Fig. 19. LLVM Listing Options

An exhaustive list of Binutils options can be found in the Binutils chapter of [2].

LLVM Print Size options

  • llvm-size is pre-set.

sizeOpts
Fig. 20. LLVM Print Size Options

An exhaustive list of Binutils options can be found in the Binutils chapter of [2].

Build the project

Now, the project will use the HighTec LLVM compiler to build the application.

The final project content after a successful build is shown in the below figure.

complete build
Fig. 21. Content of the imported Infineon project after a successful build

A complete project, run on a board.

UARThelloworld
Fig. 22. UART_VCOM_1_ example run on board TC400_COM_TRB