Unintentional HIGH when uploading code to the Teensy 4.1

mwolters

Member
While working on the project for my Bachelor's Degree in Mechanical Engineering I've come along a strange little problem and i'd like to ask if the following behaviour is happening to anyone else and how to deal with it.
Whenever I'm uploading code onto my Teensy 4.1, there obviously is a kind of reset. When trying to use the Teensy in the following circuit, I could hear some of the relays switch.

teensy41_problem.PNG

That means that there has to be some kind of voltage applied on those pins during the reset. This results in a short lasting but unwanted connection over the NO-pins of the relay.
When testing which relays had switched, I found out that only relay1 and relay2, which are connected to Teensy 4.1 pins 24 and 25, got their switching voltage applied.
The other relays remained in their non-switched-state, eventhough they're wired up in the exact same way and handled by the code in the same way.

While trying to locate the problem, I decided to remove all of my developed switching circuit and also started up a new code.
I measured the output voltage directly on the Teensy Pins with an oscilloscope while uploading code which only function was to define all digitalpins and to put them on LOW.
There are no other electronics connected than the external 5 V, the USB-connection and the oscilloscope.
The following code is the code I used to analyse the voltages given out while resetting. When this code is uploaded to any of my Teensys, this behaviour occurrs.

Code:
#define testpin0 0
#define testpin1 1
#define testpin2 2
#define testpin3 3
...
...
...
#define testpin38 38
#define testpin39 39
#define testpin40 40
#define testpin41 41


void setup() {
  pinMode(testpin0, OUTPUT);
  digitalWrite(testpin0, LOW);
  pinMode(testpin1, OUTPUT);
  digitalWrite(testpin1, LOW);
  ...
  ...
  ...
  pinMode(testpin40, OUTPUT);
  digitalWrite(testpin40, LOW);
  pinMode(testpin41, OUTPUT);
  digitalWrite(testpin41, LOW);
}

void loop() {
}

I iterated this test by measuring every single Pin on the Teensy with the oscilloscope and registered that only Pin 24 and 25 apply a voltage of 3,3 V on their outputs while resetting.
No other pin applied voltage during the process. On a second Teensy 4.1 the exact same problem occurred.
The only thing I changed on the Teensys is cutting the PCB-bridge that connects the external 5 V input and the voltage of the USB-input, as the Teensy needs the usb serial port for communication while being powered externally

As I can't change the usable pin due to an ordered pcb, I had to implement another small extension-pcb.
This pcb contains even more relays that are used as a first stage switch, to prevent the unwanted connection over the relay.
The relays are activated as the first stage, after the teensy has finished resetting.
As this is not a perfect solution to my problem, i'd like to ask if this has been registered by anyone else and whether there is a code-ish way to solve this problem.

I hope I didn't miss to give any information - if so - feel free to ask.
Unfortunately I can't give any information on the circuit the relay switches, but as it's completely seperate from the Teensy itself, there should be no interference.

I hope that we can solve this problem and a big thank you in advance.
 
Indeed I have seen this. Not gotten an answer to my questions, and I have not seen it noted or addressed anywhere on the forum.

Bootloader V 1.07 for MCU 1062's ( 4.x or MicroMod ) - NEW with TD 1.56 triggers Pin #24 as seen while the bootloader chip is in active control:
> whenever button is pressed and in bootloader
> or during UPLOAD when Bootloader is active

Teensy with 1062 ( 4.x or MicroMod ) using bootloader before V 1.07 activate Both pins #24 and #25 as above while the bootloader is active.

As seen here: This behavior does NOT happen during a normal power on boot, only when the bootloader is active.

NOTE: Testing here was with an LED on pins 24 and 25. When they are held HIGH the LED is bright, then when the Teensy 'boots' and starts after an upload the LED's are powered but very "DIM" - it seems being held high with low current keeper voltage?

Given the nature of the bootloader being involved, this can only possibly be solved with an update to the bootloader.
 
would a week pulldown resister not help?

That sounds like an EE question.

Though given full bright WHITE or GREEN LED through a suitable resistor as configured, it seems the output current is intentionally HIGH. So, it already has some weak resistance before the LED.

In fact as noted it is still DIM when the Teensy restarts after UPLOAD, and I think that is the default KEEPER current set on the pins so they don't flop around and use more current ... if reading of prior posts serves. If that weak current 'keeping' is toward 3.3V and can leak through the resistor and power the LED, then it would take a dead short.

BTW @mwolters: To be explicit RE p#2, With upgrade to bootloader V 1.07 ONLY pin #24 is held HIGH AFAIK, and Pin #25 is no longer affected. It isn't indicated, but it seems you have the prior bootloader not yet updated with installed TeensyDuino 1.56? Moving to TD 1.56 will cut your troubles in half with bootloader V 1.07 update.
 
First off - A big thank you for your answers. It's great to know that this is not a new problem and there is a kind of solution to get rid of the problem!

I'm sorry for taking my time to respond. I'm rather new to programming and I honestly didn't know that this could be a problem. Looking back on it - it does make sense.
I've been trying to find out which version I have installed. My TD-version is TD 1.53 and also my Arduino-IDE is pretty outdated. I'll try to update both and i'll make sure to post my results.

Again - Thank you for your help so far!
 
After updating both the Arduino IDE and TeensyDuino there have unfortunately been no changes. In my case Pin #25 still seems to be affected.
When uploading the code to the Teensy, there was a note saying that the bootloader had been updated - so I'm pretty sure that it is now on V 1.07.

I kept on testing and the results on Pin #24 (Yellow) und #25 (Red) are the following:
oscilloscope_31012022_1126(1).jpg
 
Presumably the pins are being actively driven high by code in the bootloader (I presume for debugging the bootloader,
or because these pins are the second I2C interface and the bootloader is checking that bus?)

Pulldowns won't help if the pin is actively driven. Can you use different pins?
 
After updating both the Arduino IDE and TeensyDuino there have unfortunately been no changes. In my case Pin #25 still seems to be affected.
When uploading the code to the Teensy, there was a note saying that the bootloader had been updated - so I'm pretty sure that it is now on V 1.07.

I kept on testing and the results on Pin #24 (Yellow) und #25 (Red) are the following:

Teensy Loader "Help / Verbose" output will confirm bootloader version.

Not looking with a scope or meter here - just a set of LED's on pins 24 and 25.

There was a change on #25 not lighting the LED going to v 1.07 - maybe the current/voltage just isn't triggering the photon emission across the LED/resistor. It does NOT on the ORANGE LED BOARD as it did on prior bootloader!
Correction > seeing pin #25 dimly light LED while in bootloader - then after upload it goes to some half that brightness.

First saw this on a board with ORANGE LED's attaches to ALL EDGE pins on T_4.1. Then manually monitored using white or green LED through some suitable resistor.

The white and green show the dim glow after upload and starting, the Orange may have a larger resistor '1001' array SMD that pulls down enough to take the 'keeper' low - or enough to mute it.
 
This kind of got me curious so was curious.

What I am seeing is when I upload a sketch (BLINK.ino) I see pin 24 going high using a LED breakout board with leds on all pins. Then it goes off like shown in your scope shot. But if I turn the power off and then back on pin 24 LED stays dark. So if it was a bootloader issue wouldn't pin 24 blinking wouldn't show on each power cycle? Looks like its only happening on uploading a sketch... I am not seeing pin 25 light up but that doesn't mean its not - may just not be visible.

Also if you look at the bootloader sequence shown on https://www.pjrc.com/store/ic_mkl02_t4.html doesn't involve pin 24 (AD_B0_12) even if its an issue with JTAG not responding (look further down on the page to troubleshooting section).

So maybe its more associated with teensyloader?
 
This kind of got me curious so was curious.

What I am seeing is when I upload a sketch (BLINK.ino) I see pin 24 going high using a LED breakout board with leds on all pins. Then it goes off like shown in your scope shot. But if I turn the power off and then back on pin 24 LED stays dark. So if it was a bootloader issue wouldn't pin 24 blinking wouldn't show on each power cycle? Looks like its only happening on uploading a sketch... I am not seeing pin 25 light up but that doesn't mean its not - may just not be visible.

Also if you look at the bootloader sequence shown on https://www.pjrc.com/store/ic_mkl02_t4.html doesn't involve pin 24 (AD_B0_12) even if its an issue with JTAG not responding (look further down on the page to troubleshooting section).

So maybe its more associated with teensyloader?

Use a USB Battery box and push the Button - the pin 24 shows up - (wasn't watching #25 as I thought that was off): Not Host software - the bootlooader MCU is in control of the MCU ... OR wants to be ... and putting the MCU in 'that state' it is powering those pins.

(noted above) The ORANGE PJRC 'edge pin' LED board resistors must MUTE the Pin #25 to the LED - use an alternate LED or DVM on pin 25 and voltage is present - fooled me too.
 
Use a USB Battery box and push the Button - the pin 24 shows up - (wasn't watching #25 as I thought that was off): Not Host software - the bootlooader MCU is in control of the MCU ... OR wants to be ... and putting the MCU in 'that state' it is powering those pins.

(noted above) The ORANGE PJRC 'edge pin' LED board resistors must MUTE the Pin #25 to the LED - use an alternate LED or DVM on pin 25 and voltage is present - fooled me too.

Ok. Hooked up a LA to pins 24 (channel 4), 25 (channel 5) , 14 (channel 6) and 13 (LED).
Capture.PNG

1st section shows sketch running and pins 24/25/14 are Low. Reloaded the Blink sketch and with the Blink Sketch running Pins 24 and 25 go high and stay high. Next I recycled power (Off and then ON again) and notice pins 24 and 25 show low which is what they are supposed to be.

And if I just power the T4.1 running blink off a battery pack (5v + GND):
Capture1.PNG
 
Ok. Hooked up a LA to pins 24 (channel 4), 25 (channel 5) , 14 (channel 6) and 13 (LED).

1st section shows sketch running and pins 24/25/14 are Low. Reloaded the Blink sketch and with the Blink Sketch running Pins 24 and 25 go high and stay high. Next I recycled power (Off and then ON again) and notice pins 24 and 25 show low which is what they are supposed to be.

And if I just power the T4.1 running blink off a battery pack (5v + GND):

While on Battery - can you show the graph when the Button is pushed. It will match to some degree HIGH on #24 and #25

Can you wire in the Program Pin as well?

Also: in the first graph - LA shows zero, but it seems as it the voltage IF HIGH on Reset (powering an LED) - the 'Keeper' works to maintain that voltage w/low current.

> just put the LED's on 24 and 25. The current from #24 is MUCH greater than from 25 - even when in bootloader. But both DIM ON after upload completes and code - so something over 1V for sure to pass the LEDs - now white and blue.

Resistors on self wired LEDs are 220 Ohm and the ORANGE PJRC board measure 1K Ohm.
 
Last edited:
Sketch running and then power button pressed:

That is what I saw and expected would show there. Running on USB power - no HOST or Teensy Loader online ... This is what would happen with an installed device and the button triggered while Teensy sits in Bootloader mode.

"Power Button" ... "Program Button"
 
That is what I saw and expected would show there. Running on USB power - no HOST or Teensy Loader online ... This is what would happen with an installed device and the button triggered while Teensy sits in Bootloader mode.

"Power Button" ... "Program Button"

Sorry but I think we got our wires crossed that was with usb + teensy loader uploading the sketch with the png button. Will rerun in the morning just on ext pwr
 
The theory is that they are "input pullup" in this state. And this is weak. So it would help.

I didn't test this so far, as the pcb is already finished and I didn't want to wire any resistors externally.
I have to admit that I was hoping for an easy software-ish way out of the situation.

However, I'll try the solution with a pulldown over the course of this morning and I will share my results!
Thank you for the idea!
 
Sorry but I think we got our wires crossed that was with usb + teensy loader uploading the sketch with the png button. Will rerun in the morning just on ext pwr

Wasn't sure when it was noted as "power button"

Thought that was testing with the USB Battery power bank running then hitting program Button - showing it isn't Loader related.

Same issue from email back around Christmas when the new Orange LED Board made it evident ... maybe notobdy got those emails ... I never got an answer after a couple repeat queries ...
 
I didn't test this so far, as the pcb is already finished and I didn't want to wire any resistors externally.
I have to admit that I was hoping for an easy software-ish way out of the situation.

However, I'll try the solution with a pulldown over the course of this morning and I will share my results!
Thank you for the idea!

Given the intensity of the #24 I don't think a pulldown will help or be wise, maybe on #25, but if 24 gets pulled down to off in bootloader it will never come on when running.

Though a pulldown will assure it doesn't stay lit after restart, pin #24 is full bright in bootloader - even swapping diff color LEDs on the same resistor array - 24 is always brighter than same on 25.
 
That is what I saw and expected would show there. Running on USB power - no HOST or Teensy Loader online ... This is what would happen with an installed device and the button triggered while Teensy sits in Bootloader mode.

"Power Button" ... "Program Button"

I could observe the same graph on my own oscilloscope when pressing the Program Button as in post#15 by mjs.
And I also get the same graphs from post#13 - which means that there is no voltage applied, when the Teensy is started up without trying to upload code.

Based of that, I could get a way around the Teensy switching the relays:
I have to remove the Teensy from my PCB, power it up externally, wire up the USB, upload my sketch, power off, put it back onto the PCB and power it up again on there.
In this case there is a fresh code and no unwanted contacts via the relays involved.

However as this takes a lot of single steps while testing different codes, I'm open for any other solution!
 
I could observe the same graph on my own oscilloscope when pressing the Program Button as in post#15 by mjs.
And I also get the same graphs from post#13 - which means that there is no voltage applied, when the Teensy is started up without trying to upload code.

Based of that, I could get a way around the Teensy switching the relays:
I have to remove the Teensy from my PCB, power it up externally, wire up the USB, upload my sketch, power off, put it back onto the PCB and power it up again on there.
In this case there is a fresh code and no unwanted contacts via the relays involved.

However as this takes a lot of single steps while testing different codes, I'm open for any other solution!

Indeed, only on UPLOAD - it was noted in post#2 :
As seen here: This behavior does NOT happen during a normal power on boot, only when the bootloader is active.

So if the #24 and #25 relays are somehow OFFLINE during programming this will work in the case. And unless the Program Button is pressed - it will never be observed when the system is 'Live'.
 
Wasn't sure when it was noted as "power button"

Thought that was testing with the USB Battery power bank running then hitting program Button - showing it isn't Loader related.

Same issue from email back around Christmas when the new Orange LED Board made it evident ... maybe notobdy got those emails ... I never got an answer after a couple repeat queries ...

Was late meant program button :(
 
From other thread:
Unfortunately there isn't a lot of solid documentation. The actual behavior is a combination of what the hardware does at reset and what NXP's ROM does at startup and when Teensy's bootloader does when it takes control of the hardware.

At reset, the hardware turns most of the pins to inputs with "weak keeper" circuitry. The keeper is basically a pullup or pulldown resistor which tries to keep the pin at whatever logic level it was previously.

NXP's ROM changes pins 24 & 25, and might do other stuff, but generally it leaves most pins alone.

Likewise, Teensy bootloader will leave all the pins as they were. It only uses the flash memory and main USB port.

However, the 15 second restore is special. It puts all pins into high impedance mode. If you press the button for 13-17 seconds and allow the flash wipe & restore to run, all the pins (except the flash signals) go tristate while it slowly wipes the flash.

If you want certain pins to be well defined voltages, real pullup or pulldown resistors are the way to go. Values like 1K to 10K are probably about right if you want to override the weak keepers. Otherwise 100K can probably work, if you only need defined results at powerup and you're willing to have the pin stay as whatever it was when the hardware stopped.

Avoid pins 24 & 25. NXP's ROM uses the pins before Teensy's bootloader can take control. You'll get undefined behavior on those pins.
 
I am currently facing a similar issue but with different pins: 36 and 48 (back) on Teensy 4.1. My situation is very similar to the one from @mwolters. I have chosen 8 different digital pins to control 8 relays, and pins 36 and 48 always started HIGH during Teensy startup, even if it was just a normal power on boot. I have used Teensy 3.5 for a long time and didn't have this issue.

What happened is that even before I could set those 8 pins to OUTPUT and LOW in the top of setup() function, the relays switched because the pins voltage reached 3.3V for some fractions of a second during startup code, activating the relay. I could not find any solution for this problem and decided not to use pins 36 and 48 and move to other pins. This worked. I still have no idea why this happens with some pins but not others. I have tested with many different Teensy 4.1 and all of them had the same issue. I even tried an separate Teensy 4.1 without any hardware or pin attached, just the USB cable, and a blink sketch, and pins 36 and 48 go HIGH anyway.

In my situation, could a pulldown connected to those pins help? Or are they directly driven HIGH?
 
Back
Top