Conditional compile over Build-Configurations

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User11996
Level 3
Level 3
Hi.

Is there a way to compile a project conditional?

I set up a new Build Configuration : TEST.
Only in this configuration, i want to compile the Uart modules to serve the XMC_ASSERT() to a uart output.

To implement this solution, i add a new Build Variables "TEST_ACTIVE" Type:String Val:"0" to the TEST configuration.
( -> Properties for My Project, -> C/C++ Build -> Build Variables; Configuration: TEST )

2491.attach
In the source code i place a : #ifdef TEST_ACTIVE (Code between) #endif

I set Configuration TEST active, but the compiler doesn't know the Variable "TEST_ACTIVE".

How can i solve this, or isn't it possible to set up a Configuration for this?

And how to implement and activate the XMC_AssertHandler?

If i define a XMC_AssertHandler() over Uart, the problem will be: during init from the Uart, XMC_AssertHandler is called, but uart is not working at this time.
Then the cat bites into the tail.
What is there before: the egg or the chicken?

And how can i enable XMC_AssertHandler() for my user-output?
I define XMC_ASSERT_ENABLE in xmc_common.h, but this doesn't work.....

My Handler looks like this:

void XMC_AssertHandler(const char *const msg, const char *const file, uint32_t line)
{
uint8_t cBuffer[256];
uint16_t iLen=0;

iLen = sprintf( cBuffer, "%s %s %d",msg, file, line );
UART_Transmit(&UART_1 , cBuffer, iLen );
}
0 Likes
7 Replies
User11996
Level 3
Level 3
Hi.

I've test the same with Symbols, without any success.
I add a symbols for the compiler and the same for the assembler ( UNIT_TEST 😞

A #ifdef UNIT_TEST block, won't be compiled!!!

2494.attach

Any idea to compile conditional????????
0 Likes
User11996
Level 3
Level 3
Hi.

Is really no one here who has ever tried conditional compile with dave?
Has no one any idea to set up a "Conditional compile" with dave?

How do you do unit tests ? ????
Do the test functions always remain active and only a test is executed instead of a program run in your project (because no conditional compile possible??) ???

?
0 Likes
lock attach
Attachments are accessible only for community members.
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

You are looking for setting preprocessor symbols.
Go to the Properties of your project and click on C/C++ Build>Settings>ARM-GCC C Compiler>Preprocessor.
2498.attach

On how to use the XMC_ASSERT have a look to the attached example included in XMClib examples/XMC4500_series/UART/UART_PRINTF
2499.attach

Regards,
Jesus
0 Likes
User11996
Level 3
Level 3
Hi jferreira.

Thanks for you reply.

But this is NOT working in combination with a additional Build-Configuration.

Let me explain.

I have 3 build-configurations:
- Debug
- Release
- Test (for unit-test's)

If i work in Debug-configuration and add a preprocessor-symbol "UNIT_TEST" ( in Properties of my project C/C++ Build>Settings>ARM-GCC C Compiler>Preprocessor)

the compiler knows the symbol if defined -> . #if defined(UNIT_TEST) is working


If i work in Release-configuration and add a preprocessor-symbol "UNIT_TEST" ( in Properties of my project C/C++ Build>Settings>ARM-GCC C Compiler>Preprocessor)

the compiler knows the symbol if defined -> . #if defined(UNIT_TEST) is working


But, if i add a preprocessor-symbol "UNIT_TEST" only in Build-configuration Test ( and delete the symbol in config Debug and Release)
the compiler doesn't know the define: #if defined(UNIT_TEST) is not working

I set configuration Debug as active -> symbol UNIT_TEST unknown -> correct
I set configuration Release as active -> symbol UNIT_TEST unknown -> correct
I set configuration Test as active -> symbol UNIT_TEST unknown -> bug / failure !!! The code-block is greyed out -> see picture below

I used BuildConfiguration -> Set Active -> Test
and i used BuildConfiguration -> Manage: choose Test and -> Set Active
to switch between the 3 Build-Configurations.


Is this a Bug in Dave?

2504.attach

2505.attach



The code-block is greyed out:

2506.attach
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

For me it is working. I created a third configuration, named Test, as a copy of the Debug one.
In the properties of the project, in the preprocessor macros I added UNIT_TEST.

For the Debug and Release configurations, the macro is not defined and therefore the code is grayed out.
2511.attach

For the Test configuration the macro is defined and therefore the code is not grayed out.
2512.attach

Please check the setting in the indexer
2510.attach

Sometime also helps to rebuild the index.

Regards,
Jesus
0 Likes
Howard-33614
Level 1
Level 1
First like given 5 sign-ins First question asked
I have run into the exact same problem today, I have a new build configuration where I have added the macro ROUND_CASE.

It all seems fine when looking at the IDE, the section of code that is dependent on that macro to be defined is greyed out when I am NOT in my new build configuration. When I am in my new build configuration then the code is enabled and it all "looks" good.

The problem is that the actual code does not get executed at run time.

5406.attach

I reach my breakpoint at line 59 and then step through the code but line 62 is never executed, it just goes straight into line 65 (not seen in the snippet, no need for that). My test variable in the code is never assigned the 0xAA value.

Can someone please try this with an actual target and step through the code to see if it works at run time?

Thanks in advance.
-Howard
0 Likes
Howard-33614
Level 1
Level 1
First like given 5 sign-ins First question asked
Never mind, this works just fine, turns out I made a mistake when creating my new build configuration (I did not copy the settings from the Debug version so the debugger was not happy).
Thanks to my local Infineon's FAE, he came to the rescue fairly quickly.
0 Likes