1

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 Oct 13 '16 at 10:44
  • Yeah, True. Pardon me for the misunderstanding. This is what I exactly asked. – goddland_16 Oct 13 '16 at 11:54
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.

  • 2
    Since 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 Oct 13 '16 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 Oct 14 '16 at 6:06
  • @goddland_16 That was an example. Arduino MEGA 2560 uses __AVR_ATmega2560__. You can check label on the MCU. – KIIV Oct 14 '16 at 6:28
  • The correct Arduino architecture macro is ARDUINO_ARCH_AVR, not DARDUINO_ARCH_AVR. – per1234 Oct 14 '16 at 9:23
  • 1
    @per1234: Fixed, copy&paste error as usual... – KIIV Oct 14 '16 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.