AnsweredAssumed Answered

Beginner Question - #ifdef -> Where do I define the data the conditional statements are switching on

Question asked by ro.dru on Nov 3, 2013
Latest reply on Nov 3, 2013 by Clive One

I have been working with the STM8S and STM32F0 Discovery boards.  One thing that I see often is the preprocessor directives and macros.  One example found in the STM32 discovery demo code is:

  #ifdef DEBUG

I tried to google the topic and I get a lot more information regarding the usage of #ifdef and creating macros etc.  This is great but nothing quite answered my question.

But my question is do I set the DEBUG (or other #ifdef) directly in code by using:
#define DEBUG

Or should this be done a different way?

I am using IAR and I can go project->options
In this window I can go to the Preprocessor tab and there is a box there called defined symbols.  Currently it is greyed out unless I choose to "override inherited settings" but there is a "VECT_TAB_FLASH" in this box.

Should I add my #defines in this box?

I get that the #ifdef is switching based on defines, but where should I be setting these defines.  Is the DEBUG define automatically handled by the IAR IDE and compiler? 

If it is where would I handle setting switches say for compiling to two different versions of the STM32 chip?  For example I have #ifdef CHIPONE and #ifdef CHIPTWO sections in my code.  Do I create two different projects with the same source code but setup the defines in the options box above?  Or do I include a project defines file and set all my switches in there using #defines.