Arduino Micro Bootloader on Teensy 2.0++

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
dresch
 
Posts: 9
Joined: Mon Feb 06, 2012 8:53 pm

Arduino Micro Bootloader on Teensy 2.0++

Post by dresch »

Hi,
I just ran across the Arduino Micro using the ATmega32u4 on the Adafruit site. I normally use the Teensy 2.0++ in my projects but really need to be able to do a software reset (to the user program) from a host computer (using C# and Win 7) and can't seem to get any traction at PJRC, or anywhere else for help in doing this.

It appears the Micro can do this reset (using the baud rate - 1200 baud setting). And as the Caterina bootloader is open source I can modify it to suit my needs. Then all I need to do is delete HalfKay from the Teensy 2.0++ and load in a modified Caterina bootloader. Then I can still use the Arduino enviroment. (And the size of the Caterina bootload is no problem with the large memory ATmega1286.)

So, a couple of questions, if anyone can point me in the right general direction... (WARNING, some may be dumb.)

1) Has anyone done this already and be willing to discuss?
2) I should be able to recompile the Caterina (LUFA) bootloader for Teensy 2.00++ by selecting ATmega1286, right?
3) Where does the switch for the 1200 baud setting take place? I could not find it in the Caterina code... is it in a USB system driver? I would like to create an alternate switch, like 1225 baud, that would allow me to drive a software reset without the 8 second bootload delay.
4) There is probably a pin definition file for Arduino I need to alter somewhere...

I can't see where this will hurt anyone's business... PJRC/Adafruit still sells the Teensy's... and I get the software reset I need.
Thanks in advance.
Bill

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: Arduino Micro Bootloader on Teensy 2.0++

Post by westfw »

It looks like the caterina bootloader uses LUFA (um, "Lightweigh USB Framework for Atmel" ?), which is pretty understandable. However, it also looks like LUFA is not included in either the binary or source Arduino distributions, so you'll have to do some additional work before you can actually build a new bootloader.

I couldn't find any 1200bps reset code, either :-( It could easily be hidden off somewhere (modified LUFA?) by setting RunBootloader to FALSE, or Timeout to TIMEOUT_PERIOD...

It took me a while to get it to compile, and the resulting .hex file looks nothing like the original .hex file :-( (The original looks like it might contain the default sketch as well as the bootloader.)

(You know, I think that the 1200bps Reset code is part of the core library in the Sketch itself, NOT part of the bootloader (which makes sense; you want it to work when the sketch is running, and the sketch takes over the USB peripheral.) That means you have to move the Leonardo/Micro cores to the Teensy, rather than fiddle with the bootloader. Which may be easier, or may interfere with different USB functionality in teensy that you were hoping to keep. The relevant code is in hardware/arduino/cores/arduino/CDC.cpp in a 1.0.5 release...)

dresch
 
Posts: 9
Joined: Mon Feb 06, 2012 8:53 pm

Re: Arduino Micro Bootloader on Teensy 2.0++

Post by dresch »

Thanks WestFW.
I see that reference in CDC.cpp to the 1200 baud setting (THANKS!). And yes, I saw the same 8 second timing code in the Caterina code. That gives me real hope my software reset on Teensy is possible.

Since my knowledge of low level USB is severely lacking, could your clarify something?

If we assume the Arduino Micro user code is locked in a tight endless loop, to break and reboot, the baud rate setting code in CDC.cpp must be called from some lower USB interrupt signal(s) that have priority over the regular processor function? Is that close to being right?

Thanks, Bill

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: Arduino Micro Bootloader on Teensy 2.0++

Post by westfw »

If we assume the Arduino Micro user code is locked in a tight endless loop, to break and reboot, the baud rate setting code in CDC.cpp must be called from some lower USB interrupt signal(s) that have priority over the regular processor function?
Yes; the auto-reset on 32u4 boards is going to require that the USB processing code happen in its usual fashion. I don't know whether this all works via interrupts (and thus would work even if you're in a tight loop, as long as you haven't disabled all or USB interrupts, or whether it requires active participation of the sketch (by doing periodic "serial" IO, for example.) I don't have a 32u4 Arduino yet to try it out. (soon!) So it's not nearly as "clean" or certain a reset as you would get on an Uno...

dresch
 
Posts: 9
Joined: Mon Feb 06, 2012 8:53 pm

Re: Arduino Micro Bootloader on Teensy 2.0++

Post by dresch »

It seems someone has already done this... and we have another alternative to the Teensy 2.0++

http://www.ebay.com/itm/AT90USB646-AT90 ... 6427ef197e

http://www.mattairtech.com/

Just ordered one...

dresch
 
Posts: 9
Joined: Mon Feb 06, 2012 8:53 pm

Re: Arduino Micro Bootloader on Teensy 2.0++

Post by dresch »

The Mattair Tech bootloader and Arduino programming IDE upgrade does work on Teensy2.0++.

I flashed Justin's bootload_no_options.hex file to the Teensy2.0++ and was able to get Arduino 1.0.5 to recognize the Mattair IDE upgrade.

From there it was getting Win7 to recognize the Teensy-Mattair hybrid (multiple USB driver plugging-uninstalling-unplugging attempts). Eventually it worked.

The last step was jumpering the ALE pin on the Teensy to +5V, so that my sketch would run with power on. Of course the pins are scrambled as the MATTAIR Arduino pin enumeration is different from PJRC's. So for instance the Teensy LED pin (#6) is now 35.

Pretty cool. I am interested to see how the Mattair board works when it gets here.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”