Compiler directive to select board

Status
Not open for further replies.

KD0RC

Well-known member
Lately, I have been playing with several Teensy boards (3.6, LC, 4.0, 4.1), often hooked together. Tweaking code back and forth means having to remember to set the board correctly every time. Is there a compiler directive that can be used to set board type?
Thanks, Len
 
You can use the code below
Code:
#if defined(__IMXRT1062__)
//Teensy 4.0 Code Here
#elif defined(__MK66FX1M0__)
//Teensy 3.6 Code Here
#elif defined(__MK64FX512__)
//Teensy 3.5 Code Here
#elif defined(__MK20DX256__)
//Teensy 3.1/3.2 Code Here
#elif defined(__MK20DX128__)
//Teensy 3.0 Code Here
#elif defined(__MKL26Z64__)
//Teensy LC Code Here
#endif
 
Thanks for the response BriComp. I am not trying to compile one program for multiple boards. Each of my boards has its own code. I was hoping that there was a compiler directive that would allow me to set the board at the project or program level so that I don't have to remember to change the board when I compile.
Screenshot 2020-11-30 101600.png
 
Thanks for the response BriComp. I am not trying to compile one program for multiple boards. Each of my boards has its own code. I was hoping that there was a compiler directive that would allow me to set the board at the project or program level so that I don't have to remember to change the board when I compile.
View attachment 22698

So how do you compile (with Arduino IDE or with Makefile)?
with makefile you simply set -D__MK66FX1M0__ for T3.6
with Arduino you select as you showed in screenshot
 
I edit and compile from the Arduino (Teensyduino) IDE. It gives me quick access to everything, including the serial console. My technique is to code a little, test a little, so I like staying in the IDE.
 
This question has been up in the Arduino forum.
There is some workarounds but I don't think they are very good.

https://forum.arduino.cc/index.php?topic=355940.0

Best way of doing it would be to create a plugin (a somewhat forgotten feature of the Arduino IDE)
This plugin should store the current board settings to a file located in the sketch folder.

I think this is not a hard thing to create, because I have developed a plugin that creates a webserver/websocketserver that make it possible to remote control Arduino IDE, it now also have a experimental AutoComplete function.

A way that after using this program Arduino_Prefs.zip
https://forum.arduino.cc/index.php?topic=629619

Is to just make a copy of preferences.txt and put that copy inside the sketch folder when a setting is changed, then when Arduino IDE loads it checks if that file exists inside the sketch folder and loads that instead of the ordinary.
 
a somewhat forgotten feature of the Arduino IDE)
It was not forgotten - its not wanted (according to Paul)
They just don't want persistent settings. Don't ask why. I don't know, and I have no Idea. I also don't know if I want to know or not... must be something like "I made that decision back then, and if I change it now I will lose face." :)
There were countless requests, all were ignored (sometimes with arguments that cannot be taken seriously)

Defragster has a nice tool, too (T_SET)
 
I meant the plugin feature is forgotten,

there are not many people knowing that the Arduino IDE has a plugin feature, or how to use it (because there are not any complete documentation and the API is somewhat limited by non public functions/fields)

But off course you can always use Reflection to access those non public methods and fields.
This is what I have done, and together with the Arduino source and a good File searcher (I use Agent Ransack as an example).

You can read what pert responded at #2 @
https://forum.arduino.cc/index.php?topic=706855.msg4765147#msg4765147

If I make this it will only be a plugin, so it can be removed/added at any time (you have to restart the IDE).

And the reason they don't have settings like that, is what I believe is so that it's maybe easier to maintain and also they don't have to read/convert old versions of settings files belonging to old projects?
Maybe they also didn't want so many files in the sketch folder, to make it cleaner easier to share?

But what they could have is a feature that only replaces settings so that you don't introduce so many errors ( i.e. when saving all settings)

/Jannik
 
Thanks for all the discussion and ideas. It sounds like the easiest thing is to just live with it. Seems like a funny limitation...
 
Not sure about the history - but all windows of each INSTANCE of the IDE works on the set board.

Multiple instances can be opened - separate start of the EXE.

However the TyCommander Tool is what I use for multiple Teensy { from the IDE or under TSET - Windows Only } - any unique named INO can go to a unique board once selected. That doesn't account for the board settings.

As Frank B noted - using TSET - and abandoning the IDE { to use an editor of choice } allows a board specification in each INO folder { Compile.cmd }

The other awesome thing about TyCommander {github releases or see Forum thread} is the ability to connect Serial USB to all active Teensy units at the same time in the same or unique windows ( with: Ctrl+N )
 
A way to make this work could be to create multiple portable installations of Arduino/Teensyduino, one for each type of board.

https://www.arduino.cc/en/Guide/PortableIDE

While I did a lot of ESP32 while using Teensy as well and had compatibility issues with both on one installation, the portable solution with two seperate installations solved all issues. Also, the board and prefs remain adjusted in each installation seperately and individually. It costs almost one GB per installation, though, but it gives as well the opportunity to archive a project completely, including the build environment.
 
I have make a kind of working prototype as a (Arduino IDE Plugin/Extension/Tool) so it works on any OS.
It works like you want, by having certain preferences saved to current sketch folder

available at:
https://github.com/manicken/arduinoPrefsSaver

*How to Install
download this repository by either Code-Download Zip or
by git clone https://github.com/manicken/arduinoPrefsSaver.git
then extract/open the repository

global (into sketchbook folder (defined in Arduino IDE - Preferenses):
make a new folder in the above defined sketchbook folder
called tools
then copy the manickenPrefSaver from the repository into this new "tools" folder.

new menu items:
PrefSaverExt.png
here you can "activate/save current board settings" and deactivate the plugin functionality.

right now there is not any possibility to select what to save
but the items I have selected work for the moment.

right now it messes up the tools menu a little:
PrefSaver_mess.png
that is after I have used teensy 4.0
and opened a project that uses Arduino Uno

There is the possibility to change the setting without any mess,
because you can select boards the normal way without mess,
but I have not figured it out yet.

the following items are saved:
Code:
board=teensy40
custom_CrystalFreq=generic_40
custom_FlashFreq=generic_40
custom_FlashMode=generic_dout
custom_ResetMethod=generic_nodemcu
custom_baud=generic_115200
custom_bmcsketchconfig=teensy40_no
custom_cpu=nano_atmega328
custom_dbg=generic_Serial
custom_eesz=generic_16M15M
custom_exception=generic_legacy
custom_ip=generic_lm2f
custom_keys=teensy40_en-us
custom_led=generic_2
custom_lvl=generic_SSLTLS_MEMHTTP_CLIENTHTTP_SERVERCOREWIFIHTTP_UPDATEUPDATEROTAOOMMDNS
custom_opt=teensy40_o2std
custom_sdk=generic_nonosdk_190703
custom_speed=teensy40_600
custom_ssl=generic_all
custom_usb=teensy40_serialmidiaudio
custom_vt=generic_flash
custom_wipe=generic_none
custom_xtal=generic_160
serial.databits=8
serial.debug_rate=9600
serial.line_ending=1
serial.parity=N
serial.port=COM8
serial.port.file=COM8
serial.port.iserial=null
serial.port.label=COM8
serial.port.protocol=serial
serial.stopbits=1
target_package=teensy
target_platform=avr
i.e. all items beginning with:
serial.
custom_
and equals board


/Jannik
 
It works this way

When its "Activated" by the user, it takes those listed items above
and save them into a preferences.txt at the sketch folder (alias the project)

When this sketch is loaded again, while had selected another sketch.
Then it checks for preferences.txt and if that file is found it merges that contents into the "global"
preferences, and then apply that changes (this is where the menu gets a little messy I will fix that tomorrow).

If preferences.txt is not found then nothing will happen.

The Deactivate just renames preferences.txt to preferences.inactive.txt.

This can be used in a future release (of the plugin)


If you want you can compile the plugin from source, just change the arduino install dir of the respective compile scripts, (also java sdk 8 (1.8) is needed with the correct PATH variables set.

I have also made a plugin template project https://github.com/manicken/arduinoIDEpluginTemplate

that anyone can use to create their own plugins,
it contains helper methods
for example Refect
if you want more there is also the API_webserver that contains more functionality
 
First a little how Arduino IDE works with preferences (settings)
(Instance=when the IDE is started from the OS)

When the IDE starts it loads the pref. file
Then directly after it saves it back

Every time a new/(existing sketch) window is opened (from the File-menu)
it saves to this pref. file
(verified by looking at the file to see it's "Date modified" change)

When the last window of the instance is closed it also saves to pref. file.

When having multiple windows open in the same instance
they all share the same current Pref. (because it's static global)

The only way of having multiple pref. (multiple selected boards)
at the same time is to have multiple instances loaded.
(you don't need to have multiple installations for this)


Now I have done some more testing of my plugin.

The mess I was seeing is some kind of feature the IDE have.

Actually it works correctly:

When a (existing sketch) with a previous saved pref. is opened.
This according to above (IDE working stuff) loads this to the instance pref.
and all open windows of that same instance is gonna use this new setting.

But as I have stated before the sketch pref. is only saved when using the Extension-Menu commands
so the previous sketch don't loose the (sketch pref. settings) by load of this new window.

The mess in the menu disappears when closing the previous window.
(don't really know the inner working of that)
the board selection menu code is a little messy.


Also a little note. right now when open a existing sketch
and the sketch pref. is loaded it also rebuild the File-Examples menu
this takes little time to load, just so that you know what is happening.
When the extensions menu is visible it's done loading.
I will make this a optional by a setting in the next release.
 
Status
Not open for further replies.
Back
Top