Setting Up Eclipse for Teensy
Motivation
I know there are those of us who prefer to program using C and without the Arduino IDE. Personally I come from using Keil (which appears unable to compile using GNU GCC, arm-none-eabi-gcc, and GNU G++, arm-none-eabi-g++ at the same time). The most complete directions I found were from this thread which is a bit dated, and now missing some details.
We wish to do the following:
Program in C/C++ modules
Use existing Arduino libraries, e.g. FastLED
Use convenient IDE features
Optionally use drivers provided by NXP
Downloads/Installation
Arduino and Teensiduino (
https://www.pjrc.com/teensy/td_download.html)
Eclipse IDE for C/C++ Developers (
http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/oxygenr)
GNU ARM Eclipse Plugin (
http://gnuarmeclipse.github.io/plugins/install/)
Alternatively, Sloeber should include both the Eclipse IDE and GNU ARM plugin (
http://eclipse.baeyens.it/stable.php?OS=Windows)
GNU MCU Eclipse Windows Build Tools - for make on Windows (
https://github.com/gnu-mcu-eclipse/windows-build-tools/releases)
Optionally, GNU ARM Embedded Tools - This is already included as a part of Teensiduino. For the case that you have no interest in using Arduino libraries. (
https://developer.arm.com/open-source/gnu-toolchain/gnu-rm)
Create a new project
Create a new project in Eclipse, File->New->C++ Project
Choose a project name and location
Under Project type select “Executable/Empty Project”
Under Toolchains select “Cross ARM GCC”
Click Next->Next and select “GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc) for Toolchain name:”. The Toolchain path should be “C:\Program Files (x86)\Arduino\hardware\tools\arm\bin” if you used the default Arduino install directory.
Configurations
Right click the Project->Properties
Under C/C++ Build->Environment, select PATH and click Edit. Add “C:\Program Files (x86)\Arduino\hardware\tools\arm\bin” if it's not already there. Use semicolon as delimiter between previous path
Under C/C++ Build->Tool Path
Build tools folder: C:\Program Files (x86)\GNU MCU Eclipse\Build Tools\2.9-20170629-1013\bin\bin
Toolchain folder: C:\Program Files (x86)\Arduino\hardware\tools\arm\bin
Adding the teensy3 core and libraries
Add the Teensy Core to the project using a linked folder:
Right click on the project->New->Folder
Click Advanced->Link to alternate location (Linked Folder), and browse to C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3
Repeat this for the Libraries you wish to use, e.g FastLEDs C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FastLED
Remove teensy3/main.cpp from the build process.
Right click main.cpp->Resource Configurations->Exclude from Build
Similarly exclude the “examples” directory of any libraries from the Build
Add your project files
Add a “main.cpp” file to the Project in a directory relative to the project that suits your preferences.
Right click the Project->New->Source Files
Or create the file in a chosen directory and link it as before.
Configure Include paths
Right click on the Project->Properties->C/C++ General->Path and Symbols
Under the Includes tab, select GNU C
Add, browse to “C:\Program Files (x86)\Arduino\hardware\tools\arm\arm-none-eabi\include”
Add, Workspace, ProjectName->teensy3.
Repeat and add all directories used in your project. (At least all the directories containing .h files)
Repeat for GNU C++
Match Arduino IDE build settings
These settings can be viewed in Arduino IDE by turning on verbose. In Arduino, File->Preferences->Show verbose output during: compilation
Right click on the Project->Properties->C/C++ General->Path and Symbols, click the Symbols Tab, click GNU C, add the following
__MK64FX512__ (for Teensy 3.5)
ARDUINO=10803
F_CPU=48000000 (or one of the other speeds supported)
LAYOUT_US_ENGLISH
TEENSYDUINO=137
USB_SERIAL
Repeat for GNU C++
Switch to C/C++ Build->Settings
Under the Tool Settings Tab, verify the follow is set from the previous steps
Cross ARM GNU C Compiler->Includes
Cross ARM GNU C++ Compiler->Includes
Cross ARM GNU C Compiler->Preprocessor
Cross ARM GNU C++ Compiler->Preprocessor
Under the Tool Settings Tab, select Target Processor, select the following
ARM family: cortex-m4
Instruction set: Thumb (-mthumb)
Under the Tool Settings Tab, select Cross ARM GNU C++ Linker->General,
Add the .ld script file corresponding to the Teensy you are using. E.g mk64fx512/ld for Teensy 3.5
Check Remove unused sections
Select Cross ARM GNU C++ Linker->Miscellaneous
Add the Linker flag --defsym=__rtc_localtime=1499566176
Check Use newlib-nano
Now the project should build as it does in the Arduino IDE!