Teensy 3.1 without arduino IDE

Status
Not open for further replies.
For several years I have been messing around with microcontrollers in a very bare-bones fashion with breadboards and discrete components. I have never used a pre-built platform like arduino or teensy. Next week I am going to be starting a contest project for my university which requires us to use a Teensy 3.1 and so I have a few questions.

First, let me explain why I want to avoid the arduino IDE as the topic title suggests (I can be convinced otherwise...this is just based on my observations):

While I don't consider myself "set in my ways", there are certain things that disturb me about the arduino IDE in relation to code management, namely the apparent lack of header files in projects. I understand that there are libraries and there are "sketches" and from what I have seen, it seems expected that all of the user code goes into a "sketch" while the libraries are written in straight up C or C++ with header files and all. While it seems to support multiple files in a project, I really prefer the more "standard" method of writing code where I define my header files with public "interfaces" and then I flesh out the functions in "modules" located in C files. I may just not be looking in the right place or pressing the right buttons (I generally avoid IDE's altogether :p), but it seems that this sort of organization is not possible with the arduino IDE.

However, if the arduino IDE does things in the same way C# does where there are no header files and all files are considered as one, I guess I can work with that too. I haven't looked deep enough to know if this what it will do...

Now, to relate this to the teensy stuff:

I know the teensy 3.1 uses a nice ARM processor. The pages I have read on this site seem to point to the teensyduino addon as the only way to develop for this board. As I understand it, teensyduino is simply an add-on to the arduino IDE with some libraries for using the on-chip peripherals and such. So here are my questions:
  • How can I compile, in a cross platform fashion (this has to be done on Windows and Linux), without being stuck with the arduino IDE? Perhaps a makefile or something that includes all the fun libraries that come with teensyduino?
  • If I must use the ardiuno IDE, can I organize my project in the normal fashion? Is even necessary? I just like organizing my code predictably so that I don't have to sort through 10,000 lines in a single file.

Also, just as a matter of knowledge: Is it possible to overwrite the USB bootloader on the teensy 3.1? I don't intend to, but I previously used a bootloader for the PIC 18F and in order for it to work properly, the program had to be compiled knowing about the bootloader so that it wouldn't overwrite the bootloader during programming (or fail to program because the boot segment of memory was protected). Is there something similar being done here or does the uploading program do all the translation and such? Is it possible to brick the chip by uploading code that doesn't take into account the space used for the bootloader? I really don't want to have to figure out how to fix a bricked teensy because I accidentally overwrote the bootloader somehow.

Thank you very much in advance for helping to alleviate my ignorance.
 
I am also new here, but have been programming for a long time. Several years ago, I started using the Arduino IDE for most of my stuff. I an not saying that the IDE is the greatest thing out there, but decided the stuff that most of the others use, so:

1) With the Arduino IDE, you don't need to put all of your stuff in one file. You can create new tabs (files), by clicking on the down triangle toward the right top of the window. If you create a tab with no extension, all of these will be logically combined into one file and compiled.

However you can give them extensions: .c, .cpp or .h. Tabs/Files with these extensions are compiled like normal C or c++ and header files. So you can define your header files with the class definitions and put the implementions into .cpp files.

More information up at: http://www.arduino.cc/en/Hacking/BuildProcess

2) At times I prefer to use higher level IDE's. Recently I installed Atmel Studio 6.1, which has plug ins to allow you to work with Arduino Sketches. I have not done much with this with the Arduino sketches yet. Have used it so for mostly for makefile based project on Atmega 32u2 (or u4). On this project the boards have a LUFA bootloader. I know some of the teensy documents talk about LUFA, but not sure for 3.1... Also not sure if this plug in will work for the Teensy or not. But you could always try it out.

I will leave your other questions for someone who knows something
Kurt
 
You may want to look at the Eclipse Arduino Plugin or better the new Eclipse Arduino IDE. I am using this with Teensy 3 and the newest Teensyduino RC 18.2.
That will provide you with a much more powerful IDE than the C/C++ IDE. I am in process of twig in instructions of how to get this to work with The latest Teensyduino release candidate.
 
I used Eclipse with Teensyduino and Teensy3.1. It's OK. Certainly better than nothing (i.e., the Arduino IDE, which is fine for a 100 lines of code program).

Last few days, I've been learning how to install/use "Visual Micro", a plug-in to Microsoft's Visual Studio that works with all the Arduinos, AVR, ARM and their odd libraries.
You have to have Visual Studio (not free), or use Atmel's (free) Visual Studio 6.1 - for which the Teensy 3.x compiler mode does work.
Microsoft has this semi-open methods for all kinds of microprocessors to be supported via add-ins and non-Microsoft compilers like GCC.

This gives us intelligent code and structured data auto-completion, etc., and better than Eclipse.

A bit of a struggle for me to get this running, and after I did, I found youtube demos that would have made it a lot easier.
The really nice part of Visual Micro is the Arduino (including Teensy 3.x) debugger. It's not the classic debugger where breakpoints are stored in RAM or SWI opcodes are overwritten to flash (e.g., J-Link w/flash breakpoints).
Thus, a tiny bit harder to use, i.e., you can delete and disable breakpoints and trace points, but to add one, you must compile and upload. This is just 10 seconds or so, when using USB/Serial.
At tracepoints and breakpoints you can choose to pause or print and continue. The breakpoint/tracepoints have easy means to printout text and values of variables.
What's really going on is that when you click in the left margin of source code to add a break/tracepoint, the Visual Micro IDE inserts invisible print statements based on what you ask to be displayed.
That breakpoint setup is remembered by the IDE, and the text is on the PC side, rather than taking up space on the microprocessor side.

It is clever and works well once you warp your brain into what it's really doing.

You can run "arduino" .ino type projects without altering any code. Or you can use cpp projects. It copes with the source-code scheme for Arduino libraries.

http://www.visualmicro.com

some demos and tutorials:
http://www.discoveringelectronics.com/arduino-programming-with-visual-micro-for-atmel-studio-6-1/

My stumbling to get this running (the Visual Micro website instructions are, er, opaque). The above demo videos are good.
Hindsight, it's really easy to use this, but the how-to-setup info is not so hot which made what should have been a 30 minute process become 8 hours.
http://www.visualmicro.com/forums/YaBB.pl?num=1389630981/0#0

If you are hard-core anti-Microsoft (who can love 'em?), this isn't for you. But it does get a very good IDE/debugger for almost nothing. The IDE per se is freeware. The debugger for one PC is about USD$20 or so (with a free trial).
 
Last edited:
I'm also new to AVR and Teensy, and I have a related question: what's the right avr-gcc -m option for the Teensy 3.1? I just got mine, and I'd like to run some of the examples, like usb_keyboard, but the Makefile only has options for Teensy 1.0 and 2.0.

I've got gcc version 4.8.1 (GCC) via CrossPack-AVR.

Thanks.
 
If you're new to AVR and Teensy the best option is to get your feet wet using the Arduino IDE and then move on to other things. Obviously the Teensy 3x. use ARM processors so you won't get very far with an AVR compiler ;-)
 
I too recommend starting with the Arduino IDE and the Teensy 3.x addition. Master that, then go with some other IDE or bare Makefiles.
 
I am using Code::Blocks to develop my software. If you're used to it, it's quite easy to set up a project that uses teensyduino and you can then use all the classes it provides.
 
I am using Code::Blocks to develop my software. If you're used to it, it's quite easy to set up a project that uses teensyduino and you can then use all the classes it provides.
I tried code::blocks and its derivatives - but I don't recall: does it have what Microsoft calls Intellisense, where a pop-up gives you alternatives for structure/class member names, function names, function prototype args, etc?
Eclipse and Visual Studio/Atmel+Visual Micro both provide that.
 
Qt Creator works great, and is well suited to general and embedded C and C++ programming despite its name. You just have to make it aware of the include path for the Teensy core code and the libraries you use manually, but then the auto-completion does wonders. I've been looking at making a plug-in to enable greater/easier compatibility with Teensyduino, but I seriously lack the time right now. Maybe in a few weeks when I get some free time :)
 
Teensy + Qt Creator is AMAZING!

I came online tonight for the sole purpose of telling everyone how awesome this combination is, then found this thread before posting my own; although I still may post a new one with instructions. That's how impressed I am!

I've been using this combination for a few weeks now. I started by using the Arduino IDE (for a few days), then to SublimeText with the Stino plugin (for a few months). But without a doubt, using Qt Creator is the best. It didn't hurt that I use it in my normal programming life... I'm just extra impressed to see it working so well with teensy.

I'm programming for Teensy 3.1 with the Teensy 3 template found in this thread http://forum.pjrc.com/threads/24527-Teensy-3-0-Project-Template.
For T3.1, pay special attention to dhylands's comments.

Anyway, AWESOME, AWESOME, AWESOME. That's what I came to say.
Give it a try. :)
 
I tried code::blocks and its derivatives - but I don't recall: does it have what Microsoft calls Intellisense, where a pop-up gives you alternatives for structure/class member names, function names, function prototype args, etc?
Eclipse and Visual Studio/Atmel+Visual Micro both provide that.

It gives you a popup with completion suggestions as you type (as soon as 4 character have been entered or when you hit CTRL+Space), but I don't know exactly how, when and where it searches for completion possibilities. I never really bothered because it works quite well. The list includes functions, members, typedefs, objects and macros. Prototype arguments are shown in a tooltip when you hover over a function name in your code.
 
Wow thanks for all the responses!

I worked for about 10 minutes with the Arduino IDE before I decided I hated it. It totally screwed with my workflow. No line numbers, no way to change the indentation, no way to re-load the sketch folder, implicitly deciding what is to be compiled based on file location and extension...no, thank you. It is way too boxed in and while I could, in theory, work with it if required, I would really prefer not to.

The only great thing about the arduino IDE was that it worked instantly with the teensy3 loader stuff.

Part of my issue is that this has to compile on both my computer (which runs arch linux) and my teammates computer (which runs windows). I saw the Code::Blocks suggestion and I have been running with that for a day or so. So far, I have used a makefile based on the one that is found in the teensy3 directory and set up build targets for Windows and Linux. I am passing in the various directories for the include files, compiler, etc via environment variables so that the Windows and Linux targets can have different directories. So far I am just running into issues with the final build step when runs the post compile program and opens the teensy loader...running ./teensy itself just causes a segfault (after a GTK warning) and running ./teensy_post_compile gives me some error about "Opening teensy loader... <Insert GTK warning here about murrine which comes from ./teensy> Unable to find teensy loader. Is the teensy loader application running?". I think perhaps the problem might be with the fact that I am running that program from the directory of my project rather than from the directory of the tools, but the segfault when loading just ./teensy is a little odd and could be causing the problem (maybe I will make a separate thread for that).

Another issue the cross-platform requirement puts on me is that I can't simply bundle the tools with the project and I need to have the project point to the appropriate executables and such based on the operating system. In Code::Blocks I am accomplishing this via environment variables and restricting the build targets by operating system, but I have a feeling there might be a better way.

I also might try the Qt Creator suggestion. Would that also involve a makefile or would I be using some in-project settings to point it to the right compiler? I have used Qt Creator and IMHO, it has the best "intellisense" out there for free (as in beer) software on Linux. Clang with Code::Blocks was super slow as well compared to Qt Creator's speed.
 
Last edited:
If you need to develop crossplatform then I'd suggest the Arduiino Eclipse IDE
I've installed int successfully on Windows7, Mac OSX 10.9 and Ubuntu (12.something) Linux.
I've installed Eclipse for use with Teensy. Is there a clear and concise instruction on the topic of how to make Eclipse work with Teensy's baseline of 1.0.5 whereas Eclipse for Arduino, in the non-Teensy world, is using Ardiuino 1.5.2?
 
Last edited:
On using the IDE: Qt Creator, as noted earlier in this thread. Looks interesting. Is there a clear/concise how-to for Teensy 3 with this IDE and Arduino 1.0.5?
 
Hi there-

I'll jump in on this thread. I'm also very old school. I do like arduino OK, but more comfortable with makefiles. Perhaps a bit of a control freak that comes with being used to the total control we once had to go through. Very impressed with the teensy and how it can be fitted under the mold of arduino. What I did was install arduino and then proceeded to rip away just what I needed to get a running makefile style environment. The below is a paste of the notes detailing most of this. Hope this helps... I've progressed past this as well and now having a running RTOS on a teensy3.1 ARM-M4. Anyone interested should let me know....

Steve S

The below is in reference to teensyduino 1.18-rc1 and on a windows system...

########

First test the virgin teensy3.1 board by connecting with USB
(should start blinking) and running teensy.exe, and pressing the reset
button on the board. You should see the teensy application
register the board...

########

Initial teensy3.1 bringup...:
1) Install arduino-1.0.5-windows (right click to run as administrator)
2) Install teensyduino (right click to run as administrator)
3) Install serial_install (right click to run as administrator)
4) Run Arduino (dbl click from desktop)
5) From Tools->Board - select Tennsy 3.1 from the option list

You can now run a sample sketch easily. I simply copied the contents of
an example blink sketch .ino into the empty editor window and compiled using
the "check" icon (verify). After it compiles OK - hit reset on the teensy3.1
board and it should load and start to run...

########

To get initial teensy3.1 makefile capability and barebones...:
1) Created an container directory - example teensy3.1
2) Optional for truly standalone: Copy the entire
<basedir of installed Arduino>\hardware\tools into
the teensy3.1 directory of 1) above. This is a pretty sizeable
copy and much of it can probably be removed later - but this will
get you going.
3) Copy from <basedir of installed Arduino>\hardware\teensy\cores\teensy3
both makefile and mk20dx256.ld into teensy3.1
4) Edit teensy3.1\makefile so that the TOOLSPATH and COMPILERPATH
to point to your newly copied tools directory,
or <basedir of installed Arduino>\hardware\original tools directory.
Also change any mk20dx128 references to mk20dx256. Preserve the case.
I also comment out the lines using the teensy application for
autoloading. The resultant lines of the makefile now look like:
%.hex: %.elf
$(SIZE) $<
$(OBJCOPY) -O ihex -R .eeprom $< $@
#$(abspath $(TOOLSPATH))/teensy_post_compile -file=$(basename $@) -path=$(shell pwd) -tools=$(abspath $(TOOLSPATH))
#-$(abspath $(TOOLSPATH))/teensy_reboot
5) Create a very simple, *empty* main() in a main.c file.
6) Open a DOS box to \teensy3.1. Run make. Make clean to remove.
The resultant .hex is *not* runnable.

########

The next step is getting the most basic application running...:
1) Copy the minimum environment needed from
<basedir of installed Arduino>\hardware\teensy\cores\teensy3.
Got by with just these files:
analog.c
mk20dx128.c
nonstd.c
pins_teensy.c
usb_desc.c
usb_dev.c
usb_mem.c
usb_serial.c
yield.c
avr_functions.h
core_pins.h
HardwareSerial.h
mk20dx128.h
pins_arduino.h
usb_desc.h
usb_dev.h
usb_mem.h
usb_names.h
usb_serial.h
2) Expand your main.c. Something like this:
#include "mk20dx128.h"
#include "core_pins.h"

int main(void)
{
pinMode(LED_BUILTIN, OUTPUT);
for(;;)
{
digitalWriteFast(LED_BUILTIN, HIGH);
delay(30);
digitalWriteFast(LED_BUILTIN, LOW);
delay(3000);
}

return 0;
}
3) Run make and now load the resultant .hex file with the teensy app.
You should get a working blinking LED...

########

For the next step - thinking it's necessary to have run serial_install.exe
so that windows recognizes the teensy3.1 board and and the USB is then emulated
as a serial device. Not sure on this as it was installed before attempting
to use the teensy3.1 USB interface in an application...
You can after starting up the teensy3.1 application use an ordinary terminal
program. Using Tera Term, *after* the teensy3.1 application has started, you
can connect as a serial device - the COM port will indicate Teensy USB Serial.
The main.c can look something like:

#include "mk20dx128.h"
#include "core_pins.h"
#include "usb_serial.h"

void SimplePrint(char* S)
{
while(*S)
{
usb_serial_putchar(*S++);
}
}

int main(void)
{
pinMode(LED_BUILTIN, OUTPUT);
for(;;)
{
digitalWriteFast(LED_BUILTIN, HIGH);
delay(2);
digitalWriteFast(LED_BUILTIN, LOW);
delay(1000 - 2);

SimplePrint("Ellie!\n\r");
}

return 0;
}

########
########

The below got copied in and pasted here while struggling to get up to
speed with the ARM and it's assembly. Leaving it in case it likewise
helps another...

A note for using .syntax unified in assembler files...
Two slightly different syntaxes are support for ARM and THUMB instructions.
The default, divided, uses the old style where ARM and THUMB instructions
had their own, separate syntaxes. The new, unified syntax, which can be
selected via the .syntax directive, and has the following main features:

Immediate operands do not require a # prefix.
The IT instruction may appear, and if it does it is validated against
subsequent conditional affixes. In ARM mode it does not generate machine
code, in THUMB mode it does.
For ARM instructions the conditional affixes always appear at the end
of the instruction. For THUMB instructions conditional affixes can be used,
but only inside the scope of an IT instruction.
All of the instructions new to the V6T2 architecture (and later) are available.
(Only a few such instructions can be written in the divided syntax).
The .N and .W suffixes are recognized and honored.
All instructions set the flags if and only if they have an s affix.
 
Hi there-

I'll jump in on this thread. I'm also very old school. I do like arduino OK, but more comfortable with makefiles.

Thanks Steve, very helpful tips. I have a teensy 3.1 project building outside of Arduino with the 3.0 makefile edited for the 3.1's arm. Things seem to be compiling and working fine.

Where i'm running into a snag is in trying to integrate the Audio Library and using the Audio Shield. I can compile and upload the PassThrough project in Arduino and audio passes just fine. However when I compile it using the c++ compiler / makefile outside of arduino … no audio. I'm calling all of the same functions as the arduino project. Maybe I'm missing something in the initialization?

Any help is greatly appreciated! Here's my C code.

Code:
#include "WProgram.h"
#include "Audio.h"
#include "Wire.h"

//Global objects
AudioInputI2S       audioInput;         // audio shield: mic or line-in
AudioOutputI2S      audioOutput;        // audio shield: headphones & line-out
// Create Audio connections between the components
AudioConnection c1(audioInput, 0, audioOutput, 0);
AudioConnection c2(audioInput, 1, audioOutput, 1);

AudioControlSGTL5000 audioShield;

void init(void);

extern "C" int main(void)
{
    init();

    //MAIN LOOP
	pinMode(13, OUTPUT);
    elapsedMillis volmsec=0;
    int blinkrate = 0;
    
	while (1)
    {
        //blink
		digitalWriteFast(13, HIGH);
		delay(blinkrate);
		digitalWriteFast(13, LOW);
		delay(blinkrate);
        
        // every 50 ms, adjust the volume & blink rate
        if (volmsec > 50)
        {
            float vol = analogRead(15);
            vol = vol / 10.24;
            audioShield.volume(vol);
            volmsec = 0;
            blinkrate = analogRead(17);
        }
	}
    
    
}

void init(void)
{
    //Init code
    AudioMemory(12); //allocate memory for audio buffer
    // Enable the audio shield and set the output volume.
    audioShield.enable();
    audioShield.inputSelect(AUDIO_INPUT_LINEIN);
    audioShield.volume(60);
}
 
I think many of us are using either Eclipse or the plug-in (Visual Micro) for MS Visual Studio or (free) Atmel Studio 6, to get the "intellisense" and so on in an IDE. In these, the Makefile is hidden or embedded Java or some such. Transparent to user.

Paul may have a suggestion re using C rather than C++ for your code.
But he's very busy and needs a very concise explanation of what's wrong, what debugging you've attempted, etc. to minimize his time poring over code.
 
Last edited:
I would love it if someone could patch https://github.com/sudar/Arduino-Makefile to support the Teensy 3.x
I know it's old-fashioned, but I use a low-powered little laptop with Linux and vim as my editor, and it works really well for me for Arduino development. I dislike having to switch back to the Arduino IDE for uploading to the Teensy :(
 
Easy as 3.1415

I installed Arduino 1.05-r2, then Teensyduino and had the Teensy Loader 1.18 at my disposal. Create a HEX file with your favorite tool chain and Teensy Loader will put it in the chip for you. Piece of cake, to mix my metaphors.

You give up the Arduino convenience/conventions but your code can go wild. Up to the HalfKay loader limitations... Write a bootloader and only use Teensy Loader to update it. Be aware Teensy Loader erases the entire chip so your App will evaporate if you update the bootloader.
 
Last few days, I've been learning how to install/use "Visual Micro", a plug-in to Microsoft's Visual Studio that works with all the Arduinos, AVR, ARM and their odd libraries.
You have to have Visual Studio (not free), or use Atmel's (free) Visual Studio 6.1 - for which the Teensy 3.x compiler mode does work.
you mean,
I can really use Atmel's Visual Studio 6.x (with Visual Micro plugin) for teensy 2.x and 3.x ?
where to put all this "teensyduino-stuff" and libraries ... ?

(I ever thought Atmel's Visual Studio 6.x is just able to compile for ATMEL-MCU's -> not for Kinetis ?)
 
you mean,
I can really use Atmel's Visual Studio 6.x (with Visual Micro plugin) for teensy 2.x and 3.x ?
where to put all this "teensyduino-stuff" and libraries ... ?

(I ever thought Atmel's Visual Studio 6.x is just able to compile for ATMEL-MCU's -> not for Kinetis ?)

Visual Micro plug-in for Visual Studio/Atmel Studio 6.1 works well for Teensy3.x. I've been using it full time for several months. It's terrific. Easily installed. And $0.
Uses the normal Arduino+Teensyduino install. You can use Arduino .ino files and thus use either the Arduino IDE or VisualMicro/VS and flip back and forth. Uses same GCC command line as does Arduino's IDE.
 
Last edited:
Status
Not open for further replies.
Back
Top