Please note as of Wednesday, August 15th, 2018 this wiki has been set to read only. If you are a TI Employee and require Edit ability please contact x0211426 from the company directory.

Using CCS Variables in source code

From Texas Instruments Wiki
Jump to: navigation, search

This article shows how you can reference CCS build variables within symbol definitions in C source code and within project options.

This can be useful when you want to

  • define a variable in the source code and place it at a specific location in memory (generally useful for specifying version numbers, code revisions, etc) and
  • have the CCS build use that variable/string as part of the output file name

1) Write your C code:
Here is an example C code that places variables nv_data (float) and nv1_data (string) into specific memory locations using #pragma DATA_SECTION.
(Refer to the Compiler Users Guide if you are not familiar with the pragma).
This is simply a template meant to be used as a reference.
Note: the syntax for the string macro is a bit different (a reference on that is here).

#define xstr(s) str(s)
#define str(s) #s

#pragma DATA_SECTION(nv_data, ".infoD")
#pragma RETAIN(nv_data)
const float nv_data[] = {MYVERSION};

#pragma DATA_SECTION(nv1_data, ".infoC")
#pragma RETAIN(nv1_data)
const char nv1_data[] = {xstr(MYVERSION_STRING)};

2) Create CCS build variables:
Go to Project properties->Build->Variables tab and create build variables with the desired values

Ccs variables.png

3) Define compiler symbols that reference the variables:
Under Project properties->Compiler->Advanced Options->Predefined Symbols, add --defines to define the symbols used in the C code

Compiler defines.png

4) Use the variable in build options:
Under Project properties->Linker->Basic Options, for example, use the variable in the output file name. "${ProjName}_${STRING1}.out"

Linker options.png