Teensy 3.0 Project Template

Status
Not open for further replies.

Juvenal

Member
Hello All,

I have created a pretty basic project template for the teensy 3.0.

One of the things I Don't love about arduino in general is the vagueness of the build process, and the java based IDE.

Its great for simple projects where you can just drop some code in and go, but for anything more advanced I find a proper build environment more appealing.

The template contains the teensy3 core, with the compiled linux tools in a subdirectory.
It should be entirely portable on any linux-like system which has make installed.

The repository is here: https://github.com/apmorton/teensy-template
More details can be found in the project readme.

Thanks,
Austin
 
Last edited:
using the Eclipse IDE is an option with T3 and libraries

While true, I believe the solution you speak of still uses the arduino build environment, right?

Either way, this template is meant for projects which intend to make heavy modifications to the teensy core.

In my case, I need to implement some custom USB interfaces, which is not possible without modifications to the existing teensy core code.

It makes more sense to include a local copy of the teensy core and hack away there, rather than make changes to my globally installed version of teensyduino in this case.
 
Nice and simple layout, very useful if you really want to get rid of loads of Arduino stuff that might get compiled in your code even if you don't need it.
 
Eclipse makes it easier, if your project is non-trivial

While I have used eclipse in the past for other project (pydev), I am not a huge fan of expensive (resources, not money) IDE's for simple things.

The project I needed this for required some changes to the USB code in the teensy core, and I wanted to be able to build it anywhere with make installed.

https://github.com/apmorton/Teensy360

I was able to configure the USB stack to have three interfaces:
- A custom interface with two bulk endpoints
- Two CDC class interfaces (TTY Devices)

Requiring anyone who wants to build and use my code to have eclipse and whatever plugins are required for teensy/arduino development seems a little much.


On a side note, I am really impressed with what the teensy can do. One of the usb tty devices acts as a USB to serial converter, while the other is used for POST code/debug output. The third interface is used to talk to an SPI device which reads/writes a flash chip.
 
I like the full feature IDEs like Eclipse, MS Visual Studio, IAR, Keil (latter 2 aren't free except for small code size).
Having more than a bare bones editor is what helps me a lot.
With disk and RAM so cheap, I don't care much about resources used, e.g., I use a 128GB SSD + NAS
 
Nice, but it couldn't find crti.o when link ran.

mitch

Fixed, my gitignore excluded them on accident.

UPDATE:
I pulled in the latest core (from teensyduino 1.17)

I also added support for arduino libraries, so you can just drop a folder in 'libraries' and it will be included/built
 
Last edited:
I just tried this template and was able to drop main.cpp into place and have it build correctly. Its reallly nice to have a clean directory structure and a make build system. Thank you for this template!!
 
Hi,

Just wanted to say thanks for putting this together. I got it working with my Teensy 3.1 by making the following modifications in the main Makefille:

Changed -DF_CPU=48000000 to be -DF_CPU=96000000
Changed -D__MK20DX128__ -DARDUIO=104 to be -D__MK20DX256__ -DARDUIO=105 (I'm not sure if the DARUINO change was need - I just happen to be using 1.0.5)
Changed LDSCRIPT = $(COREPATH)/mk20dx128.ld to be LDSCRIPT = $(COREPATH)/mk20dx256.ld
 
I am using the Makefile from this template, with some major changes, to make it work with Cygwin. Right now I can't link in external libraries, but other than that everything seems to work really well.

My modified Makefile is in my Github repo - https://github.com/JonHylands/uCee

- Jon (yes, I'm dhylands' brother)

ps - I should mention I have Arduino 1.05 and Teensyduino installed, in order to get the Windows binaries for the toolchain...
 
Last edited:
And if you want to leave your sketch as a .ino file, you can do:
Code:
$(BUILDDIR)/%.o: %.ino
	@echo "[CXX]\t$<"
	@mkdir -p "$(dir $@)"
	@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -c -x c++ -include Arduino.h "$<"
 
I also noticed a typo in the teensy-template Makefile.

It has:
Code:
OPTIONS += -D__MK20DX128__ -DARDUIO=104
and ARDUINO (in -DARDUIO=104) is mis-spelled.
 
Follow dhylands' tips above to build for teensy 3.1

To build on Mac OS X just copy "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools" into the template folder to get the correct binaries. Of course you'll need to make sure Arduino & Teensyduino are installed first. You can omit copying the AVR folder as well.
 
Just wanted to let everyone know here I have made some updates to the template.

- Updated the teensy core/tools to support teensy 3.1
- Modified the makefile to add an easy config switch for teensy 3.0 vs 3.1
- Fixed the ARDUINO typo

All changes are in the github repo.

Thanks for the feedback guys!
 
Hi,

Just wanted to say thanks for putting this together. I got it working with my Teensy 3.1 by making the following modifications in the main Makefille:

Changed -DF_CPU=48000000 to be -DF_CPU=96000000
Changed -D__MK20DX128__ -DARDUIO=104 to be -D__MK20DX256__ -DARDUIO=105 (I'm not sure if the DARUINO change was need - I just happen to be using 1.0.5)
Changed LDSCRIPT = $(COREPATH)/mk20dx128.ld to be LDSCRIPT = $(COREPATH)/mk20dx256.ld

I take it you are overclocking the CPU. I am not at all familiar with this MCU. Does changing the number here just tell the program how fast the cpu is or does this actually set the speed somehow? I see the rated speed for the 3.1 is 72 MHz. Perhaps the number controls a PPL? I'm noticing that 48, 72 and 96 are all integer multiples of 8. It looks like a 16 MHz oscillator so I am wondering if the speed can be set to 72?

In the test I ran today I had left the number at 48 and I seemed to get the correct delay.
 
One other thing I was wondering about is would it be a problem to use a main.c C file for the main function rather than the main.cpp C++ file?

The following simple file worked but I am wondering if this will be asking for trouble when I want to use USBserial or other more complex freatures?

#include "WProgram.h"

int main(void)
{

pinMode(13, OUTPUT);
while (1) {
digitalWriteFast(13, HIGH);
delay(101);
digitalWriteFast(13, LOW);
delay(900);
}


}
 
Last edited:
The MS Windows default installation's path
C:\Arduino\hardware\arduino\cores\arduino\main.cpp

has this code- you can see it's not complex.
Code:
#include <Arduino.h>

int main(void)
{
	init();

#if defined(USBCON)
	USBDevice.attach();
#endif
	
	setup();
    
	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}
        
	return 0;
}

and in the teensy directory, you'll find this variation of main.cpp
Code:
#include "WProgram.h"

extern "C" int main(void)
{
#if !defined(ARDUINO)

	// To use Teensy 3.0 without Arduino, simply put your code here.
	// For example:

	pinMode(13, OUTPUT);
	while (1) {
		digitalWriteFast(13, HIGH);
		delay(500);
		digitalWriteFast(13, LOW);
		delay(500);
	}


#else
	// Arduino's main() function just calls setup() and loop()....
	setup();
	while (1) {
		loop();
		yield();
	}
#endif
}
 
Last edited:
I'm seeing a large discrepancy in the sizes of hex files. For example, when I extract and build this template with no changes, the hex file I get is 110689 bytes long. When I build the blink example in Arduino 105 R2 and Teensyduino 1.19, the hex file is 40677 bytes. Any idea what's at play here? Also, how does the hex file size relate to "Binary sketch size: 12,992 bytes", anyway?
 
.HEX files are, I've found, about 2-3 times larger than the equivalent binary information.
There were some linker command optimizations done about 2 months ago to yield smaller (on the order or 20% though) binaries, but I'm not sure which release they are or will be in.
 
Intel HEX is an ASCII encoded data format. You can open the files in any text editor, and you find details for the meaning of the format on many websites. If you look at the actual text, it should be pretty clear why the file is larger.

I also recently discovered minor size reporting bug while working with a program for Teensy 2.0. The size reported in Arduino doesn't include some of the extra data that's placed into the final program. Usually the error is tiny, but when just over the limit, the summary in Arduino will say your code fits, but Teensy Loader will warn you it's over the limit. Teensy Loader is correct. The bug is on the Arduino side. I've put it on my TO-DO list, but it won't be fixed in 1.20, and may not be fixed for a very long time, since a correct warning is shown by Teensy Loader, even when Arduino says your program just barely fits.
 
Status
Not open for further replies.
Back
Top