Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: uploading hex file via teensy loader

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Location
    Los Angeles
    Posts
    125

    uploading hex file via teensy loader

    Hi all,
    Trying to see if I'm missing something with the teensy loader. My goal is to be able to remote into a windows machine that has a teensy 4.0 attached and update its firmware. Unfortunately pushing the button on the teensy isn't possible.

    I'm running the teensy loader by itself. No issues generating a hex file to upload. Open the file fine in the teensy loader, however both the program and reboot buttons and corresponding menu commands are greyed out. It still seems the only way to reprogram is pressing the button (which does upload, just not the goal . Am I missing something? I also tested with the fast and slow blink hex files provided here with no luck (https://www.pjrc.com/teensy/loader_win10.html). Same issue on the mac as well.

    This is using v1.52 of the loader. Windows 10. MacOs 10.14.6. Any pointers?

    Thanks,
    David

  2. #2
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    647
    Seems to me that since the arduino IDE can (usually) cause a program update without a button press, such a feature could be (but isn't) included in the teensy loader.

    You could do updates with the flasher4 code that is available here:

    https://forum.pjrc.com/threads/29607...e-air-updates/
    Last edited by jonr; 09-10-2020 at 06:26 PM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,757
    First, there is no 100% reliable way to always get your Teensy into programming mode without the pushbutton. If the code you've previously written crashes or turns off the USB port or lingers in a deep sleep mode, it can't respond to any USB communication from your PC. Nothing you do on the PC side can affect a Teensy running such code (well, with the possible exception of a rare USB hub with software control over the power on each port). This is why we make every Teensy with a pushbutton, so you have a reliable way to recover from "bad" programs.

    Assuming your Teensy is still running a previously written program, there are a couple ways you can cause it to enter program mode. The simplest is to run the "teensy_reboot" program. Look for it in {Arduino}/hardware/tools. On your Mac, control-click Arduino and click "Show Package Contents", then look for the "hardware" folder inside Contents/Java.

    If the program running on Teensy is implementing USB Serial (controlled by the prior setting in Arduino's Tools > USB Type menu), you can also cause entry to programming mode by opening the COM port (Windows) or serial device (Mac, Linux) and then set the baud rate to 134.

    To cause your Teensy to reprogram, of course have the file open in Teensy Loader and make sure it's in Auto mode. When it detects the arrival of any Teensy running in bootloader mode, it will immediately program the hex file and reboot it. This is how Arduino uses it. While you may have thought all of that was happening by Teensy Loader, in fact Arduino remotely takes control of Teensy Loader just to open the hex file and turn on Auto mode. Then it runs "teensy_reboot". The task of sending the 134 baud rate isn't built into Teensy Loader at all. It's in "teensy_reboot" located in {Arduino}/hardware/tools.

    Please remember, teensy_reboot can only work if your Teensy is still properly running whatever code you previously loaded. If you write "bad" code to your Teensy that interferes with USB communication, there is no way for software on your PC to use USB to ask it to go into programming mode. Every Teensy has a physical pushbutton to give you a reliable way to recover from this scenario.

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Location
    Los Angeles
    Posts
    125
    Thanks, Paul! This is perfect (and thanks for the warnings). Fortunately no deep sleep or messing with the USB port, and we have a watchdog running in the main loop to help keep things alive. Just tested the above on windows running teensy_reboot.exe and worked like a charm.

    Follow-up question: is there a way to run teensy_reboot.exe as command line app and specify the .hex file as well via extra argument? or 2-step process loading teensy.exe as a command line with the name of the hex file, then run teensy_reboot.exe? The above works great for what I need right now, just looking long term when I might be sending firmware updates to clients and looking for ways to update without too much hassle.

    @jonr: thanks for the link. I'll look into that as well.

    Thank you,
    David

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,757
    Yes, you can do that with "teensy_post_compile". But there isn't any documentation. To see the command line syntax, use File > Preference in Arduino to turn on verbose output while compiling and uploading. Then you can see how Arduino runs it.

    It expects the USB port specified in an unusual syntax that represents the physical USB controller/hub/port. You can also see that syntax in the lower right corner of the Arduino window.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •