NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.
Using CCS Variables in source code
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
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
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"