Where are these variables defined. I look in boards.txt or nano.variables portenta.variables but the defined words don't work it is these weird words that have ARDUINO_ in front of them.
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
#if defined(ARDUINO_ARDUINO_NANO33BLE) || defined (YOUR_BOARD1)
Serial.println("Your board is defined as ARDUINO_ARDUINO_NANO33BLE");
#endif
#if defined(ARDUINO_NANO33BLE) || defined (YOUR_BOARD1)
Serial.println("Your board is defined as ARDUINO_NANO33BLE"); // does not print
#endif
#if defined(PORTENTA_H7_M7) || defined (YOUR_BOARD1)
Serial.println("Your board is defined as PORTENTA_H7_M7"); // does not print
#endif
#if defined(ARDUINO_PORTENTA_H7_M7) || defined (YOUR_BOARD1)
Serial.println("Your board is defined as ARDUINO_PORTENTA_H7_M7");
#endif
#if defined(CORE_CM7) || defined (YOUR_BOARD1)
Serial.println("Your board is defined as CORE_CM7");
#endif
Serial.println("---------------------");
delay(1000);
// put your main code here, to run repeatedly:
}
The -DARDUINO_ARCH_{build.arch} flag might seem redundant to the -DARDUINO_ARCH_MBED flag. However, it is not because the Arduino Mbed OS boards platform has been split into a separate architecture for each of the logical board families. For example, when compiling for the Portenta H7 board, this will cause the definition of an ARDUINO_ARCH_MBED_PORTENTA macro because the architecture of the "Arduino Mbed OS Portenta Boards" platform is mbed_portenta.
The build.board property referenced in the -DARDUINO_{build.board} flag is defined in the platform's boards.txt file. For the Portenta H7, it is here:
The definition of that property references yet another property: build.variant, which is defined here if you have "Main Core" selected from the Tools > Target core menu in Arduino IDE:
@kolaha and @ptillisch thanks for the detailed explanation, what I think I hear you saying is that just add "ARDUINO_" to any of the defined words. Which is what I am seeing with my code above.
so the defined word "ARDUINO_NANO33BLE" becomes
"ARDUINO_ARDUINO_NANO33BLE"
Is that correct, because that is what works in the above sketch.
That is not what I am saying. I think I explained the origin of those ARDUINO_* macros fairly well in my previous reply. If there is something specific you don't understand about what I wrote, let me know and I'll see if I can make it more clear.
As for the defines.txt files mentioned by kolaha, these are simply a list of -D flags that are added to the compilation commands using the @<file> argument:
ARDUINO_ is not prefixed to the macros defined by the -D flags in the defines.txt files. They are defined exactly as written in that file, just as they would be if you added the flags to a compiler command you invoked directly..
I explained it already in my previous reply.
The command pattern contains this flag: -DARDUINO_{build.board}.
The "Arduino Nano 33 BLE" board definition sets the build.board property referenced in the command pattern to ARDUINO_NANO33BLE:
Put it together and you get a macro named ARDUINO_ARDUINO_NANO33BLE.
But if the flag in the command pattern had been -DFOO__{build.board} and the board definition had set the value of the build.board property to BAR, then the macro would instead be named FOO_BAR.
There is no magical arbitrary addition of an ARDUINO_ prefix. It is simply a common convention used to create a "namespace" of sorts for the macros in order to reduce the chance of name collisions with macros defined elsewhere. The platform developer has complete control over the definition and naming of such macros.