I am using a custom library for Arduino Mega which uses AES library for AES-128 encryption.
However, when I try to use that library in Intel Genuino 101 development board, it shows compilation error which is because the assembly language written in AES library was compatible with Atmel devices only.
And my question is whether there is a way, my code can automatically detect the GENUINO board by writing some sort of signature verification of this board and hence I can exclude the encryption part if it can successfully detect GENUINO 101.
For any queries, feel free to bug me, thanks.
-
No, you do not want your code to detect the Genuino 101. Your code cannot run until is is compiled. You want the compiler to detect whether it is compiling for an AVR-based Arduino or for something incompatible (whether it's ARC, ARM or Intel is irrelevant). What you want is called conditional compilation, and that is what KIIV's answer is about.Edgar Bonet– Edgar Bonet2016年10月13日 10:44:45 +00:00Commented Oct 13, 2016 at 10:44
-
Yeah, True. Pardon me for the misunderstanding. This is what I exactly asked.goddland_16– goddland_162016年10月13日 11:54:34 +00:00Commented Oct 13, 2016 at 11:54
1 Answer 1
Arduino defines some macros so you can use conditional compilation. For example these are from boards.txt:
- use
ARDUINO_AVR_PROMICRO
if it's specific for board variant - use
ARDUINO_ARCH_AVR
if it's specific for Arduino with AVR
Also avr-gcc defines macros according to cpu settings (this should be similar for other platforms too):
- use
__AVR_ATmega32U4__
if it's specific for only one MCU - use
__AVR__
if it's compatible with all AVR based MCUs
And code examples:
#if defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__)
// something for ATmegaXX8 family...
#else
// ...
#endif
#ifdef __AVR__
// Code related to AVR
#else
// Code for other architectures
#endif
More about predefined macros in avr-gcc.
-
2Since the library seems to be compatible with all AVR-based Arduinos, it is probably best to test for
#if __AVR__
(or#ifdef __AVR__
) rather than for specific MCUs.Edgar Bonet– Edgar Bonet2016年10月13日 10:39:11 +00:00Commented Oct 13, 2016 at 10:39 -
@KIIV I tried #if defined AVR and it accepts, but for #if defined(AVR_ATmega328), I could not find the expected solution. Can you suggest any link which explains more on this?goddland_16– goddland_162016年10月14日 06:06:51 +00:00Commented Oct 14, 2016 at 6:06
-
@goddland_16 That was an example. Arduino MEGA 2560 uses
__AVR_ATmega2560__
. You can check label on the MCU.KIIV– KIIV2016年10月14日 06:28:46 +00:00Commented Oct 14, 2016 at 6:28 -
1@per1234: Fixed, copy&paste error as usual...KIIV– KIIV2016年10月14日 09:25:26 +00:00Commented Oct 14, 2016 at 9:25
-
1@KIIV yeah checked it. Working and for UNO it is [AVR_ATmega328P] .goddland_16– goddland_162016年10月14日 09:52:32 +00:00Commented Oct 14, 2016 at 9:52
Explore related questions
See similar questions with these tags.