Identifying Due in Libraries

Could you tell me if there is a #define that identifies whether the board is a ARM/Due or an AVR/Uno/Mega/Leonard/etc? The best I could come up with it to just pick a random #define that is in the Arduino.h file for the Due, but not in the Arduino.h file for the atmega core.

I stuck this at the top of my cpp file, which appears to work, but surely there is a more future proof method

#ifdef WEAK
#define ARM_CORTEX
#endif

There's a LIB_SAM define in chip.h, I don't know if that will be good enough for an ID.


Rob

Yup, it works. I can live with that.

I see that gcc has the following built-in defines that I used into the SD library to distinguish between architectures:

#if defined(__arm__) 

// Arduino Due Board follows

#elif defined(__AVR__) 

// Other AVR based Boards follows

#else

#error Architecture or board not supported.

#endif

Even better as it is part of the compiler, not the core :smiley:

Using "#if defined(arm)" will also match to Teensy 3.0, Leaflabs Maple, and all other ARM-based boards that are created in the future.

Perhaps "#if defined(SAM3X8E)" would be a better check for Due?

Looks like it, in sam\boards.txt

arduino_due_x_dbg.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON


Rob

For what I want it to mean that is not an issue, in fact it is a good thing. Basically it is a check to say, if it is an ARM processor, don't use the PROGMEM command, and default to using digitalWrite() rather than direct port writes.

Yes, of course, if your goal is to detect 32 bit ARM vs 8 bit AVR, then arm and AVR are the symbols you want.

And what would be a suitable check for Teensy 3.0?

Nantonos:
And what would be a suitable check for Teensy 3.0?

#if defined(MK20DX128)

Hi all, I'm updating my AtomicBlock library for the Due, the update contains versions for 'ARM' and the 'Cortex M3' variant. However I can't find any defines to conditionally decide which to use.

Is there a macro like _TARGET_ARCH_xx or similar?

pYro_65:
Hi all, I'm updating my AtomicBlock library for the Due, the update contains versions for 'ARM' and the 'Cortex M3' variant. However I can't find any defines to conditionally decide which to use.

Is there a macro like _TARGET_ARCH_xx or similar?

Looking at the current GCC sources, there doesn't appear to any single macro that completely identifies each chip, rather there are a bunch of feature macros defined (i.e. thumb/thumb2 instruction sets, whether it has DSP multiply, etc.). I believe the Arduino IDE defines things like MK20DX128 and SAM3X8E.

Hello, i know it is an old post anyway could someone say me where these define flag like avr_atmega328p or ARDUINO_AVR_UNO are set?

Sometimes i found them in pins_arduino but not everytime

avr_atmega328p is set by the compiler as a consequence of the -mmcu=atmega328p command-line option.

The arm-gcc compiler isn't quite so customized, so it looks like SAM3X8E is set explicitly with a -D command-line option.

The other symbols used in newer versions of the IDE (1.5+?), like ARDUINO_SAM_DUE or ARDUINO_AVR_UNO are also set from the command line using -D, based on the contents of the xxx.build.board variable defined in boards.txt and the recipes in platform.txt

The build command can be see by turning on verbose compilation in the preferences dialog. It looks like this:

"/Applications/arduino/Arduino-1.8.2.app/Contents/Java/portable/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf  -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L [color=red]-DARDUINO=10802 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM  -D__SAM3X8E__[/color] -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino Due"' "-I/Applications/arduino/Arduino-1.8.2.app/Contents/Java/portable/packages/arduino/hardware/sam/1.6.11/system/libsam" "-I/Applications/arduino/Arduino-1.8.2.app/Contents/Java/portable/packages/arduino/hardware/sam/1.6.11/system/CMSIS/CMSIS/Include/" "-I/Applications/arduino/Arduino-1.8.2.app/Contents/Java/portable/packages/arduino/hardware/sam/1.6.11/system/CMSIS/Device/ATMEL/" "-I/Applications/arduino/Arduino-1.8.2.app/Contents/Java/portable/packages/arduino/hardware/sam/1.6.11/cores/arduino" "-I/Applications/arduino/Arduino-1.8.2.app/Contents/Java/portable/packages/arduino/hardware/sam/1.6.11/variants/arduino_due_x" "/var/folders/jz/5yb8f2hr8xjcpf0059bsfz4r0000gn/T/arduino_build_806983/sketch/stdio_test.ino.cpp" -o "/dev/null"

thanks westfw I was looking for this flag inside the core and not in board.txt now i found all them!

anyway i found also this, maybe could be useful for future readers: