-
Notifications
You must be signed in to change notification settings - Fork 232
Add build & upload support for Arduino Teensy #163
base: master
Are you sure you want to change the base?
Conversation
The Arduino Teensy has a different processor architecture, and therefore a different build chain, than standard Arduinos. Building and uploading are still possible through the Arduino IDE by patching it and installing the teensy build chain. This patch adds parsing and handling of extra options in the teensy's boards.txt, which should allow it to read all necessary configuration to build on all Teensy versions. With this patch, the following command will build for teensy3 with a 96 MHz clock, an en-US keyboard format, and serial USB mode: $ ino build -m teensy3 --menu='keys:en-us,speed:96,usb:serial' ** This patch supports building only. Uploading will come later. *** For some reason, this patch does not work with teensy1. I don't know why right now, but I will investigate.
This was easier than I expected; it just overrides avrdude and uses teensy-loader-cli. This should work just fine: $ ino upload -m teensy3
Hi, I'm trying to use your fork to build/upload to a Teensy 3.1 and I'm running into some problems. First, when I initialize a project I get a syntax error in build.py, but it's just a missing colon on line 182. After I add that colon, init works fine. However, I get stuck when I try to build. Here's the command and the resulting error: ino build -d $ARDUINO_DIR -m teensy31 --menu f_cpu:96000000
Traceback (most recent call last):
File "/usr/local/bin/ino", line 6, in <module>
main()
File "/usr/local/lib/python2.7/site-packages/ino/runner.py", line 76, in main
args.func(args)
File "/usr/local/lib/python2.7/site-packages/ino/commands/build.py", line 413, in run
self.discover(args)
File "/usr/local/lib/python2.7/site-packages/ino/commands/build.py", line 178, in discover
menu = self._parseMenu(args)
TypeError: _parseMenu() takes exactly 3 arguments (2 given) Then I commented out the Traceback (most recent call last):
File "/usr/local/bin/ino", line 6, in <module>
main()
File "/usr/local/lib/python2.7/site-packages/ino/runner.py", line 76, in main
args.func(args)
File "/usr/local/lib/python2.7/site-packages/ino/commands/build.py", line 413, in run
self.discover(args)
File "/usr/local/lib/python2.7/site-packages/ino/commands/build.py", line 180, in discover
_mergeDicts(self.e['menu'],menu)
NameError: global name '_mergeDicts' is not defined So I hard-coded F_CPU to be 96000000 in the Python script. Now I'm getting this error and I think I'm stuck:
Any idea why I'm running into all these problems? I'm running OS X 10.9.3, Python 2.7.6, and Arduino 1.0.5. |
I was working on improving some stuff, and it seems I broke it quite a bit in the process. I didn't have a separate "develop" branch, so the non-working commit ended up on master. I have created a develop branch and reverted master to the working version. Re-clone and it should work now. |
Thanks for the quick response! It made a whole lot more progress. Unfortunately it's still getting stuck. I got this error: Linking firmware.elf
/Users/jniehus/Downloads/teensy/tools/mac/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/bin/ld: cannot find -larm_cortexM4l_math
collect2: error: ld returned 1 exit status
make: *** [.build/teensy31-5d575bc3/firmware.elf] Error 1
Make failed with code 2 I do have a file
but that resulted in this error: Linking firmware.elf
/Users/jniehus/Downloads/teensy/tools/mac/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x12): undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
make: *** [.build/teensy31-5d575bc3/firmware.elf] Error 1
Make failed with code 2 |
It looks like you might have a weird libc.a in the arduino build system. My copy has an MD5 sum of 6cd4cd9e0c4a3f6c883085c7d46d9b81, so you can check it against yours. It also seems a little odd that your path has thumb2 in it. It's been a bit since I was really dug into the build system, but I remember having to disable something to do with thumb2. I'll see what I can figure out. Edit: I was misremembering the thumb part, which makes things weirder. It's hard to debug a problem like this remotely, but I'll see if I can find anything that could narrow things down. Edit 2.0: I found where _sbrk is defined. For me it's in /usr/share/arduino/hardware/teensy/cores/teensy3/mk20dx128.c -- do you have the teensy hardware files installed on your machine? My patch only works if you already have the teensy-specific build tools and libraries installed. Most of them are available at http://pjrc.com/teensy/teensyduino.html |
I think I had the wrong arm-none-eabi-gcc in my path, so it seems to build successfully now. Now it's looking for teensy-loader-cli. The official page for the Teensy loader command line tool says that loading a Teensy 3.0 only works in Linux. Is there a different version of that tool that can be used on OS X? Again, I tried some hackish things to make it work. I compiled this branch of teensi-loader-cli: stefanklug/teensy-loader-cli@0a2281f Neither the OS X nor Linux branches support the mk20dx256 (Teensy 3.1), but I tried adding in support and I also tried uploading to a Teensy 3.0. Both of those attempts result in this message with no response when I press the button:
I was able to build and upload to the Teensy 3.1 using this project so I'll probably stick to that, although maybe I will use ino to compile and do my own thing for uploading the hex file. |
Unfortunately even when I load the hex file manually using the GUI Teensy loader, it never gets into the compiled code (i.e. the light never turns on and it doesn't become visible over USB until after I press the button). |
Thanks for linking me to that Teensy template project! It looks like it manually does a few things I trusted to teensy-loader-cli. I'll try during this week to incorporate that and make my patch more cross-platform. Does it get into the compiled code when you use the Teensy template, or does it fail like the gui loader? If not, I'll definitely try to mimic the Teensy template. |
As far as I can tell, only the template is making a working hex file and I can only upload it sucessfully using the template's method (teensy_post_compile and teensy_reboot). |
So I noticed the hex file I was getting from the template was 30-something kilobytes while the version from ino was ~1200 bytes. The template version was compiling all the stuff in the cores/teensy3 directory. It took awhile to track down but but I found that if I put just mk20dx128.c in with the .ino file, it compiles correctly. So I guess that file needs to be compiled for a Teensy sketch to work. I don't know how that fits in with your work. |
Any news on this issue?
|
Wilywampa, could you post your boards.txt for teensy? For me it's in Corny, having to add things like that to |
@Ginto8 After installing the Teensyduino package I expect that everything works out of the box. I have just modified the search path: corny@19d40b9 |
My teensy boards.txt is here: https://gist.github.com/wilywampa/0cce8b96f50a08feec57 |
Using this current PR branch and cherry-picker corny/ino@19d40b9,
Errors on I'm using stock Arduino.app 1.0.5 with TeensyDuino installed. Any ideas? |
Does the output of |
Hey, I can add support for Teensy to PlatformIO. Can anyone help me with testing? What is interesting, PlatformIO Library Registry contains a few Teensy libs and you can install their with platformio lib install command and build your source code with it. |
teensy_reboot (bundled with Teensyduino), as defined in the boards.txt.
Otherwise arm-none-eabi-gcc can not be found for Teensy models.
an already split list properly)
Hi, I stumbled across this pull request; I use Ino extensively, and am in the middle of switching from Arduino to Teensy microcontrollers. I wanted to use this without installing teensy-upload-cli; Teensy 3.1 doesn't appear to be supported, and the Teensyduino package includes other, more general install scripts. I've implemented support in upload.py for these scripts in my fork: https://github.com/theJenix/ino/tree/master (specifically, it uses the post_compile_script and avrdude_wrapper values for the selected board, as loaded from the boards.txt file). This should extend this commit, and should work with all versions of the Teensy supported by Teensyduino. What else needs to be done for this PR to be pulled in? I'd like to help wherever I can. |
theJenix, your commits have been merged into the PR. Thanks for the contribution! |
Dear friends, I'm glad to inform you that latest version of PlatformIO has support for Teensy (2 & 3). You don't need to install any IDEs, tool chains or etc. PlatformIO works on the all popular OS, including card-size PC (Raspberry Pi, BeagleBone, CubieBoard and etc.). See here Teensy example. |
My commit messages give more technical details, but in essence, this patch allows ino to build and upload projects for Arduino Teensy boards. I avoided changes that would obviously break other boards, adding exceptions specifically for the Teensy boards.
There are two small changes to argument handling in ino build: the build chain option defaults are now overridden by settings in boards.txt (eg. teensy3.build.command.make), and the --menu option allows command-line selection of build options that would typically be presented in drop-downs in the Arduino IDE. --menu's argument is a comma-delimited list of colon-separated key-value pairs (eg. "k0:v0,k1:v1,...") which select options for menus found in boards.txt (eg. "usb:serial" selects teensy3.menu.usb.serial), and the contents of these are merged into the board dictionary, making them invisible to the program after argument processing.
ino upload has been changed to support post_compile_script and avrdude_wrapper options specifically for teensy, which are defined in boards.txt. This lets ino support any board that works with Teensyduino, including the teensy3.1 (thanks to theJenix for his work on this).
Best wishes,
-Joe Doyle (Ginto8)