Bug: SerialUSB.read is not functional

This has also been added as issue #652 in the cores GitHub repo.

There appears to be an issue with the USB serial driver supplied with Teensyduino. Some critical state info. is not being transmitted by the Teensy driver to the Linux host, which in turn causes the Linux cdc_acm driver to block sending any data to the Teensy.

In other words, the SerialUSB only works in one direction: from Teensy to Linux.

The test program is attached.

The test program was also used with an Arduino Nano 33 BLE Sense, and a Raspberry Pi Pico, with no issues. Same test environment.

Ubuntu Linux 18.04.6
Arduino IDE 1.8.15
Teensyduino 1.57
Board: Teensy4.1
USB Type: Serial
Speed: 600MHz
Optimize: Debug (also Faster tested)
Serial port: /dev/ttyACM0

Steps:
1. Load program onto board
2. Open Arduino IDE Serial Monitor
3. Echo Test Ready appears in Serial Monitor
4. In the Serial Monitor input area, type any character and hit Return
5. Continue step 4, noticing there is no output in the Serial Monitor. Eventually the entire Arduino IDE will stop responding until the Teensy is powered off.

This behavior can also been seen at a Terminal command prompt with the Teensy powered on:

Code:
echo hello > /dev/ttyACM0
The command will simply hang until the Teensy is powered off.

David Davis
 

Attachments

  • EchoTest.zip
    576 bytes · Views: 89
Such a short sketch easily posts:
Code:
void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB) {
    delay(1000);
  }
  SerialUSB.println("Echo Test Ready");
}

void loop() {
  if (SerialUSB.available() > 0) {
    SerialUSB.print("Got character: ");
    char c = SerialUSB.read();
    if (isPrintable(c)) {
      SerialUSB.print(c);
    }
    SerialUSB.print(" (");
    SerialUSB.print(c, DEC);
    SerialUSB.println(")");
  }
}
 
On Windows 11 against TyCommander as SerMon not able to see it fail.

On Windows there is no driver installed - the default system driver is used.

The Code doesn't seem to have a way to know the Teensy is receiving data ... blink the LED on receive, or other? : " SerialUSB only works in one direction: from Teensy to Linux."
Code:
// https://forum.pjrc.com/threads/71035-Bug-SerialUSB-read-is-not-functional
void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB) {
    delay(1000);
  }
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  SerialUSB.println("Echo Test Ready");
  pinMode( LED_BUILTIN, OUTPUT );
}

void loop() {
  if (SerialUSB.available() > 0) {
    digitalToggle( LED_BUILTIN );
    SerialUSB.print("Got character: ");
    char c = SerialUSB.read();
    if (isPrintable(c)) {
      SerialUSB.print(c);
    }
    SerialUSB.print(" (");
    SerialUSB.print(c, DEC);
    SerialUSB.println(")");
  }
}

Assuming the linux install also uses standard USB driver code - the problem can be the assumption of the port by another modem program?
 
Works fine when I run it here on Ubuntu 20.04.

screenshot.png
 
Odd - added a char Rx count display - and using TyComm upload of the Source file and some characters I got this:
TeensyBusy.png
No more LED blinks and No more reply from Teensy.

Code:
// https://forum.pjrc.com/threads/71035-Bug-SerialUSB-read-is-not-functional
void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB) {
    delay(1000);
  }
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  SerialUSB.println("Echo Test Ready");
  pinMode( LED_BUILTIN, OUTPUT );
}

uint32_t cCnt = 0;
void loop() {
  if (SerialUSB.available() > 0) {
    digitalToggle( LED_BUILTIN );
    cCnt++;
    SerialUSB.print(cCnt);
    SerialUSB.print(" chars Rx\t");
    SerialUSB.print("Got character: ");
    char c = SerialUSB.read();
    if (isPrintable(c)) {
      SerialUSB.print(c);
    }
    SerialUSB.print(" (");
    SerialUSB.print(c, DEC);
    SerialUSB.println(")");
  }
}

I can use Loader and Button to Upload and the code starts - but I can no longer send any characters.
Code:
C:\T_Drive\tCode\FORUM\SerailFailTest\SerailFailTest.ino Sep  4 2022 03:52:57
Echo Test Ready
Even after repowering Teensy and also the HUB?

Seems I did something to TyCommander? Closed and restarted TyComm and on two T_4.1's BOTH have taken over 20K characters.
 
Usually Linux problems are related to not having the udev rules file installed which usually means the port can't be accessed at all, or having another program trying to use it (modemmanager or a prior instance of Arduino / teensy_serialmon) which usually goggles up data Teensy transmits but usually doesn't affect the Linux-to-Teensy direction. So this one is strange. And it definitely doesn't happen on my desktop machine running Ubuntu 20.04.

Often when things go wrong on Linux, the kernel sends syslog messages. Usually they can be viewed in a terminal with "tail -f /var/log/messages". Maybe that can help shine some light on what's going wrong here? (well, not TyCommander on Windows...)
 
Note: I modified this slightly to verify what I was assuming:

Code:
// https://forum.pjrc.com/threads/71035-Bug-SerialUSB-read-is-not-functional
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  SerialUSB.begin(9600);
  while (!SerialUSB) {
    delay(1000);
  }
  digitalWrite(13, LOW);
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  SerialUSB.println("Echo Test Ready");
  pinMode( LED_BUILTIN, OUTPUT );
}

uint32_t cCnt = 0;
void loop() {
  if (SerialUSB.available() > 0) {
    digitalToggle( LED_BUILTIN );
    cCnt++;
    SerialUSB.print(cCnt);
    SerialUSB.print(" chars Rx\t");
    SerialUSB.print("Got character: ");
    char c = SerialUSB.read();
    if (isPrintable(c)) {
      SerialUSB.print(c);
    }
    SerialUSB.print(" (");
    SerialUSB.print(c, DEC);
    SerialUSB.println(")");
  }
}

I built on Ubuntu 22.04 64bit, using Todays Arduino 2 nightly build with 1.57 Teensyduino.


I unplugged the T4.1 after the program uploaded and opened terminal and did the:
Code:
echo hello > /dev/ttyACM0

The terminal window did not hang, but the Teensy was left with the LED turned on.
Which implies it still is looping waiting on:
Code:
[COLOR="#FF0000"]  while (!SerialUSB) {
    delay(1000);
  }

[/COLOR]

i.e. the echo > does not satisfy the magic Serial cookie.

Oops need to reach back over and keep the Ubuntu machine from going to sleep. If the monitor turns off it won't turn back on (NVideo issues with 22.04)...
Sometimes linux is a real pain in the arch.

Edit: Reran with 1.8.19 open serial monitor, and then did the echo and it appeared to work.

If Teensyduino 1.57 installed, I would assume that the udev rules were installed? As it checks that you have the most recent one and shows you command to install... Unless you then ignored it.

Not sure if there are any differences in how Serial Monitor works on the older version of Arduino? Or older version of Linux?
Like ModemManger? Or ???
 
Last edited:
Udev rules were installed, and checked for installation by the Teensyduino installer.

There are no errors in kern.log or syslog, only the usual USB connect/disconnect messages for the cdc_acm driver that would be expected.

Modem manager is not running, nor is it installed.

I cannot really suspect Linux here, as the test program works with both the Nano 33 BLE Sense, and the rPI Pico. Both of those devices have very different low-level implementations within the Arduino framework.

Unfortunately I cannot upgrade to Ubuntu 20.04 mid-development (too many issues for too many people involved in the project).
Is this a possible incompatibility between Arduino IDE 1.8.15 and Teensyduino? I may be able to upgrade to the 1.8.19 version.

@PaulStoffregen I only post bugs on official forums or (most of the time) as Github issues.

David Davis
 
You can always try installing 1.8.19 in a different directory and see if it makes a difference.

As for modem manager, I don't know/remember enough about it back about 18.04 timeframe. I mainly use Ubuntu, when I have to. I sort of remember that when some people did some upgrades or the like, they ended up with it installed, and there were several Arduino types that had issues...

Good luck
 
@KurtE I will try a more up to date Arduino IDE and report the results here. As for modem manager, it was purged some time ago from my Ubuntu install after it was found inserting AT commands into our testing scripts which use the USB serial port.

And thank you all for such a quick response to this issue, on a holiday weekend no less.

David Davis
 
Might also be worth mentioning you should see Teensy twice in the Arduino Tools > Ports menu. The "Teensy Ports" one uses a Linux native helper program (and on Windows and Mac, also helper programs native to those systems). The "Serial Ports" uses Java APIs only and a Java serial library. Do both give the same problem on your 18.04 machine?
 
Might also be worth mentioning you should see Teensy twice in the Arduino Tools > Ports menu. The "Teensy Ports" one uses a Linux native helper program (and on Windows and Mac, also helper programs native to those systems). The "Serial Ports" uses Java APIs only and a Java serial library. Do both give the same problem on your 18.04 machine?

I tried both of the serial port entries multiple times. No difference, the issue still persists.

David Davis
 
@KurtE I will try a more up to date Arduino IDE and report the results here. As for modem manager, it was purged some time ago from my Ubuntu install after it was found inserting AT commands into our testing scripts which use the USB serial port.

And thank you all for such a quick response to this issue, on a holiday weekend no less.

David Davis


Update: I tried Arduino IDE 1.8.19 and reinstalled Teensyduino and the issue still occurs.

David Davis
 
Can the output from post #8 be shown, explained?
>> See below version instead ...

@KurtE variation of the code I posted with turn the LED on.
From OP it is expected some amount of USB output is displayed - the Intro text in setup?

After that in Loop the LED will toggle if input is received ( though it toggles each char - so an odd # has to be sent to see the change ).

It will only print again as written when new .read() data is seen - it could be updated to print something each second to show as indicated PRINT works when READ fails.

Adding the recurring print looks like this:
Code:
// https://forum.pjrc.com/threads/71035-Bug-Serial-read-is-not-functional
void setup() {
  pinMode( LED_BUILTIN, OUTPUT );
  digitalWrite(13, HIGH);
  Serial.begin(9600);
  while (!Serial) {
    delay(1000);
  }
  delay(1000);
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  Serial.println("Echo Test Ready");
  digitalWrite(13, LOW);
}

uint32_t cCnt = 0;
uint32_t sCnt = 0;
elapsedMillis someWait;
void loop() {
  if ( someWait > 1000 ) {
    Serial.print(".");
    someWait = 0;
    if ( !(++sCnt % 40) )
      Serial.println( millis());
  }
  if (Serial.available() > 0) {
    digitalToggle( LED_BUILTIN );
    if ( digitalReadFast( LED_BUILTIN ) )
      Serial.print("+>");
    else
      Serial.print("->");
    cCnt++;
    Serial.print(cCnt);
    Serial.print(" chars Rx\t");
    Serial.print("Got character: ");
    char c = Serial.read();
    if (isPrintable(c)) {
      Serial.print(c);
    }
    Serial.print(" (");
    Serial.print(c, DEC);
    Serial.println(")");
  }
}
 
Back
Top