CORE_TEENSY define

microderm

Well-known member
I was updating some t3.6 classes to run on T4.0 or Arduino Uno and tried to use the follow to implement the core specific code:
Code:
#if (defined(CORE_TEENSY) && defined(__arm__))
...
#endif
The problem I found was that CORE_TEENSY was intermittently defined, so my core detection code compiled for both Teensy 3.6 and Arduino cores causing problems.

I can get round the problem using TEENSYDUINO:
Code:
#if (defined(__IMXRT1052__) || defined(__IMXRT1062__))
    #warning("T4") // Teensy 4 //
#elif (defined(TEENSYDUINO))
    #warning("T3") // Teensy 3+ //
#else
    #warning("OP") // Other processor //
#endif

So, my question is really, why is the CORE_TEENSY unreliable compared to TEENSYDUINO in my usage context, when I see CORE_TEENSY so much in internal library functions?

I've included a test build. Just compile under T4, T3.6 and Arduino Uno and see the compilation output.
 

Attachments

  • Defines_Test.zip
    2.9 KB · Views: 97
So, my question is really, why is the CORE_TEENSY unreliable compared to TEENSYDUINO in my usage context

You're (probably) not including the correct headers. You need to include Arduino.h or wiring.h to get CORE_TEENSY. Arduino does this automatically for all .ino and .pde files. But if you create .cpp or .c files, it's your responsibility to include the headers you need.

TEENSYDUINO is defined on the command line when running the compiler, so it's always defined by default, regardless of which .h files you've included, or even if you have no includes at all.
 
Wow, brilliant answer! As soon as I placed "Arduino.h" at the top of header Test.h I get CORE_TEENSY correctly reported. This knowledge will save me countless hours of fiddling with configuration.

Many thanks,

microderm
 
Back
Top