Missing board compiler switch

Status
Not open for further replies.

Elmue

Well-known member
Hello Paul

It would be great if you add the following "feature".
It will not cost you more than 5 minutes.


When you compile a sketch for an Arduino board you can detect in code for which board the code has been compiled.
For example if you compile for "Arduino Uno" you will get the compiler switch ARDUINO_AVR_UNO defined.

Sadly none of the Teensy boards can be detecetd in code as easy as this.
It would be very helpful if you add to the file "platform.txt" the following commandline parameter:

-DTEENSY_{build.board}

With that you could use in code:

#if defined(TEENSY_TEENSY31)
// This is a Teensy 3.1 board
#endif

For more details please see my posting on Arduino.StackExchange.com:

http://arduino.stackexchange.com/a/21257/18754
 
There are easy to test defines specified for Teensy boards:

teensy31.build.flags.defs=-D__MK20DX256__ -DTEENSYDUINO=127
teensy30.build.flags.defs=-D__MK20DX128__ -DTEENSYDUINO=127
teensyLC.build.flags.defs=-D__MKL26Z64__ -DTEENSYDUINO=127

like: #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
 
Hello Defragster

You did not understand my request.

I know that I can obtain the CPU.
This is nothing new.
But I want the BOARD, not the CPU.
 
Elmue - as far as I know there is one CPU type per board type so they are one in the same? When the newer Teensy's ship they will be the same - having a unique CPU defining them as a unique Teensy. There are already one or two new #define's dropping into the PJRC sources - one or the other or both when shipping will constitute a new Teensy.

Unlike GENUINO units - to date - the same CPU is never present on multiple configurations of hardware. Indeed PJRC could add the "build.board" to the compile switches - but it would be redundant.

#if defined(__MK20DX256__)
// This is a Teensy 3.1 or 3.2 board
#endif
#if defined(__MK20DX128__)
// This is a Teensy 3.0 board
#endif
 
Has Arduino published guidelines on how these names are supposed to work?

Sure, pointing to "ARDUINO_AVR_UNO" is easy. It's simply to suggest we just follow that example. But when you look a little closer, it's not so simple at all.

For us, is the first part supposed to be "PJRC" or "TEENSY"? Is it the name of the manufacturer, or the name of the "hardware target" folder (at least I think that's what Arduino calls it now... they've changed their terminology), or something else?

We currently put everything under "avr" as a platform (folder name which the Arduino IDE uses), partly because the older Teensy boards actually do have AVR chips, partly because we emulate many AVR registers, and partly because some libraries that work fine actually list their platform compatibility like "avr,sam". There's a very strong disincentive to use any platform name that isn't the same as Arduino's products!

So for the middle part, do we use "AVR"? That would match our folder/platform name. Or is this meant to be descriptive?

For the last part, I suppose we'd omit the decimal point in the name? Maybe?
 
Aside from this being unclear how we should do it, a bigger question in my mind is if we should do it at all.

Is there really any technical reason other than the processor names are aesthetically displeasing to some people?
 
finding ARM/Teensy libraries, core, etc in a folder named AVR, confuses the heck out of one and all.
Geeze, if it was named TeensyARM_AVR to avoid something apparently complex in having two folders: Teensy/AVR and Teensy/ARM, so be it.
 
finding ARM/Teensy libraries, core, etc in a folder named AVR, confuses the heck out of one and all.

A folder named "avr" buried 3 levels of hierarchy inside Arduino is far better than any of the alternatives, which all involve libraries being incompatible with Teensy.

Yeah, it's not perfect, and I understand some people *really* value internal details like this to be neat and clean looking. But the Arduino IDE's design doesn't leave me much choice. This was discussed before they released 1.6.0, and they did make a number of improvements from what would have been much larger problems. But even though they pretty much agreed this architecture naming scheme would create problems for using anything other than "avr", they decided to leave this as part of the 1.6.x design. I think by that point, there simply wasn't much will to keep changing things, and this was already very deeply ingrained from the 1.5.x betas. So now we all get to live with it.

If anyone knows a way to rename the folder without compatibility problems, and without a huge (maintenance nightmare) java patch to the IDE, I'm willing to change. But believe me, I've put a *lot* of work into making Teensy as compatible as possible with the universe of Arduino libraries and code, and this is one small but very necessary piece of the puzzle.
 
You've done well Paul - it works silently for anyone to just use. Worst case for most is locating sketchbook\libraries right? Those that want/need to muck around under there just need to find and follow the rules - then it works. There is a leap learning/locating it, but better to be well done and usable - then say half done and a dead end ... there was a SAM directory?

Perhaps some sort of doc - like a wiki - entry on this would be handy. Luckily I have a 20+ year old editor that trivially greps such dirs. into a project so I can find stuff. I say trivial because I found it to work on a new tech OS file system at some company when their junior OS file system took FAT from 16 to 32 bits . . . so many places to change 16 bits to 32 when doing a disk check . . . and the new guys were rejecting it.
 
Hello All

Sorry for the delay.

1.)
> For the last part, I suppose we'd omit the decimal point in the name? Maybe?

The last part already exists. It is already defined in boards.txt as
teensy31.build.board=TEENSY31

And if the name starts with TEENSY_TEENSY31 or PJRC_TEENSY31 or ARDUINO_TEENSY31 is up to you.
For me it does not matter.
The only important thing is that there IS any switch that allows to distinguish the boards.


2.)
Having a switch for CPU does not eliminate the need to have switch for the board.
In the case of Arduino there are several borads that have the same CPU.
And in the case of Teensy 3.1 and 3.2 they also cannot be distinguished by the CPU because it is the same.


3.)
Why I need this:
As described in this article
http://arduino.stackexchange.com/a/21257/18754
I want to compile a code that runs on ALL Arduino and Teensy boards.
I want to show the user at the PC which board is currently connected.

You can see in that article the code that I use currenty.
It works perfectly.
The only missing thing is a really tiny change in the file platforms.txt in the Teensy folder which is adding one commandline argument like

-DPJRC_{build.board}

which would define the compiler switch

PJRC_TEENSY31

This is done in 5 minutes and I think discussing it more time is not necessary.
The board name is ALREADY there in the file boards.txt.
The only missing thing is passing this name to the compiler.


> If anyone knows a way to rename the folder without compatibility problems,

I have no problem with folder names, this is another topic.
 
Last edited:
In the case of Arduino there are several borads that have the same CPU.
And in the case of Teensy 3.1 and 3.2 they also cannot be distinguished by the CPU because it is the same.

They're also together under the same choice in Tools > Boards, so at compile time we don't have this info available.
 
I want to show the user at the PC which board is currently connected.

... ??
Doesn't the user know which board is connected ?
Does this sketch have more than one user ? :)

To upload your sketch, the user needs to know, which board it is.. BEFORE your sketch runs.
 
Last edited:
The compiler knows which board it was built for - all of these switches are compile time #ifdef's.

As noted in post #5 - the_BOARD == the_TEENSY == the_CPU. This is the case now and if magically two new Teensy's appeared next month - they would each have a unique CPU and compile uniquely and one sketch would not run on the other.

If you somehow got a sketch compiled for GENUINO_A1 and uploaded it to GENUINO_A2 - if it runs even on this different board - it will still report GENUINO_A1.
 
Status
Not open for further replies.
Back
Top