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

Thread: Program Teensy 4 from command line without pushing the button

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    6

    Program Teensy 4 from command line without pushing the button

    Hi,
    I'm trying to figure out a way to program the Teensy 4.1 from the command line (Ubuntu) without pushing the button because it will be sealed inside a box. Are there any workarounds to be able to do this (without using hardware to pull down the programming pin)?

  2. #2
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    649
    Yes, use the teensy_loader_cli with the '-s' option.

    See:
    https://www.pjrc.com/teensy/loader_cli.html

  3. #3
    Junior Member
    Join Date
    Apr 2021
    Posts
    6
    Quote Originally Posted by brtaylor View Post
    Yes, use the teensy_loader_cli with the '-s' option.
    Yeah, I tried that, but it didn't work. Unless I'm doing it wrong or something...it hangs when I program it:

    Code:
    mike@ubuntu:~/Downloads/teensy_loader_cli-master$ teensy_loader_cli --mcu=TEENSY40 blink_slow_Teensy40.hex -vs
    Teensy Loader, Command Line, Version 2.2
    Read "blink_slow_Teensy40.hex": 12132 bytes, 0.6% usage
    Error opening USB device: No error
    Waiting for Teensy device...
     (hint: press the reset button)
    Last edited by mah115; 04-15-2021 at 09:44 PM.

  4. #4
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    649
    We'll need more details - is it hanging on
    Code:
    Waiting for Teensy device...
     (hint: press the reset button)
    Or is there some other problem? Have you installed udev rules? Is the teensy connected via USB and powered?

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,915
    The "Error opening USB device: No error" may suggests a bad cable or some other software on the system has taken control of the USB Serial port or the Teensy doesn't have an active USB Stack running to recognize the incoming request.

    There was a recent update to the (udev?) "RULES" with TD 1.54 Beta 7 to account for new linux behavior

  6. #6
    Junior Member
    Join Date
    Apr 2021
    Posts
    6
    Quote Originally Posted by defragster View Post
    The "Error opening USB device: No error" may suggests a bad cable or some other software on the system has taken control of the USB Serial port or the Teensy doesn't have an active USB Stack running to recognize the incoming request.

    There was a recent update to the (udev?) "RULES" with TD 1.54 Beta 7 to account for new linux behavior
    It works if I push the button, so it doesnt' seem to be a port access or cable issue.
    I installed the UDEV rules already.

    The -s options says "Perform a sort (soft?) reset request by searching for any Teensy running USB Serial code built by Teensyduino." I'm confused by that statement. What USB Serial code am I supposed to be running for it to work?
    Thanks

  7. #7
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    649
    I just checked my use case again. If I don't have the Teensy plugged in and powered on, my readout is:
    Code:
    Teensy Loader, Command Line, Version 2.1
    Read "spi_example.hex": 15572 bytes, 1.5% usage
    Error opening USB device: No error
    Waiting for Teensy device...
     (hint: press the reset button)
    With Teensy plugged in and powered on, I get:
    Code:
    Teensy Loader, Command Line, Version 2.1
    Read "spi_example.hex": 15572 bytes, 1.5% usage
    Soft reboot performed
    Waiting for Teensy device...
     (hint: press the reset button)
    Found HalfKay Bootloader
    Read "spi_example.hex": 15572 bytes, 1.5% usage
    Programming................
    Booting
    This is on Ubuntu 20.04. Notice I also get the "Error opening USB device: No error" if no device is present, otherwise I don't.

    Typically, if my code is able to keep the Teensy up and running, the USB stack works (it's part of core) and I can soft-reboot all day long. If it's a brand new custom board, or I load some bad code (i.e. out of bounds memory access), then I need to press the button to get Teensy to come back up. This roughly correlates to the Arduino use case and whether I see Teensy in my ports list (USB working) or I see a teensy_hid device (USB not yet working).

    Maybe try the command line upload with soft reboot on a simple blink sketch to rule out a bad program / sketch causing the issue?

  8. #8
    Junior Member
    Join Date
    Apr 2021
    Posts
    6
    When you say plugged in, you mean plugged into and powered off of the USB, or are you using an external power supply? Which Teensy are you using? I've been using the Teensy 4.0 by itself (not plugged into any board), powered off USB, and using the Blink sketch provided with the CLI loader.

  9. #9
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    649
    Oh nevermind, I was testing with a Teensy 3.6, since that was what I happened to be working on. Tried again with the Teensy 4.1 and I can repeat the issue - no soft reboot working for me either.

    Interesting that I'm getting a different message though:
    Code:
    Teensy Loader, Command Line, Version 2.1
    Read "spi_example.hex": 18396 bytes, 0.9% usage
    Unable to soft reboot with USB error: error sending control message: Broken pipe
    Waiting for Teensy device...
     (hint: press the reset button)
    Maybe because I'm not on version 2.2?

  10. #10
    Junior Member
    Join Date
    Apr 2021
    Posts
    6
    Thanks for testing for me, I really appreciate it . I suppose the architecture of the Teensy 4 is a bit different.

  11. #11
    Senior Member
    Join Date
    Oct 2019
    Location
    Calgary
    Posts
    109
    Quote Originally Posted by brtaylor View Post
    Maybe because I'm not on version 2.2?
    The broken pipe error was caused by a too short "SET_LINE_REQUEST_TYPE" message. The system was expecting 7 bytes (4 bytes for speed, 1 for stop bit, 1 for data bits, and another for parity) but the loader was only sending 1 byte. Grab the latest version from Github; it's fixed there.

  12. #12
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    649
    Quote Originally Posted by Silverlock View Post
    The broken pipe error was caused by a too short "SET_LINE_REQUEST_TYPE" message. The system was expecting 7 bytes (4 bytes for speed, 1 for stop bit, 1 for data bits, and another for parity) but the loader was only sending 1 byte. Grab the latest version from Github; it's fixed there.
    Thanks, that works for me on Teensy 4.1:
    Code:
    Teensy Loader, Command Line, Version 2.2
    Read "spi_example.hex": 18396 bytes, 0.9% usage
    Soft reboot performed
    Waiting for Teensy device...
     (hint: press the reset button)
    Found HalfKay Bootloader
    Read "spi_example.hex": 18396 bytes, 0.9% usage
    Programming...............
    Booting
    So now mah115, I'm not sure again why it's not working for you. I just tried your exact command using the hex file from the teensy_loader_cli github and it works fine. Teensy 4.1 plugged in with a USB and that's it:
    Code:
    $./teensy_loader_cli --mcu=TEENSY40 blink_slow_Teensy40.hex -vs
    Teensy Loader, Command Line, Version 2.2
    Read "blink_slow_Teensy40.hex": 12132 bytes, 0.6% usage
    Soft reboot performed
    Waiting for Teensy device...
     (hint: press the reset button)
    Found HalfKay Bootloader
    Read "blink_slow_Teensy40.hex": 12132 bytes, 0.6% usage
    Programming.........
    Booting

  13. #13
    Senior Member
    Join Date
    Oct 2019
    Location
    Calgary
    Posts
    109
    I can duplicate the problem on Raspbian if I load "blink_slow_Teensy40.hex" into a Teensy4.1 and then try and load it again.
    Code:
    me@raspberrypi:~/Documents/src/teensy_loader_cli $ ./teensy_loader_cli --mcu=TEENSY41 blink_slow_Teensy40.hex -v -s
    Teensy Loader, Command Line, Version 2.2
    Read "blink_slow_Teensy40.hex": 12132 bytes, 0.1% usage
    Soft reboot performed
    Waiting for Teensy device...
     (hint: press the reset button)
    Found HalfKay Bootloader
    Read "blink_slow_Teensy40.hex": 12132 bytes, 0.1% usage
    Programming.........
    Booting
    me@raspberrypi:~/Documents/src/teensy_loader_cli $ ./teensy_loader_cli --mcu=TEENSY41 blink_slow_Teensy40.hex -v -s
    Teensy Loader, Command Line, Version 2.2
    Read "blink_slow_Teensy40.hex": 12132 bytes, 0.1% usage
    Error opening USB device: No error
    Waiting for Teensy device...
     (hint: press the reset button)
    But, if I compile the blink example for the Teensy4.1 and load that hex file, it works just fine:

    Code:
    me@raspberrypi:~/Documents/src/teensy_loader_cli $ ./teensy_loader_cli --mcu=TEENSY41 blink_slow_Teensy41.hex -v -s
    Teensy Loader, Command Line, Version 2.2
    Read "blink_slow_Teensy41.hex": 13428 bytes, 0.2% usage
    Soft reboot performed
    Waiting for Teensy device...
     (hint: press the reset button)
    Found HalfKay Bootloader
    Read "blink_slow_Teensy41.hex": 13428 bytes, 0.2% usage
    Programming...........
    Booting
    me@raspberrypi:~/Documents/src/teensy_loader_cli $ ./teensy_loader_cli --mcu=TEENSY41 blink_slow_Teensy41.hex -v -s
    Teensy Loader, Command Line, Version 2.2
    Read "blink_slow_Teensy41.hex": 13428 bytes, 0.2% usage
    Soft reboot performed
    Waiting for Teensy device...
     (hint: press the reset button)
    Found HalfKay Bootloader
    Read "blink_slow_Teensy41.hex": 13428 bytes, 0.2% usage
    Programming...........
    Booting
    The hex files for the blink example compiled for Teensy4.0 and Teensy4.1 are different.

  14. #14
    Junior Member
    Join Date
    Apr 2021
    Posts
    6
    Thanks everyone, I was able to get it to work on Linux (but not OSX or Windows). The culprit here was the included blink_slow_teensy40.hex file (even on the Teensy 4.0)--I recompiled a fresh one, and it works. So there's probably something incompatible with the existing hex files. I opened an issue ticket on github.

  15. #15
    Senior Member
    Join Date
    Oct 2019
    Location
    Calgary
    Posts
    109
    It was the hex file itself, not a 4.0/4.1 incompatibility? Interesting.

    The soft reboot code is only implemented in the Linux portion of the code. There's just a stub for OSX and Windows.

Posting Permissions

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