If you just need a true/false setting, you can use #IFDEF to test for existence.
Thanks for Your comment but I need a defined number (range 0..999)
Some clarification: The #define has nothing to do with PSoCs, but the underlying Keil compiler. To get more information about the pre-processing it would be best to look for ARM DP8051 Keil compiler.
Afaik you may define a symbol using the command line, but you cannot assign it a value.
Do not use an equal sign when you want to give a symbol a value in a #define, that seems to be an error.
So what I did:
- I added to my code something like this:
#if TESTDEF == 1
- then I went to project / build settings
- I selected Keil 9.51 / compiler
- There is a setting 'preprocessor definitions', reading 'DEBUG'
- I changed it to 'Debug ; TESTDEF=1' (I actually opened the edit dialog for this setting and added a new one)
- I compiled and got the expected compile error (missing semicolon). When changing TESTDEF to 2, it went away.
The editor also got the code correct (OK, it tells me this is not a valid binary expression, but knows what code is active and which is not).
I reproduced the steps, I think it's definitive a bug in PSoC Creator!
1. When I define the TEST_VAL in "normal" way, the if-query has no problem, the code is NOT gray.
2. I define it in build settings (toolcahin ARM GCC) in correct way (TEST_VAL=1)
3. The if-query has an error, the code is gray although it is active for the compiler!
This is a bug or isn't it???? Please help! Is there anywhere a supporter from Cypress?
Have a look here at Preprocessor chapter.
To get in contact with Cypress directly (this here is a developer forum) :
At top of this page select "Design Support -> Create a Support Case" and describe your problem.
You are posting in the PSoC3 forum, so I used a PSoC3 project. This is using the Keil C compiler. Are you using something different?
For me it worked: when setting the value to '1' my code is enabled, when setting it to '2' its grayed out. The compiler also agrees with that. This 'binary expression'thingy is just a warning of the IDE, it seems not to know about '==' or so.
So I tested this again with a PSoC5LP project, and it works exactly the same way (and everything is fine). The actual command line (taken from the build log) is this:
arm-none-eabi-gcc.exe -mcpu=cortex-m3 -mthumb -Wno-main -I. -IGenerated_Source\PSoC5 -Wa,-alh=.\CortexM3\ARM_GCC_493\Debug/main.lst -g -D DEBUG -D TESTDEF=2 -Wall -ffunction-sections -O0 -ffat-lto-objects -std=gnu11 -c .\main.c -o .\CortexM3\ARM_GCC_493\Debug\main.o
The IDE warning seems to come from the source code error checker not looking at the #defines in the build config. But it works nonetheless (even though the IDE always thinks the #IF is false always)
I think, the IDE does not know about parameters given to the compiler start.
So all references to symbols defined or set at command line are not taken into account in the IDE when displaying the sources.
This issue will be fixed in PSoC Creator 4.0.