Freezing the program running for a short time on startup (Teensy 4.1)

Hello everyone!

I encountered a particular problem when I connected Teensy 4.1 to the PC (via USB).

The problem occurs when I apply a digital signal to a GPIO pin declared as an input.

I have made a simple example program:

A button is connected to GPIO pin 2 (the pin has a 3300 Ohm pulldown resistor).
The button sets GPIO pin 2 to HIGH (3.3V)
As output I used the LED mounted on the board (e.g. GPIO pin 13).

The program reads GPIO pin 2 and writes the value to GPIO pin 13.

In addition to writing the value to GPIO pin 13, I write the digital value of GPIO pin 2 to the serial port (USB).

The problem occurs when I connect Teensy 4.1 to my PC.

By pressing the button quickly, the LED connected to pin 13 of the GPIO flashes but for a short time it stops (half a second, even less) and then starts again and everything stabilizes.

In addition to writing the value to GPIO pin 13, I write the digital value of GPIO pin 2 to the serial port (USB).

The loaded program is indifferent.

I tried to load a more complex program in which the Teensy 4.1 has an address bus to control the multiplexers and I noticed that when I connect it to the PC and try to activate an input from the multiplexers the bus freezes for a moment (always half a second, even less) and then starts again and everything stabilizes.

I tried to load various projects (programs) in which there are GPIO pins declared as input and serial enabled, and all of them have this block at startup if Teensy 4.1 is connected to the PC (USB)

I tried powering Teensy 4.1 with an external power supply and the blockage problem did not occur.

The program starts and does not crash.

The problem occurs with all 5 Teensy 4.1. I have both version MIMXRT1062DVJA and version MIMXRT1062DVJB (final A&B)

Has anyone had this problem?

I'm very curious to understand why it happens and how to fix it, if you can...

Because if I have to connect Teensy 4.1 via USB to transmit MIDI data but then it freezes for a moment at startup, I don't like it...:(

Sample program:

Code:
#define Pin_In 2
#define Pin_Out 13

bool Input, Last_Input;
bool Output;

void setup() {
 
  delay(10);

  pinMode(Pin_In, INPUT);
  pinMode(Pin_Out, OUTPUT);

  Serial.begin(115200);

  delay(100);

  digitalWrite(Pin_Out, 1);
  delay(500);
  digitalWrite(Pin_Out, 0);
  delay(500);

  delay(100);

}

void loop() {

  Input = digitalRead(Pin_In);
 
  Output = Input;

  digitalWrite(Pin_Out, Output);
 
  if(Input != Last_Input){

    Serial.print("Input > ");
    Serial.println(Input);

    Last_Input = Input;
  }

}

The settings in the drop-down menu (Arduino IDE 2.3.3):

Factsheet: Teensy 4.1
Port: USB:10003/0/0/8 (COM25 Serial (Teensy 4.1)
Keyboard layout: American English
Optimize: Faster
CPU Speed: 600Mhz
USB Type: Serial

Thank you all in advance for your help!!:D
 
Last edited:
translation of p#1 below ...

Normally Serial.begin(115200); is used and when USB is seen as 'connected' it can wait for a bit over 2 seconds to see if USB fully connects. It will exit sooner when USB connects.

When running from 5V external then there will be no USB detected and that would likely fall through without any wait.

That Serial.begin(115200); can be removed and USB will still start when connected - though early messages would likely be missed.

Hello everyone!

I encountered a particular problem when I connected Teensy 4.1 to the PC (via USB).

The problem occurs when I apply a digital signal to a GPIO pin declared as an input.

I have made a simple example program:

A button is connected to GPIO pin 2 (the pin has a 3300 Ohm pulldown resistor).

The button sets GPIO pin 2 to HIGH (3.3V)

As output I used the LED mounted on the board (e.g. GPIO pin 13).

The program reads GPIO pin 2 and writes the value to GPIO pin 13.

In addition to writing the value to GPIO pin 13, I write the digital value of GPIO pin 2 to the serial port (USB).

The problem occurs when I connect Teensy 4.1 to my PC.

By pressing the button quickly, the LED connected to pin 13 of the GPIO flashes but for a short time it stops (half a second, even less) and then starts again and everything stabilizes. The program reads GPIO pin 2 and writes the value to GPIO pin 13.

In addition to writing the value to GPIO pin 13, I write the digital value of GPIO pin 2 to the serial port (USB).

The problem occurs when I connect Teensy 4.1 to my PC.

By pressing the button quickly, the LED connected to pin 13 of the GPIO flashes but for a short time it stops (half a second, even less) and then starts again and everything stabilizes.

The loaded program is indifferent.

I tried to load a more complex program in which the Teensy 4.1 has an address bus to control the multiplexers and I noticed that when I connect it to the PC and try to activate an input from the multiplexers the bus freezes for a moment (always half a second, even less) and then starts again and everything stabilizes.

I tried to load various projects (programs) in which there are GPIO pins declared as input and serial enabled, and all of them have this block at startup if Teensy 4.1 is connected to the PC (USB)

I tried powering Teensy 4.1 with an external power supply and the blockage problem did not occur.

The program starts and does not crash.

The problem occurs with all 5 Teensy 4.1. I have both version MIMXRT1062DVJA and version MIMXRT1062DVJB (final A&B)

Has anyone had this problem?

I'm very curious to understand why it happens and how to fix it, if you can...

Because if I have to connect Teensy 4.1 via USB to transmit MIDI data but then it freezes for a moment at startup, I don't like it...:(

Sample program:

Code:
#define Pin_In 2
#define Pin_Out 13

bool Input, Last_Input;
bool Output;

void setup() {
 
  delay(10);

  pinMode(Pin_In, INPUT);
  pinMode(Pin_Out, OUTPUT);

  Serial.begin(115200);

  delay(100);

  digitalWrite(Pin_Out, 1);
  delay(500);
  digitalWrite(Pin_Out, 0);
  delay(500);

  delay(100);

}

void loop() {

  Input = digitalRead(Pin_In);
 
  Output = Input;

  digitalWrite(Pin_Out, Output);
 
  if(Input != Last_Input){

    Serial.print("Input > ");
    Serial.println(Input);

    Last_Input = Input;
  }

}

The settings in the drop-down menu (Arduino IDE 2.3.3):

Factsheet: Teensy 4.1
Port: USB:10003/0/0/8 (COM25 Serial (Teensy 4.1)
Keyboard layout: American English
Optimize: Faster
CPU Speed: 600Mhz
USB Type: Serial

Thank you all in advance for your help!!:D
 
Update:

I discovered that if I omit the serial writing (Serial.print) in the program, the block does not occur at startup.

I found that the freeze only happens when the first serial write takes place even if the program started a long time ago.
 
translation of p#1 below ...

Normally Serial.begin(115200); is used and when USB is seen as 'connected' it can wait for a bit over 2 seconds to see if USB fully connects. It will exit sooner when USB connects.

When running from 5V external then there will be no USB detected and that would likely fall through without any wait.

That Serial.begin(115200); can be removed and USB will still start when connected - though early messages would likely be missed.
I didn't understand...

Can I remove the Serial.begin() statement?

Even if in the "loop()" function I use the serial?
 
Update:

I realized that Serial is just USB communication.

I found that if I use a hardware serial (not USB) the system does not crash.

I found that if the serial communication is connected to a terminal such as the serial monitor of Arduino IDE 2.3.3 the program does not crash.

I also tried with a terminal that I created in Visual Studio (Basic) and it works: if I connect the Teensy 4.1 to the PC and let it communicate with the serial monitor it does not crash.

It crashes only if I connect it to the PC without any program that reads the data from the USB serial.

It seems that the program freezes because of USB serial communication, as explained by the user "defragster", that is, that it does not find any terminal or receiver to write the data...

Is the reasoning correct?

Thanks for the help!!
 
Yes,
The code will start before USB is connected - and some prints may be lost - but USB always starts when connected if specified
If I omit the instruction "Serial.begin(115200);" at what speed does it work?

If I have a Serial Monitor program (like my custom one I created) that needs to know the communication speed how do I do it?

Thanks for the help! :D
 
what speed does it work?
Teensy has native USB and always runs at the hardware supported USB speed 12 or 480 Mbps.
With Teensy that (baud) param is ignored - but required to be supplied for compatibility.

It is not like those using a UART to USB transfer chip that require a baud rate.
 
Hey!Based on your description, the issue could come from USB power, Teensy 4.1 is quite "power-hungry," especially at higher CPU frequencies.Try adding a 100uF capacitor between VUSB and GND, it might help stabilize the voltage, It helped me with a similar issue.Also, check the ground connection between the PC and Teensy.Sometimes ground potential differences can cause interference. :giggle:
 
Back
Top