Executing the following code will result in a hung Teensy on loop 6:
The issue only occurs if the destination string already contains something (i.e. it is greater than zero length), and only occurs if the substring() call returns a string of zero length. We have tested on Teensy 4.0 and Teensy 4.1, both result in a fairly hard hang (requiring power cycle or button push). Interestingly a set watchdog timer will get it restarted on its own (obviously not included in the code above). Code runs fine and forever on regular Arduino/Mega/etc., just need to comment out the Serial.send_now() calls. This was all tested on Arduino 1.8.13, with Teensy 1.5.3 (on Linux).
We have started to look at the Teensy String code, but it will probably take us a while to muddle through that. Let us know if we can provide any further details on this that might be helpful.
Code:
String destination_string;
String source_string;
int counter;
void setup()
{
source_string = "ABC";
destination_string = "123";
counter = 0;
}
void loop()
{
counter++;
Serial.print("Beginning loop ");
Serial.println(counter);
Serial.send_now();
Serial.print(" source_string is ");
Serial.println(source_string);
Serial.send_now();
if(counter > 5)
{
destination_string = source_string.substring(2,2);
}
Serial.print(" destination_string is ");
Serial.println(destination_string);
Serial.send_now();
delay(1000);
}
The issue only occurs if the destination string already contains something (i.e. it is greater than zero length), and only occurs if the substring() call returns a string of zero length. We have tested on Teensy 4.0 and Teensy 4.1, both result in a fairly hard hang (requiring power cycle or button push). Interestingly a set watchdog timer will get it restarted on its own (obviously not included in the code above). Code runs fine and forever on regular Arduino/Mega/etc., just need to comment out the Serial.send_now() calls. This was all tested on Arduino 1.8.13, with Teensy 1.5.3 (on Linux).
We have started to look at the Teensy String code, but it will probably take us a while to muddle through that. Let us know if we can provide any further details on this that might be helpful.