PDA

View Full Version : how to jump the bootloader for teensy 3.0



mohawkpiper
11-12-2012, 11:54 PM
Hey all,
just a heads up, im extremely new to arduino/teensy kinda stuff so i know very little about this stuff, but am looking to learn...

anyhow, i have a project i am working on using the teensy 3.0
the teensy is going to be inaccessible by the time the project is done, but there will be a slot to plug the usb into it still.
hence, i will need any new code uploaded to take into effect without pushing the reload button on the teensy.
i can find how to do it with the 2.0, but cant seem to find the info with the 3.0

how do i go about getting this to work so that when i compile the code on the computer to the teensy it takes into effect immediately?

thanks in advance.

ps, project is putting addressable leds into a Monovelo monowheel so i can control the light patterns...

some progress vids...
2/3rds one side done
http://www.youtube.com/watch?v=rCym-rWtDnI

1 whole side and 1/3rd the backside done...
http://www.youtube.com/watch?v=v2QwMHnMC3s&feature=relmfu
(some glitches in the code still in this one..)

G

JBeale
11-13-2012, 12:40 AM
Normally that is how the teensy works, you do not need to push the button, except for the very first time you connect it to your computer. After that, when you hit "upload" from the Arduino environment, the Teensy Bootloader pops up, you see "Reboot OK" flash and the Teensy 3 is running your new program.

Paul
11-13-2012, 01:22 AM
John is right, you only need to push the button is the Teensy doesn't respond to the reboot request. When it's running previously loaded code (built with Arduino/Teensyduino), it will respond to the reboot request.

However, if your program crashes with interrupts disabled, or it shuts down the USB port, or you load different USB code that doesn't listen for the reboot request, it can't respond to the reboot request. If the pushbutton is inaccessible, loading bogus code could forever make the boards non-upgradable. To safeguard against a bad code update, the only thing you can do is expose the pushbutton, or add another pushbutton and solder it between the PROG & GND (Teensy 3.0) or RESET & GND (Teensy 2.0).

For either Teensy 2.0 or 3.0, the "teensy_reboot" program actually sends the request. You can find it in hardware/tools inside Arduino after running the Teensyduino installer. On a Mac, control-click Arduino and choose "show package contents". On Linux and Windows, Arduino is ordinary directories you can navigate. The teensy_reboot program doesn't take any inputs... it just searches until it finds the first Teensy running code Teensyduino-based code, and then sends it the reboot request.

If you want to make your code running on Teensy reboot to the bootloader mode, just call the _reboot_Teensyduino_() function. It will not return. You can also copy the code from that function, but for Teensy 3.0 I would recommend calling it, since I'm planning to change the mechanism somewhat. Calling the function will continue to work on future versions when the implementation changes. If you read through my USB code, you'll see the responses to the reboot request simply call that function. Actually, for Serial it starts a timer and calls _reboot_Teensyduino_() many milliseconds later, to avoid bugs in Microsoft's drivers that are triggered if the device disconnects at certain times (yes, their own drivers in Windows do not pass Microsoft's own WHQL quality requirements). When designing your code that calls _reboot_Teensyduino_(), be aware it causes a USB disconnect.

You can also automatically open the Teensy Loader and inform it of your .hex file. Doing that before the reboot causes the Teensy Loader to be ready to reprogram the board when it appears due to the reboot. That's how Teensyduino does it. The "teensy_post_compile" utility does this trick. There's an example of using it in the sample Teensy 3.0 makefile, which you can find in hardware/teensy/cores/teensy3. The process is the same for Teensy 2.0.

Also, please be aware the Teensy Loader looks for a corresponding .elf file in the same directory as your .hex file. If it's found, some additional (but not necessary) checks are done to make sure the code you're loading was designed to run on the board you've got connected. For example, if the code is built for a Teensy++ 2.0 but the board is actually a Teensy 2.0, the loader will display an error message rather than writing the .hex data that obviously will not work. If the .elf file is missing or can't be parsed, the loader will write the .hex data without any extra sanity checks. (someday I might add code in the loader to reverse engineer the .hex data for extra checking........)

I'm not sure if this answers the question, but hopefully this lengthy explanation will give you the info you need, and serve as a reference when similar questions come up?

JBeale
11-13-2012, 07:22 AM
This is an informative reply; seems like it would be useful to have these gems distilled eventually into a FAQ or a "Teensy 3 Internals" document, or the like.

mohawkpiper
11-22-2012, 06:24 AM
hey guys,
thanks for the reply. Sorry its taken me a while to get back to this...
anyways, Paul, your reply is a bit over my head unfortunately :( i wish it weren't, but im still learning. Anyhow, i spent the past few hours trying to get the automatic thing to work. I finally got it...
i believe it had to do with my computer. Prolly something i messed up in the beginning when i started, but my computer downloaded some drivers that were interfering with the teensy automatically uploading. I removed these drivers... and all is working!
i guess i ended up taking a look at this because it seemed the more i tried different things the worse the teensy got to the point where i couldnt even use the pushbutton to upload the new code. Id move to a new usb port and it was the same thing all over again until i ran out of ports. So i removed the drivers, started from the beginning, and its totally working the way it should.

i have a 64 bit laptop with windows 7 on it btw.

also, Paul, not important but just a little info... the teensy is mounted into the wheel in a way that it ultimately is removable. Its not in there permanently, so if i do really need to get to the button its doable. Its just that i have to remove a bunch of screws out of a cover on the frame so its not ideal to have to push the button. If you care to see how i mounted it here it is...
http://www.instructables.com/id/Monovelo-Monowheel-LED-modification/step6/Installing-the-Teensy/

thanks again!

Jp3141
12-17-2012, 01:16 AM
Using this _reboot_Teensyduino_() seems to call the Teensy loader app and reload the software on the Teensy 3.0 board; I just want to reboot the board the same way as it would when power is just applied.

What function would I use to just restart the board (without using the Teensy loader) ? -- I'm trying to debug an issue when it is connected to a different computer and am using the USB serial port as a means of sending commands.

sblanzio
12-24-2012, 04:14 PM
What function would I use to just restart the board (without using the Teensy loader) ? -- I'm trying to debug an issue when it is connected to a different computer and am using the USB serial port as a means of sending commands.

I have a similar issue when using max7219 for 7digits that behaves herratically at first power-on but always work as intended after pushing the on-board button. Can you please give us a hint?

tyvm!

PaulStoffregen
12-24-2012, 10:03 PM
I have a similar issue when using max7219 for 7digits that behaves herratically at first power-on but always work as intended after pushing the on-board button. Can you please give us a hint?


Without enough information to reproduce the problem, there's no much I can do to help.

Are you using the LedControl library?

http://www.pjrc.com/teensy/td_libs_LedControl.html