Go Down

Topic: Identifying Due in Libraries (Read 4 times) previous topic - next topic

Tom Carpenter

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
Code: [Select]
#ifdef WEAK
#define ARM_CORTEX
#endif
~Tom~

Graynomad

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

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Tom Carpenter

Yup, it works. I can live with that.
~Tom~

cmaglie

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

Code: [Select]

#if defined(__arm__)

// Arduino Due Board follows

#elif defined(__AVR__)

// Other AVR based Boards follows

#else

#error Architecture or board not supported.

#endif
C.

Tom Carpenter

Even better as it is part of the compiler, not the core :D
~Tom~

Paul Stoffregen

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?

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

Tom Carpenter


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?


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.
~Tom~

Paul Stoffregen

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.

Nantonos


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?


And what would be a suitable check for Teensy 3.0?

Paul Stoffregen


And what would be a suitable check for Teensy 3.0?


#if defined(__MK20DX128__)

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?

MichaelMeissner


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__.

Go Up