How to use TARGETPROC and TARGETCHIP?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use TARGETPROC and TARGETCHIP?

1,785 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RA1981 on Sat Jul 16 00:08:54 MST 2011
Hi,

this question is based on this thread:
http://knowledgebase.nxp.com/showthread.php?t=1687

Based on that thread I tried to use the TARGETCHIP macro (using LPCx 4):
#if TARGETCHIP == LPC1114_301

but it doesn't work, throws a expression syntax warning and the expression is taken regardless of the value!!!
Using quotation marks around LPC1114_301 gives a error "token ""LPC1114_301"" is not valid in preprocessor expressions".
What am I doing wrong?

Another thing is, as suggested in the above mentioned thread, it would be great if CodeRed implements the symbols TARGETDEVICE (LPCxxxx) and TARGETREV (e.g.302) if possible.

Regards,

Ralf
0 Kudos
Reply
9 Replies

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RA1981 on Sat Jul 30 05:02:35 MST 2011

Quote:
Sorry, but no.

That's okay :)  Regards,  Ralf
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sat Jul 30 01:26:11 MST 2011

Quote:


So, I ask again to CodeRed (didn't get a answer last time, even a 'no' is okay):
Is it possible that you implement two additional symbols which reflect   the used target and revision separately? Something like TARGETREV and   TARGETMCU?

Sorry, but no.
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RA1981 on Fri Jul 29 11:24:15 MST 2011
Hi,

I saw that the LPC13xx/17xx chips don't have a revision identifier. I  don't know if it's because they are all currently at the first revision  or if it's a break in the line => LPC11xx/13xx have a device ID  register, LPC17xx don't have it (bootloader API must be used).
However, TARGETCHIP now result in different symbols (with and without revision, depending on the used chip).

So, I ask again to CodeRed (didn't get a answer last time, even a 'no' is okay):
Is it possible that you implement two additional symbols which reflect  the used target and revision separately? Something like TARGETREV and  TARGETMCU?

For all of you which like the idea to have it separated I attached a  device header file which does it (rename it to device.h). It covers LPC11xx/13xx/17xx devices  and defines TARGETFAM, TARGETMCU and TARGETREV, e.g. LPC13XX, LPC1343  and 302. For devices which don't have a revision number TARGETREV will  expand to 000.
The corresponding device header file is also included.
Note: I couldn't fully test it, so please report any bugs found.

Anyone knows a way to customize the project and file templates so that  the symbols mentioned in the answers above are created automatically? (previous question also not answered by CodeRed ;))
Customizing the C template file would be also good to include the  "device.h" instead of the corresponding chip header file.

Regards,

Ralf
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RA1981 on Sun Jul 17 22:56:11 MST 2011
@CodeRed:
Thank you for clarification.

Quote:
Just add "${TargetProc}" to the Compiler symbols


Is there a way to modify the project template to get this symbol automatically in new projects?

@Atomicdog & TheFallGuy:
Thank you for showing up the possible solutions. This is really close to what I want :)

Regards,

Ralf
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sun Jul 17 13:31:21 MST 2011
RA1981: You can already do this. Just add
${TargetProc}
to the Compiler symbols. This is very similar to what was suggest by TheFallGuy in his first posting, except he assigned it a value (=1)

atomicdog: These are not environment variables. They are IDE internal variables that you can make available to the compiler and other tools. Hope that is clear.
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Sat Jul 16 20:02:11 MST 2011

Quote: RA1981
Hmmm... But that means that these symbols have to be defined in the linker scripts on each project manually.

...

Regards,

Ralf



You don't need to change the linker script. Those are environment variables not preprocessor symbols. So you need to convert the env variable to a preprocessor symbol like TheFallGuy has shown. This can be done through the IDE which defines the symbol via the command line.
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RA1981 on Sat Jul 16 07:08:43 MST 2011
Hmmm... But that means that these symbols have to be defined in the linker scripts on each project manually. Of course, sometimes the scripts must be modified, but I always try to avoid that if possible - I think the IDE should do as much as possible for the user.
The Keil compiler defined preprocessor symbols according to the selected target. Symbol name was the selected target itself.
So, instead of comparing symbols against each other the approach is to check if the symbol is defined:
#ifdef LPC1114
...
#else if defined LPC1343
...
else if defined LPC1768
...
#endif


@CodeRed:
Is this possible for one of the next releases?

Regards,

Ralf
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Sat Jul 16 01:05:49 MST 2011
I had another thought on this...
Using
- TARGETPROC=${TargetProc}
then this works:
#define LPC1768 1
#define LPC1114_301 2

#if TARGETCHIP == LPC1768
#warning LPC1768
#else
#warning LPC1114_301
#endif


However, I think this (comparison against another preprocessor symbol) is a GCC extension and so wouldn't work across other compiler.
0 Kudos
Reply

1,775 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Sat Jul 16 00:56:31 MST 2011
C preprocessor comparison operations will only work with integers - you cannot use strings. Therefore, I suggest you do something like this:
- In the Compiler symbols page, use ${TargetChip}=1
- In your source, test for the chip like this
#if LPC1768 == 1
...
#end
OR
#ifdef LPC1114_301
...
#endif
0 Kudos
Reply