I need to modify an existing library that relies on being able to detrmine what board / processor the code is being run on. To do this, it uses definitions such as this for an Arduino Mega:
// Arduino Mega
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
I need to update the library for a further 2 boards, namely the Raspberry pi pico (mbed os) and the Robotis OpenCR.
I can't seem t find where the processor name is actually defined. If someone could point me in the right direction, that would be great. Thanks.
Edit: If anyone knows what the equivelent define is for the raspbery pi pico - rp2040, that would be fantastic!
1 Answer 1
They are defined by the compiler itself, and based on the name of the microcontroller passed to the compiler as (for AVR GCC) -mcpu=<mcu name>
.
You can list the defines for a version of GCC using (for example for AVR gcc):
avr-gcc -mmcu=atmega328p -dM -E - < /dev/null
Not sure what you'd use on Windows for /dev/null
. Different target compilers use different flags to define the MCU, and you of course need to know the MCU the board uses to pass to the compiler.
You will have to investigate what relevant flags are passed to the compiler for your desired chips, and you can find those by looking in the platform.txt file for the core associated with the board.
-
I'm most interested in the pico, which would be RP2040 or some variant of that name. I'm not sure it uses the GCC compiler, could be wrong though.Ben Bird– Ben Bird2021年06月03日 17:16:51 +00:00Commented Jun 3, 2021 at 17:16
-
Almost everything that's not Microsoft uses the GCC compiler...Majenko– Majenko2021年06月03日 17:32:18 +00:00Commented Jun 3, 2021 at 17:32
Explore related questions
See similar questions with these tags.
#ifdef ARDUINO_AVR_UNO