You are here

Preprocessor defines in Build Settings wrong!? Please help me! | Cypress Semiconductor

Preprocessor defines in Build Settings wrong!? Please help me!

Summary: 11 Replies, Latest post by pvkv on 03 Apr 2016 10:59 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
hubertus.stallerus's picture
User
3 posts

This problem occurs with PSoC Creator  3.3 (3.3.0.410)

 

Hello community,

I ask You about help for an issue (bug?) in the PSoC Creator. What I simple want: Define a preprocessor definition with a value in the build settings and use it correctly in the editor.

1. Define it by hand in a header-file (see screenshot 1)

Anything correct here. The PSoC Creator makes the unused code gray and shows the correct case. Also on compiling the correct error is shown.

2. Define it in "Build Settings" > "Compiler" > "Preprocessor Definitions" in correct syntax (TEST_VAL=1) (see screenshot 2)

The PSoC Creator shows the define as "1=" instead of "1". So the code is not shown correct, gray code is indeed compiled! The compiler works correct, the correct error is shown.

3. Define it in "Build Settings" > "Compiler" > "Preprocessor Definitions" in false syntax (TEST_VAL 1) (see screenshot 3)

The PSoC Creator shows all correct, the gray code is really unused. But the compiler cannot handle the parameter -D "TEST_VAL 1" (see screenshot 4).

 

So my problem is that I must choose if the compiler does the correct things or the PSoC Creator shows all correct. My favor is both together. Please help me to find a way or bugfix the PSoC Creator because this seems to be a bug in this Software.

 

Thank You a lot for Your help!

hli
user_78878863's picture
User
2759 posts

If you just need a true/false setting, you can use #IFDEF to test for existence.

hubertus.stallerus's picture
User
3 posts

Thanks for Your comment but I need a defined number (range 0..999)

user_1377889's picture
User
10803 posts

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.

 

Bob

hli
user_78878863's picture
User
2759 posts

So what I did:

  • I added to my code something like this:

#if TESTDEF == 1
something silly
#ENDIF

  • 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).

hli
user_78878863's picture
User
2759 posts

Aargh! There should have been a screenshot attached :( Lets try whether embedding it works, if not it should be there as an attachement...

hubertus.stallerus's picture
User
3 posts

Pooh... are You sure You don't have the same problem? Your comment "OK, it tells me this is not a valid binary expression" sounds as it doesn't work on Your client too!

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?

hli
user_78878863's picture
User
2759 posts

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.

user_1377889's picture
User
10803 posts

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.

Bob

 

hli
user_78878863's picture
User
2759 posts

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)

 

user_1377889's picture
User
10803 posts

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.

 

Bob

Log in to post new comments.