Icon courtesy of https://github.com/turesheim/eclipse-icons
Motivation
Program using C and without the Arduino IDE.
- Program in C/C++ modules
- Use existing Arduino libraries, e.g. FastLED
- Use convenient IDE features
- Optionally use drivers provided by NXP (in the case of Teensy)
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.
- Under the Includes tab, select GNU C++
- Add all Arduino library directories used in your project. (At least all the directories containing .h files)
- Optionally use the projects meta tag, ${ProjName}, in place of the literal project name to make the project a bit more portable.
- e.g /${ProjName}/Libraries/teensy3 instead of /MyProject/Libraries/teensy3
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
- __MK29DX256__ (for Teensy 3.2)
- __MK64FX512__ (for Teensy 3.5)
- ARDUINO=10803
- F_CPU=48000000 (or one of the other speeds supported)
- LAYOUT_US_ENGLISH
- TEENSYDUINO=140 (or current version number)
- USB_SERIAL
- __MK29DX256__ (for Teensy 3.2)
- 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 Optimization, select ONLY the following (to match teensyduino settings)
- Optimization Level Optimize more (-O2)
- Function sections -ffunction-sections
- Data sections -fdata-sections
- Single precision constants -fsingle-precision-constant
- Under the Tool Settings Tab->Cross ARM GNU C Compiler->Miscellaneous, under Other compiler flags enter:
- -nostdlib -fno-exceptions
- Under the Tool Settings Tab->Cross ARM GNU C Compiler->Miscellaneous, under Other compiler flags enter:
- -nostdlib -fno-exceptions -felide-constructors
- 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!
Upload the hex file
The Teensy loader can be used to easily upload the hex files. In the case of other Arduino boards, bossac can be used via command line.
Links
There are numerous other tutorials on configuring Eclipse for Arduino. This one from the Arduino homepage, using AVR based Arduinos, for example.