Upload problem.

Stanleyvc

Active member
Dear all,

I regularly use the Teensy 4.1
And when a programme is already in the teensy, very often the automatic upload function to also the manual upload function of the "Teensy Loader" does not work.
When you then press the reset button, the programme does upload nicely.
This is tricky because the Teensy is mounted in a housing and then it has to be opened every time.

How would I urn solve this, thanks in advance.
 
It is NOT a RESET button, but a PROGRAM button.
You could have a small hole over the PROGRAM button and then press it with a pin.
 
You could add a momentary pushbutton switch (mounted somewhere accessible) attached to the GND and Program holes above the SD card slot:
card11b_rev4_web.png
 
Thanks,

But I don't mean via the programme button, but from the "Teensy Loader" which uploads the hex to the teensy. Normally you don't need to press this little button. But sometimes this doesn't work and I do have to press the button and wonder why?
 
That would have to be a bug in your program, by default the usb code is always listening for the reset sequence that the loader sends.
 
Ok, but what does that affect?

The most common problem is disabling interrupts for too long, either by intentionally using noInterrupts() or cli() or similar, or by your own interrupt function which takes too long and thereby blocks other interrupts until it completes.

When software on your PC tries to ask Teensy to go into programming mode, the USB host controller inside your PC sends a control transfer. The USB device controller inside Teensy hears this and requests an interrupt to handle it. Control transfers require an ACK response. If Teensy doesn't acknowledge within a short time, the USB device driver in your PC gives up. The software keeps trying, making many attempts for about 6 seconds. But if Teensy just isn't responding to the USB control transfer, there's nothing it can do.

Disabling interrupts isn't the only thing which your program can do, but it's the common issue. You could also put the CPU into low power modes where the USB interrupt does wake it up. You can even turn off the USB hardware or mess us the PLL which generates the 480 MHz clock it uses. The USB code which gets compiled into every program does use some memory, so if you have a buffer overflow or other serious software problem that overwrites other memory, you can also interfere with the USB code's ability to respond to the control transfer. There are many other ways, though they're pretty unlikely for "normal" programs which don't mess with very low-level access to the hardware.

Please understand this is all blind guesswork. You asked what can affect the USB communication, and I've tried to answer. But I can't see anything about your program. But I'll make this already lengthy message a bit longer with some practical suggestions to troubleshoot, also absent any specific knowledge of your code. First try a basic LED blink program, just to confirm the simplest possible program does reliably respond to those USB control transfers. Then try with a copy of your program where you delete or disable large portions of its functionality. Obviously if you whittle it all the way down to just the basic LED blink, it will work. But your goal is to discover which portion of your program is somewhere interfering with the USB communication. Once you find a large change which makes that difference, then put it back and try to remove successively smaller parts. Not all program are so simple that each part acts independently, so of course this generic advice requires some good thinking to apply to your program.

Just remember, I can't see anything about your program, so this generic answer is the best I can do. Hopefully it helps?
 
Problems can also happen entirely on your PC. Usually you would see an error message. The most common problem is some other program (not the Arduino IDE) tries to access Teensy. Especially with Windows, when another program has opened access to Teensy, access from Arduino IDE gets blocked.

Before Windows 10 the USBSER.SYS driver had terribly confusing bugs, which could cause these problems depending on the way Teensy had previously disconnected and what was running on your PC in that moment. Thankfully Microsoft finally fixed those horrible problems with Windows 10, so this is a non-issue unless you have Windows 7, 8, or older. But it used to be a huge problem because so many people used Windows 7 for so long, and despite looking pretty and running a lot of popular games, the USB driver quality on Windows 7 was abysmal.

None of this should matter if you're only using Arduino IDE and a modern operating system. But you asked what can affect it, and while unlikely, problems on the PC side are unlikely but also a possibility.
 
Last edited:
Sorry for the long post, but I can assure you that its length is merely to fully convey a potential work-around to the inability to upload to the Teensy without pressing the PROGRAM button !!

I occasionally have similar problems uploading to multiple Teensy 4.x devices which are embedded in a multitude of different projects. In my particular case, I have narrowed it down to the following set of repeatable circumstances (I call this my "shake the rubber chicken" solution . . . you know, shake the rubber chicken & the problem goes away . . . but, does the rubber chicken really have anything to do with the solution, or is it merely a happy coincidence ?!?!?):

EDIT: I forgot to mention that all of these screen captures were done with a Teensy 4.0 running the unmodified BLINK example, with absolutely nothing else connected. So, in this case at least, it's not likely anything going on within the Teensy itself . . . this one is strictly something going wrong with Windows !!

When I am unable to upload to my Teensy(s) without pressing the PROGRAM button, I have noticed the following in Device Manager (I'm running Windows 11 Pro, Version "24H2", OS Build "26100.3037", Experience "Windows Feature Experience Pack 1000.26100,48.0"):

I have an extra device that shows up under the category "Other devices" & is identified by Windows as "USB Serial", always with a yellow triangle on it as follows:

1738463672049.png


Double-clicking on that (failed) device reveals the following (NOTE, in particular, the indication that "The drivers for this device are not installed. (Code 28)"):

1738463780519.png


Now, here's the rubber chicken:

If I right-click on that failed USB Serial device, and select "Uninstall device", as follows:

1738463936172.png


And this warning is presented:

1738464195399.png


Following the uninstall, the ability to upload to the Teensy without pressing the PROGRAM button is restored !!

I have no idea how nor why this failed device is being created (the "magic" of Windows & its associated registry at work !!), but its presence seems to be interfering with the Teensy upload process in a very deterministic & detrimental way.

Hope that helps . . .

Mark J Culross
KD5RXT

P.S. I'm willing to take any suggestions for further troubleshooting of this particular set of circumstances in order to help pin down an explanation of the actual cause and/or determination of the actual solution, if even there is one (again, this is Windows !!). In the meantime, I'll continue shaking the rubber chicken & making use of the positive results of doing so, even if it shouldn't be having any effect at all !! MJC
 

Attachments

  • 1738463639326.png
    1738463639326.png
    119.6 KB · Views: 6
  • 1738464125544.png
    1738464125544.png
    25.2 KB · Views: 3
Last edited:
Back
Top