teensy_loader_cli and serial port

Status
Not open for further replies.

aae

Member
Hello all,

I've noticed some weird behavior using the teensy_loader_cli. If I use the cli to load a program built for the teensy to be in "Serial" mode, and then try to send something out to the teensy through the serial port like "echo "hello" > /dev/ttyACM0, it puts the teensy into the hidraw mode like its waiting for code to be uploaded. Very odd.

This does not happen on my linux laptop, but does when its run on the ARM devices that we are actually deploying this to.

Any help here would be appreciated, let me know if more info is necessary.

Thanks,
Alex
 
When a Teensy is put into bootload for Program mode it goes into a HID mode for the program uplaod by Teensy loader.

If the cli program puts it into bootloader mode that will 'take the Teensy offline' of normal Serial and stop the sketch from running.

Not sure if that matches the observed behavior?
 
First, thanks for the quick response! It does not match the observed, I'm sorry if I explained poorly. The observed is as follows:

Put teensy in program mode - the device is now HID
Use the CLI to load a .hex firmware file that was compiled using the arduino sketch export tool, with the device type set to "Serial" - the device is now in Serial mode, connected at /dev/ttyACM0
echo "anything at all" > /dev/ttyACM0 - the device is now in HID mode, with the onboard LED indicating it is in program mode.

I hope thats clearer. Interesting that it behaves this way on our ARM machine, but I cannot replicate on x86.
 
That description is clearer - maybe the first might have been as well .... what makes no sense of course is having it act like that :( :confused:

Can it be reproduced with a simple ECHO/Blink sketch?

An echo sketch like this changed to USB only : T:\arduino-1.8.13\examples\Teensy\Serial\EchoBoth\EchoBoth.pde

Combined with a once per second or faster blink showing the Teensy is running until it quits? { like this one :: T:\arduino-1.8.13\examples\02.Digital\BlinkWithoutDelay\BlinkWithoutDelay.ino }

Here is a cut and paste merge of those two - it might even compile and run ...
It should come up and print after Serial is online - then just blink every 300 ms and echo back any incoming characters and keep blinking:
Code:
#define HWSERIAL Serial
// constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 300;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
	pinMode(ledPin, OUTPUT);
	Serial.begin(9600);
	while (!Serial && millis() < 4000 );
	Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
}

void loop() {
        int incomingByte;

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }

        
	if (Serial.available() > 0) {
		incomingByte = Serial.read();
		Serial.print("USB received: ");
		Serial.println(incomingByte, DEC);
		HWSERIAL.print("USB received:");
		HWSERIAL.println(incomingByte, DEC);
	}


}
 
Thanks defragster. I replicated the behavior using that sketch. I'm out of ideas here, what other evidence can I provide to help nail down whats going on?
 
Hello Defragster, Do you know if the Teensy 4.0 gets put in program mode (PGM LED is dim, waiting for code state) and no code ever arrives, if the loader on the Teensy will eventually time out and restart the previous code?
 
maybe related to this but the sample as provided does not work for me on teensy 41.
the serial1 works ok. but the emulated serial does not work. or better said : i have no idea how to make it work. usually an emulated serial is CDC and can be selected by a terminal emulator. the arduino serial emu does select the emulated serial.
it also says : Online.
but what ever i type there, nothing is received. also when i send data from uart1 it also does not show up.
i just changed one thing to be sure where there data came from in the sample :

Code:
// set this to the hardware serial port you wish to use
#define HWSERIAL Serial1

void setup() {
	Serial.begin(9600);
	HWSERIAL.begin(38400);
}

void loop() {
        int incomingByte;
        
	if (Serial.available() > 0) {
		incomingByte = Serial.read();
		Serial.print("USB received: ");
		Serial.println(incomingByte, DEC);
		HWSERIAL.print("USB received:");
		HWSERIAL.println(incomingByte, DEC);
	}
	if (HWSERIAL.available() > 0) {
		incomingByte = HWSERIAL.read();
		Serial.print("UART received: ");
		Serial.println(incomingByte, DEC);
		HWSERIAL.print("UART1 received:");
		HWSERIAL.println(incomingByte, DEC);
	}
}

instead of UART received i made it UART1 received.
So uart1/serial1 works ok.
but i see no way to get the serial work in the serial monitor.
i think this is the same problem? or should i put this in a new thread?
 
maybe related to this but the sample as provided does not work for me on teensy 41.
the serial1 works ok. but the emulated serial does not work. or better said : i have no idea how to make it work. usually an emulated serial is CDC and can be selected by a terminal emulator. the arduino serial emu does select the emulated serial.
...

Sorry, I am not sure what you are asking or your setup or... Other than your are using a T4.1

Simple things like: What are you running this on? Windows, Linux, ... (which versions)
How are you building this? Arduino IDE? which version Teensyduino which version...

If built by IDE what do you have setup as USB type? Serial?

If you build the simple sketch and run it and open up Serial monitor, does it work?

If you are not using USB type of Serial or something that includes serial, what terminal app are you using?
Is it configured to talk to the right thing? If windows COM<zz> number. If linus probably somthing like: /dev/ttyACM<xx> like ttyACM0
If Linux, are the udev rules properly installed...

Now if your USB type does not user normal Serial but instead uses emulated serial (SEREMU) then I know that the Arduino IDE and terminal monitor knows how to talk to it. ... TyTools knows how to... Not sure how many others.

But again not sure of setup
 
thanks for the reply. i thought that arduino would work the same on all platforms. I use windows 7. with arduino 1.8.9. i downloaded and installed teensyduino 1.55.
I compiled and uploaded the echoboth sample.
this was just to learn more about xbar (if by default the tx/rx of the hardware serials would work). ok, serial1 works just fine.
but Serial.print("USB received: "); does not work.
In arduino i use the serial monitor. it shows : TeensyMonitor:(emulated serial) Online

ok, i found the problem. USB type must be set to Serial. And this will create a CDC class driver with a virtual COM. In arduino you need to select this port. So this Serial object is routed to the serial CDC.
Before this i tested a MIDIx4 and while it uses the serial object, it does not work. It will give (emulated serial) under the ports but what ever i do i get no output on it.

So the problem seems to be the emulated serial. is it supposed to work regardless of the USB setting? since serial monitor will see an emulated serial i think it should.
 
Yes, emulated serial (all the Tools > USB Type options which do not have "Serial") is supposed to work on all computers, because it uses HID protocol.

Before you open the Arduino Serial Monitor, you do need to select the HID interface from the Tools > Ports menu.

Admittedly, Windows 7 doesn't get much testing these days, now that most Windows users are on Windows 10 or 11. If you believe this is broken on Windows 7, I could re-image my test machine back to Windows 7 to check. But first, please select the HID interface and at least show a screenshot (before I re-image that computer's Windows partition...)

Windows 7 (and all versions before Windows 10) also has a known bug in USBSER.SYS used for the CDC virtual serial mode. If you unplug the USB cable or press the pushbutton on Teensy while the Arduino Serial Monitor or any other program has the COM port open, it will fail to communicate the *next* time the driver creates a COM port. This is very confusing, because it happens after a successful upload (all uploading on Teensy uses HID protocol, never CDC, never a COM port). For this reason, I usually recommend using Windows 10.
 
t41-cdc.png
This is the CDC which works as expected.

t41-midi.png
This is when i select something without cdc serial. It show the HID device but it does not make the serial emulator in arduino work.

t41-midi-emu.png
And this is when i select emulator. now for some odd reason it works partial.
what i send from Serial1 is received and shown !
But whatever i send from the Serial Monitor : noting is received.

ok it could be win7. it is not a real problem when it does not work. i prefer cdc anyway.
ok, learned some things ;)

thanks for taking the time to reply. I do search forum and docs first before i ask. but as a beginner it is not all evident.
 
Also, when using CDC serial, you should see the COM appear in both "Teensy Ports" and "Serial ports".

If you select the Teensy Ports version, a highly optimized Arduino Serial Monitor is used together with a "teensy_serialmon" helper program which uses native WIN32 functions to access the port.

If you select if from Serial Ports, the normal (inefficient) Arduino Serial Monitor is used and all access to hardware is done through Java libraries.

If you run a program on Teensy 4.0 or 4.1 which prints at maximum speed, you'll see a pretty incredible performance difference. Depending on the speed of your PC and other factors, the Arduino IDE might completely crash under the load, so save your work before trying such a test.

The Teensy Ports selections remember the physical USB port location on your PC rather than a COM port, so as you change the USB Type, the select will "stick" to the same device even as it becomes HID, MIDI, Audio, Serial, etc. The Serial Ports part of that menu was designed for traditional "everything is a serial port" Arduino boards.
 
Yes like mentioned before : CDC works correct as expected.
I tried again and select hid but i get : Unable to open hid#vid_16c0&pid_0485...
And the serial monitor says : (offline) (Teensy)

Only when i select emulated serial it works partial : i can receive data but i can not send it.
it is not a big problem. i will use cdc. it is just for testing anyway, in the end i will not use a pc but another micro. i just thought it would be convenient for debugging/testing existing samples since they all use the Serial object.
it might be my setup since i did not see similar problems on the forum.
 
Status
Not open for further replies.
Back
Top