adafruit / Adafruit-Trinket-USB

Arduino libraries allowing Trinket to act as USB devices
209 stars 75 forks source link

Warning about duplicate #define __SFR_OFFSET in TrinketMouse #22

Open allyourcode opened 7 years ago

allyourcode commented 7 years ago

I'm able to use TrinketMouse successfully, but when I compile I get an annoying warning:

In file included from /Users/danielwong/Documents/Arduino/libraries/TrinketMouse/usbdrvasm_includer.S:24:0:
/Users/danielwong/Documents/Arduino/libraries/TrinketMouse/usbdrv/usbdrvasm.S:18:0: warning: "__SFR_OFFSET" redefined
 #define __SFR_OFFSET 0      /* used by avr-libc's register definitions */
 ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/io.h:99:0,
                 from /Users/danielwong/Documents/Arduino/libraries/TrinketMouse/cmdline_defs.h:26,
                 from /Users/danielwong/Documents/Arduino/libraries/TrinketMouse/usbdrvasm_includer.S:22:
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/sfr_defs.h:141:0: note: this is the location of the previous definition
 #    define __SFR_OFFSET 0x20
 ^

I tried to solve this by commenting out line 18 in usbdrvasm.S, but that just broke everything. I also tried replacing that #define with #include <avr/sfr_defs.h> but that didn't do the trick either.

Obviously, this isn't the end of the world, but it would be nice to have clean builds.

christakahashi commented 7 years ago

I'm having the same issue. Arduino 1.8.2, windows 10. Same warning.

jous commented 6 years ago

The avr libraries (sfr_defs.h) first set _SFR_OFFSET to 0x20. Later on usbdrvasm165.inc and asmcommon.inc need _SFR_OFFSET to be 0x00. usbdrvasm.S sets it to 0x00, but this generates a warning because defined macros are supposed to be constant.

In usbdrvasm.S, please add

#undef __SFR_OFFSET

before the

#define __SFR_OFFSET 0 /* used by avr-libc's register definitions */

line to suppress the message completely.

jackhumbert commented 6 years ago

I'm not sure if this is applicable here, but I had a similar issue, and solved it by using the __ASSEMBLER__ flag:

#ifndef __ASSEMBLER__
  #include <avr/io.h>
#endif