Teensy 4 and 4.1 pre-processor defines?

Status
Not open for further replies.

awbmilne

New member
I have been looking for a reliable way to determine the compile platform for code.
I am looking for code to compile differently using the preprocessor based on if the hardware is Teensy 4 or Teensy 4.1.

I havent been able to find any forum posts on how to accomplish this.

I found this thread:
CORE_TEENSY define

This is useful for compiling code differently between, say, an Arduino Uno and Teensy, but not between different Teensy boards.

Thanks for the help!
 
There are a few different naming conventions going on.

You can find all T3.x with check like:
#if defined(KINETISK)

T-LC with:
#elif defined(KINETISL)


Many boards are known by their processor...
So you will see things like:
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)

With
T3 - __MK20DX128__
3.2 __MK20DX256__
3.5 __MK64FX512__
3.6 __MK66FX1M0__

T4 and T4.1 __IMXRT1062__

So with the release of T4.1 we needed a way to know the difference, so now our builds have a define that like some other Arduino platforms do. So for example if you build for Teensy T4.1: ARDUINO_TEENSY41
T4 ARDUINO_TEENSY40

Likewise for T3..
 
Some defines come from the command line and others are a result of including headers. Including Arduino.h gives you everything. Other headers might or might not.

You can tell which are from the command line by turning on verbose output while compiling in File > Preferences. Then when you click Verify or Upload, the Arduino IDE will print a *lot* of info about the full commands it is using. You can see things like -DARDUINO_TEENSY41 in those commands.

Everything else comes from the header files. CORE_TEENSY, KINETISK and KINETISL definitely come from the headers.
 
Status
Not open for further replies.
Back
Top