I'm facing a problem on Eclipse IDE that when compiling my project (which has #include <avr/io.h>), the compiler includes avr/iom16.h (for ATmega16) instead of avr/iom32.h (for my ATmega32). It appears when I press ctrl + click on any constant like DDR in my program, It opens the avr/iom16.h file which means it was included.

I've checked the compiler options of the project and found that the control switch option -mmcu=atmega32 is fine, the same is for assembler options and linker options.

I've tried to make a new project, chosen target hardware as Atmega 32 -as I usually do-, copied my source files into the new project, compiled the project, but the problem persists.

A strange thing also need to be mentioned is when I open the file avr/io.h after compiling, it is showing all the controller constants in gray background (which means they are not defined) except for this one __AVR_ATmega32__ in white background (which means it is defined). The following is the two lines of code that appears with a white background:

#elif defined (__AVR_ATmega32__)
#  include <avr/iom32.h>

So, what is making the trouble then? is it could be something in the earlier preprocessing stages?

Any help would be appreciated. Thanks in advance!

  • \$\begingroup\$ Don't place too much trust in the coloring of things in an IDE window. This is typically not a result of evaluation by the actual compiler. Look at what flags are being passed to gcc that could pre-define things, and look up the built in defines; in general I would not expect the -mmcu to define things to pass to the code. Also consider just doing a full text search (grep -r or whatever IDE function) for some of these keywords in the codebase. \$\endgroup\$ – Chris Stratton Aug 31 '19 at 9:52
  • \$\begingroup\$ Without having the AVR plugin installed and not even Eclipse on my current machine, just my 2 cents. What Eclipse shows to you it not what the compiler sees. But you can setup Eclipse for this, I would search the preferences for something like "scanner" and see which command (most probably some GCC call) with which options are set. At this entry the MCU should be corrected if wrong. Did you search the web with "AVR ATmega32 Eclipse code analysis"? \$\endgroup\$ – the busybee Aug 31 '19 at 10:24
  • \$\begingroup\$ Please remove the avrdude tag as it has no relevance to the issue. \$\endgroup\$ – Chris Stratton Aug 31 '19 at 10:31
  • \$\begingroup\$ @ChrisStratton I've written this command on the terminal avr-gcc -dM -E - < /dev/null it showed me all the predefined macros in avr-gcc. I used grep to find anything in relation to m16 or 16 or mmcu but found nothing that may affect the target hardware. \$\endgroup\$ – Gamal Othman Aug 31 '19 at 10:38
  • \$\begingroup\$ You neglected to put your -mmcu in the test command line. It looks like that should actually produce the __AVR_ATmega32__ if done right. Otherwise you can define things with -D on the command line but the format of that one is the sort of thing set by the compiler, contrary to my earlier thought. \$\endgroup\$ – Chris Stratton Aug 31 '19 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.