PDA

View Full Version : Teensy 3.0 Project Template



Juvenal
11-17-2013, 03:43 AM
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

stevech
11-17-2013, 05:18 AM
using the Eclipse IDE is an option with T3 and libraries

Juvenal
11-17-2013, 07:01 AM
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.

MickMad
11-17-2013, 04:32 PM
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.

stevech
11-18-2013, 05:36 AM
Eclipse makes it easier, if your project is non-trivial

Juvenal
11-18-2013, 05:41 PM
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.

stevech
11-19-2013, 12:11 AM
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

mitch
11-25-2013, 11:13 AM
Nice, but it couldn't find crti.o when link ran.

mitch

Juvenal
12-13-2013, 04:09 PM
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

donpdonp
12-20-2013, 02:03 AM
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!!

dhylands
12-28-2013, 04:12 PM
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

JonHylands
12-31-2013, 03:15 PM
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...

dhylands
01-08-2014, 10:20 PM
And if you want to leave your sketch as a .ino file, you can do:

$(BUILDDIR)/%.o: %.ino
@echo "[CXX]\t$<"
@mkdir -p "$(dir $@)"
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -c -x c++ -include Arduino.h "$<"

dhylands
01-08-2014, 10:24 PM
I also noticed a typo in the teensy-template Makefile.

It has:

OPTIONS += -D__MK20DX128__ -DARDUIO=104

and ARDUINO (in -DARDUIO=104) is mis-spelled.

xxxajk
02-18-2014, 04:07 PM
I too disliked the whole IDE from the start. I have been using this, instead. https://github.com/xxxajk/Arduino_Makefile_master

DJohnstone
02-20-2014, 01:25 AM
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.

Juvenal
04-05-2014, 09:47 AM
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!

PaulStoffregen
04-05-2014, 01:00 PM
I've added a comment Teensyduino's sample makefile, with a link to your template and other makefiles.

https://github.com/PaulStoffregen/cores/commit/63f26decf39eb6bc4545624e74b74ba64b3b3aef

Hopefully this will help people interested in non-Arduino building find your template.

danpeirce
07-26-2014, 10:27 PM
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.

danpeirce
07-27-2014, 12:08 AM
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);
}


}

stevech
07-27-2014, 02:11 AM
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.

#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

#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
}

AndyMcKenzie
08-07-2014, 04:50 PM
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?

stevech
08-07-2014, 04:58 PM
.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.

PaulStoffregen
08-07-2014, 07:06 PM
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.