Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 24 of 24

Thread: Teensy 3.0 Project Template

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    5

    Teensy 3.0 Project Template

    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 by Juvenal; 11-17-2013 at 03:47 AM.

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    using the Eclipse IDE is an option with T3 and libraries

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    5
    Quote Originally Posted by stevech View Post
    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.

  4. #4
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    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.

  5. #5
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Eclipse makes it easier, if your project is non-trivial

  6. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    5
    Quote Originally Posted by stevech View Post
    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.

  7. #7
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    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

  8. #8
    Junior Member
    Join Date
    Feb 2013
    Posts
    5
    Nice, but it couldn't find crti.o when link ran.

    mitch

  9. #9
    Junior Member
    Join Date
    Nov 2013
    Posts
    5
    Quote Originally Posted by mitch View Post
    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 by Juvenal; 12-16-2013 at 06:53 AM.

  10. #10
    Junior Member
    Join Date
    Nov 2012
    Posts
    7
    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!!

  11. #11
    Member dhylands's Avatar
    Join Date
    Nov 2013
    Location
    Shuswap, BC, Canada
    Posts
    45
    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

  12. #12
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    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 by JonHylands; 12-31-2013 at 03:18 PM.

  13. #13
    Member dhylands's Avatar
    Join Date
    Nov 2013
    Location
    Shuswap, BC, Canada
    Posts
    45
    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 "$<"

  14. #14
    Member dhylands's Avatar
    Join Date
    Nov 2013
    Location
    Shuswap, BC, Canada
    Posts
    45
    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.

  15. #15
    Senior Member xxxajk's Avatar
    Join Date
    Nov 2013
    Location
    Buffalo, NY USA
    Posts
    528
    I too disliked the whole IDE from the start. I have been using this, instead. https://github.com/xxxajk/Arduino_Makefile_master

  16. #16
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    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.

  17. #17
    Junior Member
    Join Date
    Nov 2013
    Posts
    5
    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!

  18. #18
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,579
    I've added a comment Teensyduino's sample makefile, with a link to your template and other makefiles.

    https://github.com/PaulStoffregen/co...b74ba64b3b3aef

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

  19. #19
    Junior Member
    Join Date
    Jul 2014
    Location
    Surrey, BC
    Posts
    10
    Quote Originally Posted by dhylands View Post
    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.

  20. #20
    Junior Member
    Join Date
    Jul 2014
    Location
    Surrey, BC
    Posts
    10
    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 by danpeirce; 07-27-2014 at 12:14 AM. Reason: added example main.c

  21. #21
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    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 by stevech; 07-27-2014 at 02:14 AM.

  22. #22
    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?

  23. #23
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    .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.

  24. #24
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,579
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •