Pages: [1]   Go Down
Author Topic: Identifying Due in Libraries  (Read 3628 times)
0 Members and 1 Guest are viewing this topic.
Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#ifdef WEAK
#define ARM_CORTEX
#endif
Logged

~Tom~

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yup, it works. I can live with that.
Logged

~Tom~

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#if defined(__arm__)

// Arduino Due Board follows

#elif defined(__AVR__)

// Other AVR based Boards follows

#else

#error Architecture or board not supported.

#endif
Logged

C.

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Even better as it is part of the compiler, not the core smiley-grin
Logged

~Tom~

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

~Tom~

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And what would be a suitable check for Teensy 3.0?

#if defined(__MK20DX128__)
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 64
Posts: 2101
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1832
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: