Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teensy 3.2 cannot be programmed after first time, unless press reset button #41

Closed
424778940z opened this issue Apr 7, 2016 · 39 comments
Assignees
Labels

Comments

@424778940z
Copy link

I'm using latest stable version platformio ide

This issue may caused by I set it to usb uart mode, and download script doesn't reboot it before program.

i did following change in this file: .atom\packages\platformio-ide\penv\Lib\site-packages\platformio\builder\scripts\teensy.py
start at: Line 68

before:

env.Append(
        UPLOADER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_post_compile"),
        UPLOADERFLAGS=[
            "-file=firmware",
            '-path="$BUILD_DIR"',
            '-tools="%s"' % join("$PIOPACKAGES_DIR", "tool-teensy")
        ],
        UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS'
    )

after:

env.Append(
        REBOTTER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_reboot"),
        UPLOADER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_post_compile"),
        UPLOADERFLAGS=[
            "-file=firmware",
            '-path="$BUILD_DIR"',
            '-tools="%s"' % join("$PIOPACKAGES_DIR", "tool-teensy")
        ],
        UPLOADHEXCMD='"$REBOTTER" & "$UPLOADER" $UPLOADERFLAGS'
    )

it solve this issue for now but will have a error because delay between restart and program is not enough
error msg: "Teensy Loader is currently busy with another operation (p). Please try again in a few seconds, or restart Teensy Loader."

@ivankravets
Copy link
Member

@PaulStoffregen Could you explain upload scenario? Should we make "teensy_reboot" before uploading? Currently, Teensy CLI asks to press "Reset button...".

@424778940z
Copy link
Author

@ivankravets It should reboot before program, because programming only can be done in bootloader mode.
however current official script do not reboot before program, that's why it can only success at the first time.

arduino ide reboot before program, it can success everytime.

@PaulStoffregen
Copy link

In Arduino, we run teensy_post_compile first, which sends a message to the (GUI-based) Teensy Loader to open the latest compiled file, and configure in auto mode. Then teensy_reboot is run, to send a request to the Teensy to reboot into bootloader mode. Because Teensy Loader is in auto mode, when the Teensy appears, it gets programmed by Teensy Loader.

If you're using the CLI instead of GUI, you probably want to run teensy_reboot first.

@424778940z
Copy link
Author

@PaulStoffregen thanks for the information, current official script using GUI loader, but not reboot

@424778940z
Copy link
Author

        REBOTTER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_reboot"),
        UPLOADER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_post_compile"),
        UPLOADERFLAGS=[
            "-file=firmware",
            '-path="$BUILD_DIR"',
            '-tools="%s"' % join("$PIOPACKAGES_DIR", "tool-teensy")
        ],
        UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS  & "$REBOTTER"'

This is the final code, works perfectly.

@ivankravets ivankravets self-assigned this Apr 8, 2016
@ivankravets
Copy link
Member

@424778940z by default PlatformIO uses Teensy Loader CLI. If you want to use Teensy Loader GUI, please place all files to ~/.platformio/packages/tool-teensy:

/Users/ikravets/.platformio/packages/tool-teensy
├── teensy.app
├── teensy_gateway
├── teensy_post_compile
├── teensy_reboot
└── teensy_restart

teensy_post_compile will call teensy_reboot automatically. We run the same comand as @PaulStoffregen does in Arduino IDE. See

Arduino IDE

"/Applications/Arduino.app/Contents/Java/hardware/tools/avr/..//teensy_post_compile" "-file=Blink.ino" "-path=/var/folders/nj/nt38kxwd2xxfl5l42np_w7qw0000gn/T/buildd5ae82e677127ac286f51de66781d807.tmp" "-tools=/Applications/Arduino.app/Contents/Java/hardware/tools/avr/../" "-board=TEENSY31"
Opening Teensy Loader...

PlatformIO

"/Users/ikravets/.platformio/packages/tool-teensy/teensy_post_compile" -file=firmware -path="/Volumes/SOFT/Projects/GitHub/platformio/origin/examples/wiring-blink/.pioenvs/teensy31" -tools="/Users/ikravets/.platformio/packages/tool-teensy"
Opening Teensy Loader...

@424778940z
Copy link
Author

@ivankravets

em...that's strange. I install platformio IDE with touch any settings. it use GUI version by default ...
And teensy_post_compile never call teensy_reboot....

@ivankravets
Copy link
Member

@424778940z Do you see teensy_loader_cli in ~/.platformio/packages/tool-teensy?

@424778940z
Copy link
Author

yes, it is there

@ivankravets
Copy link
Member

@424778940z Sorry, I've just remembered it... Teensy Loader CLI doesn't work on Windows 😞 See http://www.pjrc.com/teensy/loader_cli.html

You can ask @PaulStoffregen to add support in this repo https://github.com/PaulStoffregen/teensy_loader_cli

@ivankravets
Copy link
Member

@PaulStoffregen we call teensy_post_compile for uploading... Should we call separately teensy_reboot? I don't see this call in Teensyduino IDE.

@424778940z
Copy link
Author

@ivankravets PaulStoffregen is already answered above.

This issue is already solved by modify platformio script.

However, my way is a little bit lazy, just use & run them at one line.
Put them separately may looks better.

@ivankravets
Copy link
Member

@424778940z I don't understand how does it work for you. Rebooter requires GUI to be run. In your case, you call Rebooter before Teensy GUI.

Ok, I'll implement it.

@424778940z
Copy link
Author

@ivankravets
At the first time GUI start will looking for the ready board, then upload it and reset. This is works perfectly in platformio.

Problem is about second time upload, because GUI is already running, according to PaulStoffregen, it supposed to call teensy_post_compile fist tell GUI new file is ready, then call teensy_reboot reboot the hardware to bootloader mode allows GUI upload again.

In current platformio official code, it only call teensy_post_compile, but no reboot. Therefore GUI knows there is a new file ready, but the hardware is not in bootloader mode, GUI cannot upload, if people press reset button on the board at this time, it will uoload.

@424778940z
Copy link
Author

Here is the whole modified script

# Copyright 2014-2016 Ivan Kravets <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
    Builder for Teensy boards
"""

from os.path import isfile, join

from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
                          DefaultEnvironment, SConscript)

env = DefaultEnvironment()

if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy":
    SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "baseavr.py")))
elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
    SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
    env.Append(
        LINKFLAGS=[
            "-Wl,--defsym=__rtc_localtime=$UNIX_TIME",
            "-fsingle-precision-constant",
            "--specs=nano.specs"
        ],
        CCFLAGS=[
            "-fsingle-precision-constant"
        ]
    )

env.Append(
    CPPDEFINES=[
        "USB_SERIAL",
        "LAYOUT_US_ENGLISH"
    ],

    CXXFLAGS=[
        "-std=gnu++0x",
        "-felide-constructors"
    ]
)

if isfile(env.subst(join(
        "$PIOPACKAGES_DIR", "tool-teensy", "teensy_loader_cli"))):
    env.Append(
        UPLOADER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_loader_cli"),
        UPLOADERFLAGS=[
            "-mmcu=$BOARD_MCU",
            "-w",  # wait for device to apear
            "-s",  # soft reboot if device not online
            "-v"   # verbose output
        ],
        UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
    )
else:
    env.Append(
    #BZH_FIXED
        # UPLOADER=join(
            # "$PIOPACKAGES_DIR", "tool-teensy", "teensy_post_compile"),
        # UPLOADERFLAGS=[
            # "-file=firmware",
            # '-path="$BUILD_DIR"',
            # '-tools="%s"' % join("$PIOPACKAGES_DIR", "tool-teensy")
        # ],
        # UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS'
        REBOTTER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_reboot"),
        UPLOADER=join(
            "$PIOPACKAGES_DIR", "tool-teensy", "teensy_post_compile"),
        UPLOADERFLAGS=[
            "-file=firmware",
            '-path="$BUILD_DIR"',
            '-tools="%s"' % join("$PIOPACKAGES_DIR", "tool-teensy")
        ],
        UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS  & "$REBOTTER"'
    )

#
# Target: Build executable and linkable firmware
#

target_elf = env.BuildProgram()

#
# Target: Build the firmware file
#

if "uploadlazy" in COMMAND_LINE_TARGETS:
    target_firm = join("$BUILD_DIR", "firmware.hex")
else:
    target_firm = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf)

#
# Target: Print binary size
#

target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Upload by default firmware file
#

upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADHEXCMD")
AlwaysBuild(upload)

#
# Target: Define targets
#

Default([target_firm, target_size])

@ivankravets
Copy link
Member

@424778940z
Copy link
Author

@ivankravets Tested, it works perfectly.

@ivankravets
Copy link
Member

@424778940z thank you for the report and for the issue. 2.9.0 will be released next week.

ivankravets referenced this issue in platformio/platformio-core Apr 9, 2016
@zmrubin
Copy link

zmrubin commented Nov 13, 2017

Looks like things were moved around, and this fix was undone. Where does teensy.py / teensy.py's functionality live now?

@ivankravets
Copy link
Member

@scotram
Copy link

scotram commented Dec 4, 2018

@ivankravets
I am having this exact issue uploading to my Teensy 3.5. Is there a different fix for this board?
I am getting "Teensy did not respond to a USB-based request to enter program mode." However the auto reboot does work when I try flashing with the Arduino IDE. Its strange, because my very first program uploaded no problem at all. Any help is appreciated! Thank you.

@PaulStoffregen
Copy link

Auto-reboot requires software to work correctly on both sides of the USB cable. Every Teensy has a button dedicated for entering bootloader mode, because plenty can go wrong on either side.

To get an idea which side might be the problem, maybe try programming your Teensy using PlatformIO, so it has no code running that came from Arduino.

Then quit PlatformIO and run Arduino again. Does auto-reboot work from Arduino on the first try, while the Teensy still has code that was created by PlatformIO? If that works, it's a good sign PlatformIO is putting good code onto the Teensy which properly listens for the auto-reboot request from your PC.

Likewise, after Arduino has programmed the Teensy with known-good code, try running PlatformIO. This can serve as a double confirmation whether the problem is on the PC side not sending the auto-reboot request properly, or on the Teensy side not hearing it and entering bootloader mode.

@ivankravets ivankravets reopened this Dec 14, 2018
@ivankravets ivankravets transferred this issue from platformio/platformio-core Dec 14, 2018
@ivankravets
Copy link
Member

@PaulStoffregen which minimum version of Teensy Loader is required for Teensy 3.5? I see that the latest package in our repository is 1.41.

@ivankravets
Copy link
Member

@PaulStoffregen
Copy link

Its strange, because my very first program uploaded no problem at all. Any help is appreciated!

On that first try, perhaps Teensy is still running a program that was written by Arduino?

When you switch to Arduino, is a button press needed for the first upload? Then does Arduino upload automatically? On that first Arduino upload the Teensy would still running be running code that was created by PlatformIO.

If you can confirm both of these cases, that would suggest PlatformIO is indeed sending the reboot request properly, but creating images on the Teensy which do not respond to the request.

@scotram
Copy link

scotram commented Dec 14, 2018

Its strange, because my very first program uploaded no problem at all. Any help is appreciated!

On that first try, perhaps Teensy is still running a program that was written by Arduino?

When you switch to Arduino, is a button press needed for the first upload? Then does Arduino upload automatically? On that first Arduino upload the Teensy would still running be running code that was created by PlatformIO.

If you can confirm both of these cases, that would suggest PlatformIO is indeed sending the reboot request properly, but creating images on the Teensy which do not respond to the request.

OK.. i just uploaded a program to the board using PlatformIO (had to use the flash button). Right after this I opened Arduino and without even closing PlatformIO the Arduino IDE will auto-reboot and flash the Teensy with no issue, no button press necessary.

@PaulStoffregen
Copy link

Ok then, there goes that theory. Looks like PlatformIO is creating the correct code.

Any chance this is Windows 7? (or XP or 8... anything before 10 there Microsoft finally fixed the surprise removal bugs)

@PaulStoffregen
Copy link

If it's one of those older buggy versions of Windows, maybe whether PlatformIO still have a handle to the COM port open could be playing a factor?

@scotram
Copy link

scotram commented Dec 14, 2018

Ok then, there goes that theory. Looks like PlatformIO is creating the correct code.

Any chance this is Windows 7? (or XP or 8... anything before 10 there Microsoft finally fixed the surprise removal bugs)

Actually Mac Mojave, is that a problem? Should I try it on my windows 10 machine and see if I can replicate the failure?

@PaulStoffregen
Copy link

So far, the only problem I know on Mojave is a regression on ability to handle sustained maximum full speed incoming USB data. Still unknown whether it's a Java issue or something MacOS. To be realistic, it's on my to-do list for a few months from now. Currently working on an urgent profit (the kind that actually funds my time to do open source the rest of the year) so can't do a lot right now.

But yeah, try Windows 10. Avoid earlier pre-10 versions of Windows. They all have USB bugs.

Also, does PlatformIO support using the HID emulated serial? (like when you select MIDI or RawHID in Arduino Tools > USB Type)

@ivankravets
Copy link
Member

@PaulStoffregen could you take a look at what we actually do? See https://github.com/platformio/platform-teensy/blob/develop/builder/main.py#L214:L227

  1. We call teensy_post_compile
  2. We call teensy_reboot without any flags.

I see that in a case with CLI upload mode, we use teensy_reboot -s. Is it OK?

@scotram
Copy link

scotram commented Dec 14, 2018

So far, the only problem I know on Mojave is a regression on ability to handle sustained maximum full speed incoming USB data. Still unknown whether it's a Java issue or something MacOS. To be realistic, it's on my to-do list for a few months from now. Currently working on an urgent profit (the kind that actually funds my time to do open source the rest of the year) so can't do a lot right now.

But yeah, try Windows 10. Avoid earlier pre-10 versions of Windows. They all have USB bugs.

Also, does PlatformIO support using the HID emulated serial? (like when you select MIDI or RawHID in Arduino Tools > USB Type)

Alright, I tested it on windows 10 and the same problems occur. I cant flash with platformio unless i press the flash button AND have the teensy flasher program up in front of the platformio window. When i open Arduino IDE and attempt to flash it works every time.

@PaulStoffregen
Copy link

1. We call `teensy_post_compile`
2. We call `teensy_reboot` without any flags.

I can confirm that is the correct approach.

Sorry, can't do anything more at this moment. Big hardware project, already far behind schedule....

However, one thing that might help is comparing the exact commands. In Arduino, click File > Preferences and turn on verbose output while uploading. That should at least make the commands Arduino is using visible.

@424778940z
Copy link
Author

424778940z commented Dec 15, 2018

just got email from this issue after 2 years lol.

I think the problem still same as before, the teensy is not being rebooted, you could try write a simple bliking led code in pio, then load it to teensy.

then keep try load it again, see if the led still blinking at the same time, if it does it means teensy it not being rebooted. then we could try copy the teense tools from arduino to pio folder see if their version works.

@scotram
Copy link

scotram commented Dec 15, 2018

just got email from this issue after 2 years lol.

I think the problem still same as before, the teensy is not being rebooted, you could try write a simple bliking led code in pio, then load it to teensy.

then keep try load it again, see if the led still blinking at the same time, if it does it means teensy it not being rebooted. then we could try copy the teense tools from arduino to pio folder see if their version works.

Hey, I was hoping you'd chime in. I will give it a try and post my findings.

@ivankravets
Copy link
Member

@PaulStoffregen actually, you were right. I see that you use just 1 teensy_post_compile now. I did the same changes and it works for me now for Teensy 3.1 and Teensy 3.6

@scott620 @424778940z @zmrubin please re-test with the latest upstream version https://docs.platformio.org/en/latest/platforms/teensy.html#upstream

Also, please don't forget to update all packages via pio update or from PIO Home.

@ivankravets
Copy link
Member

Please update to the final 3.7.0 release https://community.platformio.org/t/teensy-dev-platform-v3-7-0/5975

@scotram
Copy link

scotram commented Dec 21, 2018

@PaulStoffregen actually, you were right. I see that you use just 1 teensy_post_compile now. I did the same changes and it works for me now for Teensy 3.1 and Teensy 3.6

@scott620 @424778940z @zmrubin please re-test with the latest upstream version https://docs.platformio.org/en/latest/platforms/teensy.html#upstream

Also, please don't forget to update all packages via pio update or from PIO Home.

Works perfectly now!

@424778940z
Copy link
Author

sadly I don't have a treensy anymore, my teensy was losted with a drone project.... I cannot test it this time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants