0

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!

2
  • in Arduino you can use macro ARDUINO_{build.board} where build.board is defined in boards.txt for example as uno.build.board=AVR_UNO. the #idef is then #ifdef ARDUINO_AVR_UNO
    – Juraj
    Commented Jun 3, 2021 at 18:03
  • the more you can avoid board detection, the more places your program will run or just need a slight modification instead of something that confuses the developer.
    – dandavis
    Commented Jun 5, 2021 at 17:29

1 Answer 1

2

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.

2
  • 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
    Commented Jun 3, 2021 at 17:16
  • Almost everything that's not Microsoft uses the GCC compiler...
    – Majenko
    Commented Jun 3, 2021 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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