[teensy 4.0] with-serial on port 1-3 goes to USB instead of Serial1-3


#1

I’m still investigating this issue, but I’m posting to see if anyone else has run into similar problems. Using with-serial on the Teensy 4.0 appears to send output to the USB serial console instead of the actual serial outputs.

Steps to reproduce:

  1. Obtain a Teensy 4.0
  2. Flash uLisp 4.1a
  3. (optional) Hook up an oscilloscope to to Pin 1 (TX of Serial1)
  4. Open serial console, define the following function:
    (defun serial-test ()
    (with-serial (s 1)
    (write-byte 45 s))) ; 45 is the hyphen character ‘-’
  5. Evaluate (serial-test)

On the scope, you can observe that TX output goes from low to high (as a result of with-serial calling Serial1.Begin() on the appropriate port), but then immediately goes back down without transmitting char 45.

On the USB console, you can observe the ‘-’ character printed, suggesting that this is going to the USB console instead:

uLisp 4.1a
59999> (defun serial-test ()
 (with-serial (s 1 96)
   (write-byte 45 s)))
serial-test

59974> (serial-test)
(serial-test)
-
nil

Aside, the (with-spi) form does appear to work correctly with (write-byte), so this issue might be isolated to serial.

I suspect something is going wrong in pstreamfun or sp_withserial, but would need to do some more poking to find out.


#2

I think the error is in pstreamfun. The block:

  } else if (streamtype == SERIALSTREAM) {
    if (address == 0) pfun = pserial;
    #if defined(SERIAL3)
    else if (address == 1) pfun = serial1write;
    else if (address == 2) pfun = serial2write;
    else if (address == 3) pfun = serial3write;
    #elif defined(SERIAL2)
    else if (address == 1) pfun = serial1write;
    else if (address == 2) pfun = serial2write;
    #elif defined(SERIAL1)
    else if (address == 1) pfun = serial1write;
    #endif
  }

should be:

  } else if (streamtype == SERIALSTREAM) {
    if (address == 0) pfun = pserial;
    #if defined(ULISP_SERIAL3)
    else if (address == 1) pfun = serial1write;
    else if (address == 2) pfun = serial2write;
    else if (address == 3) pfun = serial3write;
    #elif defined(ULISP_SERIAL2)
    else if (address == 1) pfun = serial1write;
    else if (address == 2) pfun = serial2write;
    #elif defined(ULISP_SERIAL1)
    else if (address == 1) pfun = serial1write;
    #endif
  }

Sorry about that, and thanks for spotting it! Let me know if that fixes it.


#3

Also slightly before that:

#if defined(SERIAL3)
inline void serial1write (char c) { Serial1.write(c); }
inline void serial2write (char c) { Serial2.write(c); }
inline void serial3write (char c) { Serial3.write(c); }
#elif defined(SERIAL1)
inline void serial1write (char c) { Serial1.write(c); }
#endif

should be:

#if defined(ULISP_SERIAL3)
inline void serial1write (char c) { Serial1.write(c); }
inline void serial2write (char c) { Serial2.write(c); }
inline void serial3write (char c) { Serial3.write(c); }
#elif defined(ULISP_SERIAL2)
inline void serial2write (char c) { Serial2.write(c); }
inline void serial1write (char c) { Serial1.write(c); }
#elif defined(ULISP_SERIAL1)
inline void serial1write (char c) { Serial1.write(c); }
#endif

#4

I had to squint for a while even when the changes were right in front of me!

These changes fix writing to streams inside (with-serial) for me.

Thank you for ULisp and for the quick response and fix.


#5

Thanks for reporting back. I’ll release a new version incorporating the fix within a few days.


#7

#8

This is now fixed in ARM Version 4.2.


#9