board specific define statements

Where are the board specific “define” statements such as “AVR_ATmega328P” defined in the core?

These statements seems to confuse eclipse a lot. For instance Hardwareserial.cpp starts wit the following line:

// this next line disables the entire HardwareSerial.cpp, 
// this is so I can support Attiny series and any other chip without a uart
#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)

However these UBRRH macros are not defined anywhere on the core but rather in the /avr/include which is conditionally compiled based on the board type (e.g. AVR_ATmega328P) in io.h

That is why, eclipse code analyzer generates error everytime it sees anything related with HardwareSerial.h.

is it the avr-gcc that implicitly defines the board type based on -mmcu parameter? I could not find anywhere neither in the core nor in the avr/include where the board types (e.g. AVR_ATmega328P) are explicitly defined.

Not sure how the defines get folded into the compile process, however I think the source of the defines is the boards.txt file in the arduino core directory. Here is the first board entry of that file in version 22:

##############################################################

uno.name=Arduino Uno
uno.upload.protocol=stk500
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
uno.bootloader.file=optiboot_atmega328.hex
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino

##############################################################

Lefty

Not sure how the defines get folded into the compile process, however I think the source of the defines is the boards.txt file in the arduino core directory. Here is the first board entry of that file in version 22:

In the IDE, the use has to select the board type. Presumably, that information is included in the compiler command line, in some format.

PaulS:
In the IDE, the use has to select the board type. Presumably, that information is included in the compiler command line, in some format.

Arduino IDE uses board.txt file to determine the -mmcu, -DF_CPU and -DARDUINO parameters. We can see that in the verbose output such as:

avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -I/usr/share/arduino/hardware/arduino/cores/arduino /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp -o/tmp/build1970894109843045849.tmp/HardwareSerial.cpp.o

It seems to me as if the avr-gcc internally defines the board type based on the "-mmcu" parameter and the conditionally compile the rest. However, unless these board specific statements are explicitly defined in the code itself, it becomes impossible to track the call hierarchy on the code. How may I know the outcome of the following code:

#if defined(UBRRH)
  extern HardwareSerial Serial;
#elif defined(USBCON)
  #include "usb_api.h"
#endif

I need a way to understand whether UBRRH or USBCON is defined for my board (so does the code analyzer of the Eclipse and intellisense of VS).

I need a way to understand whether UBRRH or USBCON is defined for my board

UBRRH and USBCON are register names. AVR Libc conveniently provides pseudo-variables of the same name if the processor has those registers. To find out more about what registers are available for your processor, Use the Datasheet, Luke.