Teensy 4.1 Workaround Assigned Uart Pins

Boberman

New member
Hello Everyone,

I’m currently working on a project that uses the Teensy 4.1. As we move forward to a new iteration of our prototypes, there are some changes in the wiring, but we’d still like to maintain compatibility with the old prototypes.

At the moment, we are using Serial6 to both send and receive data at 115200 baud, but we now need it to receive data at a higher baud rate — around 2,000,000 baud — while continuing to send at the same slower rate of 115200 baud.

Since pins 0-41 are already in use in the new design, the wiring can’t be changed easily. Ideally, we’d like to assign two different UARTs to pins 24 and 25, with one UART for sending and the other for receiving. However, based on my current understanding, this may not be possible.

This leads me to wonder: could it be possible to use the hardware UART to receive data at the higher baud rate, deactivate the sending functionality, and then use a Software UART on the available pin to send at a slower baud rate? In theory, the baud rate for sending could also be lowered further, if necessary.

I’m curious if anyone has attempted something similar or has insights into how this could be done. Any suggestions or advice would be greatly appreciated!
 
Sadly, pins 24 and 25 don't have FlexIO or XBAR capbility, so SoftwareSerial is looking like your only option.

SoftwareSerial has been broken on Teensy 4.x until only recently. You'll need to grab the latest SoftwareSerial from github.

In Arduino IDE preferences, turn on verbose output during compile. Then when you compile, look for the info about which libraries it actually used. Make sure Arduino IDE is really using the fixed copy. The old version will compile, but it just uses the hardware serial ports and we only useful for running programs hard-coded to need "SoftwareSerial" class. Only the new version actually does bitbang.

The new version should work at 115200. But it can really have adverse effects on other libraries, so if you're simultaneously receiving at 2Mbit on Serial6, you might lose incoming data if SoftwareSerial blocks interrupts for too long. There is no realistic workaround, as that's simply the nature of timing sensitive bitbanging. But at least knowing the potential problem might help you do some early testing, rather than have a highly unpleasant experience where things seem to work at first, but then fail in difficult to reproduce ways later.
 
Thanks for the quick reply and the helpful info!

One quick follow-up: Are there any pin steps necessary to deactivate sending on serial6 so there are no interferences for the software uart on that pin ?

Thanks again!
 
Quick question. Can pins 23 and 22 be used for software serial? Trying to get it working because i have used up all the hardware serial ports. TIA
 
Quick question. Can pins 23 and 22 be used for software serial?

Yes, you can use those pins.

Since msg #2 was written the new SoftwareSerial library has been released in version 1.60, so no need to grab it from github and manually install. If using Arduino IDE 2.3.7, just click Boards Manager and search "Teensy". If older than version 1.60, use the drop-down list to update to version 1.60.

You can also use FlexSerial from the FlexIO_t4 library, because both pins 22 and 23 are FlexIO pins. FlexSerial is much more efficient than SoftwareSerial. You can use FlexSerial to create several extra serial ports, which is really useful for applications like a MIDI router or many-port interface.

SoftwareSerial is limited to only 1 extra port. But with the new version in 1.60, it can work with any digital pins, whereas FlexIO only works with certain pins. See Kurt's large pinout diagram to know which pins have FlexIO capability.
 
I am finding that using pins 22 and 23 are stalling the teensy. I cant find a solution. I am finding it hard to get a definitive answer on which pins are available for FlexIO. I think I found that pins 4 and 5 might work? Im just finding limited help with FlexIO
 
Yes, pins 4 and 5 should work for FlexIO.

From Kurt's large pinout diagram (link in msg #5) these pins with yellow are the ones that work for FlexIO.

1772056142007.png
 
I am finding that using pins 22 and 23 are stalling the teensy. I cant find a solution.

The way this forum works for specific problems like a program that crashes is we generally expect you to show a complete program anyone can copy into Arduino IDE and upload to a Teensy to reproduce the problem. If your program is large or has confidential info, you can still do this by just editing any of the library examples programs (click File > Examples > FlexIO_t4) to use the same settings and reproduce the problem.

We probably can help you fix whatever is wrong... but only if we can see and ideally reproduce the problem. Trying to help with this sort of issue by blind guesswork just wastes everyone's time. Please, let us help you quickly and efficiently by giving us the program which stalls or crashes.
 
Thanks Paul. Let me try with the new pin pair first and then if I run into the same issue I will post as a separate thread. I'm trying to connect a Teensy 4.1 with a Raspberry Pi CM5 via UART. And I've used all the hardware UARTS on the teensy already.
 
Sorry, again not sure what is happening on the connections between the two boards. Note: Flexio 3 does not have DMA. I don't think that matters much on the Serial object, but... I also assume you probably tried swapping the two pins to make sure your RX goes to the TX of the the other board...

What Baud rate? Example sketch and setup? ...
 
Back
Top