AVR libc device defines ?

Nov 19, 2006 1 Replies

Here's a newbie question. I'm doing the the example program that's listed in the gcc AVR libc documentation. I'm using the STK500 dev. board with a ATMEGA8515 and AVR Studio. The example provides a file iocompat.h that defines some device specific stuff. Here's a exerpt:



#if defined(__AVR_AT90S2313__) # define OC1 PB3 # define OCR OCR1 # define DDROC DDRB # define TIMER1_OVF_vect TIMER1_OVF1_vect #elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__) # define OC1 PB1 # define DDROC DDRB # define OCR OCR1 #elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || \ defined(__AVR_AT90S4434__) || defined(__AVR_AT90S8535__) || \ defined(__AVR_ATmega163__) || defined(__AVR_ATmega8515__) || \ defined(__AVR_ATmega8535__) || \ defined(__AVR_ATmega164P__) || defined(__AVR_ATmega324P__) || \ defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__)



My question, where are these device constants defined? For example, I think (__AVR_AT90S8515__) is defined somewhere for my project but where. I've searched all the include headers that come with gcc and can't find it. Can a makefile define this somehow? Does AVR studio do it somehow by knowing I'm using a 8515? Is it getting built by some algorithm somewhere and that's why I can't find this string?



I'm baffled. Any insight is appreciated.



They're not in any source file. They're provided by the compiler.

You can examine this like so:

touch foo.S avr-gcc -dM -E -mmcu=atmega8 foo.S

(substitute the name of your compiler for "avr-gcc" if it's different). The "-dM" instructs it to print out the things which are defined; the "-E" tells it to stop after preprocessing.

You'll see several dozen predefined constants, including the ones you're interested in (for example, -mmcu=atmega8 sets __AVR_ENHANCED__, __AVR_ATmega8__, __AVR_ARCH__, etc.)

In fact, it could (you can explicitly set things on the command line as well with the -D option), but in this case that probably isn't the mechanism being used.

There's probably an -mmcu= or equivalent option being passed from your development environment if you picked the target part there, yes.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required