Multi-Architecture libraries. Determining target platform or board type.
I'm debugging a multi-platfrom library which supports multiple architectures and appears also to have worked at one time with an older version of an STM32 platform. I'm trying to get it to work with an STM32F103C8 "bluepill" and am using the Official STMicroelectronics Arduino Core version 2.2.0 (the latest)
The library I am debugging selects code depending on the platform using preprocessor macro definitions such as
#if defined(__AVR_ATmega32U4__)
. . .
#endif
#if defined(__SAM3X8E__)
. . .
#endif
#if defined(__STM32F1__)
. . .
#endif
It is the last one which now appears to fail. In the meantime, by looking at another multi-platform library, I have discovered that the following will work (with STMicroelectronics Arduino Core version 2.2.0):
#if defined(STM32F1)
. . .
#endif
Here is the sample code I used added to the blink sketch:
/*
Blink
*/
#if defined(STM32F1)
#warning IS "STM32F1"
#else
#warning IS NOT "STM32F1"
#endif
#if defined(__STM32F1__)
#warning IS "__STM32F1__"
#else
#warning IS NOT "__STM32F1__"
#endif
#if defined(ARDUINO_ARCH_STM32F1)
#warning IS "ARDUINO_ARCH_STM32F1"
#else
#warning IS NOT "ARDUINO_ARCH_STM32F1"
#endif
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
and here the sumarised results:
C:\Users\6v6gt\Documents\Arduino\_STM32\Blink1\Blink1.ino:8:2: warning: #warning IS "STM32F1" [-Wcpp]
8 | #warning IS "STM32F1"
| ^~~~~~~
C:\Users\6v6gt\Documents\Arduino\_STM32\Blink1\Blink1.ino:16:2: warning: #warning IS NOT "__STM32F1__" [-Wcpp]
16 | #warning IS NOT "__STM32F1__"
| ^~~~~~~
C:\Users\6v6gt\Documents\Arduino\_STM32\Blink1\Blink1.ino:22:2: warning: #warning IS NOT "ARDUINO_ARCH_STM32F1" [-Wcpp]
22 | #warning IS NOT "ARDUINO_ARCH_STM32F1"
| ^~~~~~~
Compiling libraries...
Compiling library "SrcWrapper"
It is not obvious from the platform's boards.txt file or the platform.txt file which is the correct macro definition to use. Neither can I find a clear formula in this link Platform specification - Arduino CLI
So how can the correct platform identifier macro be chosen/ determined ?
Here are the boards.txt and platform.txt files, zipped because .txt is a forbidden extension:
boards.zip (35.8 KB)
platform.zip (3.4 KB)