Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Teensy 4.x Serial ports hanging?

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Location
    Italy
    Posts
    15

    Teensy 4.x Serial ports hanging?

    I'm using Teensy 4.x Serial ports for driving LED strips via WS2812Serial, either directly or indirectly via FastLED and they seem to freeze at random times (all LED strips at the same time). This happens especially while flashing new code, but also while running.

    The most interesting part is that it seems to depend on code, somehow. It happened several times that a small (and unrelated) change made it unstable (freezing) while it was perfectly stable just before that change.

    The only way for restoring functionality is to power down.

    Is there a way for manually ensuring all Serial ports are properly reset?

    Should you need to look at my code, here it is: https://github.com/lpaolini/Striptease

    Thanks,
    Luca
    Last edited by lpaolini; 01-22-2021 at 08:59 AM.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,980
    Can you give me a small self-contained program (using only libs Teensyduino installs) which I can copy into Arduino (not PlatformIO) to reproduce the problem?

    To specifically answer your question:

    Is there a way for manually ensuring all Serial ports are properly reset?
    Serial1.begin(), Serial2.begin(), etc are supposed to fully initialize the serial port hardware. If using WS2812Serial, that code is built into the WS2812Serial library, so you should not add Serial1.begin().


    It happened several times that a small (and unrelated) change made it unstable (freezing) while it was perfectly stable just before that change.
    We have seen these sorts of problems over and over on this forum. Almost always the issue turns out to be a buffer overflow. These bugs are very hard to troubleshoot, partly because even small changes to your program can alter the layout of items in memory, partly because a bug which overwrites other variables tends to manifest problems *much* later when other code actually uses those corrupted variables.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Location
    Italy
    Posts
    15
    Hi Paul,

    Many thanks for your reply.

    Quote Originally Posted by PaulStoffregen View Post
    Can you give me a small self-contained program (using only libs Teensyduino installs) which I can copy into Arduino (not PlatformIO) to reproduce the problem?
    I'll try to shrink it down and send it over to you the next time it happens.

    Quote Originally Posted by PaulStoffregen View Post
    Serial1.begin(), Serial2.begin(), etc are supposed to fully initialize the serial port hardware. If using WS2812Serial, that code is built into the WS2812Serial library, so you should not add Serial1.begin().
    Ok.

    Quote Originally Posted by PaulStoffregen View Post
    We have seen these sorts of problems over and over on this forum. Almost always the issue turns out to be a buffer overflow. These bugs are very hard to troubleshoot, partly because even small changes to your program can alter the layout of items in memory, partly because a bug which overwrites other variables tends to manifest problems *much* later when other code actually uses those corrupted variables.
    Yeah, exactly what I was thinking.
    I'll go through my code again, but I'm not very positive about finding something as it's pretty "high level" code.

    Thanks again.

  4. #4
    Junior Member
    Join Date
    Jun 2020
    Location
    Italy
    Posts
    15
    It happened again, after many hours.

    Right now all my LED strips, connected to Teensy 4.1 Serial 1, 3, 4 and 7 and frozen, but the program is running.
    I can use the serial monitor or the infrared remote to interact with it and everything looks fine, except for the LED strips.

    I have tried re-uploaded the same code: it succeeds but nothing changes.
    What I'm thinking is that Serial ports are now in a bad state.

    Is this possible? Is the reset triggered after uploading any different from a hard reboot?
    I'm really confused. :-/

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,980
    Quote Originally Posted by lpaolini View Post
    Is the reset triggered after uploading any different from a hard reboot?
    After uploading, the bootloader chip uses the hardware reset signal to fully reset the main processor. The serial port hardware is supposed to be fully reset.

    Let me answer now with another question. How could you know whether the problem is Teensy or your LEDs?

    Maybe try wiring the LEDs to separate power (USB power might be simplest), so you can power cycle Teensy without also power cycling the LEDs.

  6. #6
    Junior Member
    Join Date
    Jun 2020
    Location
    Italy
    Posts
    15
    Quote Originally Posted by PaulStoffregen View Post
    After uploading, the bootloader chip uses the hardware reset signal to fully reset the main processor. The serial port hardware is supposed to be fully reset.
    Ok.

    Quote Originally Posted by PaulStoffregen View Post
    Let me answer now with another question. How could you know whether the problem is Teensy or your LEDs?
    I don't know for sure, I'm just guessing.
    Between the serial ports and the strips there's a single 8-port level converter (74HCT245) followed by a 100ohm resistor for each port.
    What makes me think of the serial ports is the fact that all strips freeze at the same time.
    The only other reason I can think of is a faulty 74HCT245, which is quite unlikely I guess.

    Quote Originally Posted by PaulStoffregen View Post
    Maybe try wiring the LEDs to separate power (USB power might be simplest), so you can power cycle Teensy without also power cycling the LEDs.
    Sure, I'll try that. I can disconnect the main board (holding the Teensy, the Audio Board and level shifter) while keeping the LED strips powered, then reconnect the board and see what happens.

  7. #7
    Junior Member
    Join Date
    Jun 2020
    Location
    Italy
    Posts
    15
    Quote Originally Posted by PaulStoffregen View Post
    Maybe try wiring the LEDs to separate power (USB power might be simplest), so you can power cycle Teensy without also power cycling the LEDs.
    Hi Paul,

    I followed your suggestion and, unbelievably enough, I found that the problem is in the level shifter. :-O
    I can't really understand how can a 74HCT245 enter this state... I hope it's a faulty device, otherwise I don't know what to think.

    And why this happens almost always after uploading?

    In case you have time to look at my (very simple) circuit, it's here:
    https://github.com/lpaolini/Striptea...hardware/EAGLE

    Thanks a lot for pointing me to the right direction.
    Last edited by lpaolini; 01-24-2021 at 11:04 AM.

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,875
    Take this with a grain of salt, as I never use Eagle and the version I have is really old (6.6.0) and may not have read everything properly

    But when I looked at your T4.1 board, it almost looks like some of the ground signals are not routed? C3, C2 and your 74245N?

    Again probably not seeing it right...

  9. #9
    Junior Member
    Join Date
    Jun 2020
    Location
    Italy
    Posts
    15
    Quote Originally Posted by KurtE View Post
    Take this with a grain of salt, as I never use Eagle and the version I have is really old (6.6.0) and may not have read everything properly

    But when I looked at your T4.1 board, it almost looks like some of the ground signals are not routed? C3, C2 and your 74245N?

    Again probably not seeing it right...
    OUCH! YOU'RE RIGHT!!

    That's the problem, for sure!
    At least it'll be easy to fix, because of the ground planes all around...

    Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •