LenSamuelson
Well-known member
I have good news for you this morning, something I had not thought to try until now. It is possible to do the entire reload remotely if the Teensy is runing a sketch that has the teensyduino code running properly.
Paul's USB code interprets a request to set a "serial baudrate" of 134 bits/second as a request to reboot to the bootloader (this is the "USB controls" stuff that I referred to earlier). I've verified that it does exactly that, including loading a new sketch hex file. In the example below, the hex file is "dac_out.cpp.hex" ("dac_out" is my name for the sketch, your hex filename will be different). I've set up my workstation with libusb-1.0 but the pattern should still work for you.
After doing these two steps, the Teensy is indeed running the updated sketch hex file.
For this to work, the sketch must have Paul's magic "baudrate=134" USB detection code in an otherwise sane sketch. Hopefully, your teensy code is working well enough to interpret the control setting.
DO NOT place a reboot request in your sketch setup() function!!! (Actually, you are free to do that... It will cause the unit to force itself into bootloader mode instantly on starting...)
In case you don't already know, the basic Arduino executive pattern is simple: Execute the sketch function setup() once, then repeatedly call the loop() function in a while(1) {} loop. The basic idea is to put one-time-only init code in setup(), and put the main applicaton inside the loop() function. The code fragment is an illustration of how your application might reboot to the bootloader when the sketch decides that it wants to be reloaded.
Good luck, hope this helps.
Paul's USB code interprets a request to set a "serial baudrate" of 134 bits/second as a request to reboot to the bootloader (this is the "USB controls" stuff that I referred to earlier). I've verified that it does exactly that, including loading a new sketch hex file. In the example below, the hex file is "dac_out.cpp.hex" ("dac_out" is my name for the sketch, your hex filename will be different). I've set up my workstation with libusb-1.0 but the pattern should still work for you.
Code:
$ stty -F /dev/ttyACM0 speed 134
9600
<<< At this point, the workstation's syslog shows that the teensy has indeed reset and restarted in its bootloader>>>
$ ./teensy_loader_cli -v -mmcu=mk20dx256 /tmp/build353870272024895909.tmp/dac_out.cpp.hex
Teensy Loader, Command Line, Version 2.1
Using libusb version is 1
Read "/tmp/build353870272024895909.tmp/dac_out.cpp.hex": 31252 bytes, 11.9% usage
Found HalfKay Bootloader
Programming...............................
Booting
$
After doing these two steps, the Teensy is indeed running the updated sketch hex file.
For this to work, the sketch must have Paul's magic "baudrate=134" USB detection code in an otherwise sane sketch. Hopefully, your teensy code is working well enough to interpret the control setting.
DO NOT place a reboot request in your sketch setup() function!!! (Actually, you are free to do that... It will cause the unit to force itself into bootloader mode instantly on starting...)
In case you don't already know, the basic Arduino executive pattern is simple: Execute the sketch function setup() once, then repeatedly call the loop() function in a while(1) {} loop. The basic idea is to put one-time-only init code in setup(), and put the main applicaton inside the loop() function. The code fragment is an illustration of how your application might reboot to the bootloader when the sketch decides that it wants to be reloaded.
Good luck, hope this helps.