Another vexing problem with FastLED (lastest version): code hangs on show()

Status
Not open for further replies.

marcmerlin

Well-known member
This one makes no sense:
1) my code only works if I upload other code before that also talks to my neomatrix, let's say
https://github.com/marcmerlin/Adafr...ster/examples/MatrixGFXDemo/MatrixGFXDemo.ino
this one talks to adafruit's neopixel code.
I upload, that code works.

Then, I upload my new code that uses FastLED instead (just wrote it):
https://github.com/marcmerlin/FastLED_NeoMatrix/blob/master/examples/MatrixGFXDemo/MatrixGFXDemo.ino
and it works, well kinda. It will sometimes be very slow and take 1 sec for each fastled::show() to run . Other times it runs at full speed and I haven't pinned down why or how yet.

2) if I power cycle the teensy 3.1 or 3.2, the code hangs on
Matrix Size: 16 16
Num Pixels: 256
malloc size: 768
If the code crashes here, decrease the brightness or turn off the all white display below
Basically it hangs just before the very first show() command.

Although more testing showed that maybe it doesn't hang, but just takes a very very long time, like maybe 1mn or more for each show() command to work.
To get out of that state, I upload another neopixel sketch and then upload my code again, and it works full speed until the next power cycle.

3) if I upload other basic test fastled code, it seems to work ok.

4) I tried to change the speed from 96Mhz to others, but it doesn't fix the show() hang. I also tried optimize fast/faster/fastest and it didn't seem to help either.
I'm just stumped.

Any idea how I can debug further?

Thanks

"/var/local/arduino-1.8.5-teensyduino-1.41/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O1 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -D__MK20DX256__ -DTEENSYDUINO=141 -DARDUINO=10805 -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/var/local/arduino-1.8.5-teensyduino-1.41/hardware/teensy/avr/cores/teensy3" "-I/home/merlin/Arduino/libraries/Adafruit-GFX-Library" "-I/home/merlin/Arduino/libraries/FastLED_NeoMatrix" "-I/home/merlin/Arduino/libraries/FastLED" "/tmp/arduino_build_896572/sketch/MatrixGFXDemo.ino.cpp" -o "/tmp/arduino_build_896572/sketch/MatrixGFXDemo.ino.cpp.o"
In file included from /home/merlin/Arduino/libraries/FastLED_NeoMatrix/FastLED_NeoMatrix.h:31:0,
from /home/merlin/Arduino/libraries/FastLED_NeoMatrix/examples/MatrixGFXDemo/MatrixGFXDemo.ino:6:
/home/merlin/Arduino/libraries/FastLED/FastLED.h:17:21: note: #pragma message: FastLED version 3.001.007
# pragma message "FastLED version 3.001.007"
 
As further debug, I removed all the Serial.printxx commands from my code and the same problem happens.
I then let it run for 4H while I was away, and it was able to run the show() command 16 times, or about once after 15 minutes.
So basically I was wrong when I said it hangs, it just runs very very very slowly unless I load other code first to "prime" it.

For good measure, I also allowed my code to use FastLED bundled with teensyduino, and that made no difference to my problem
/var/local/arduino-1.8.5-teensyduino-1.41/hardware/teensy/avr/libraries/FastLED/FastLED.h:17:21: note: #pragma message: FastLED version 3.001.008
# pragma message "FastLED version 3.001.008"


I then tested the same exact code recompiled on ESP8266, and it just worked.
I then unplugged and plugged the ESP8266 and it still just worked.
So, there seems to be an issue with teensy 3.1, maybe with my binary or timing or something, but I can't tell what.

Any ideas?
 
Last edited:
There was a FastLED bug a while back that had this symptom. It was a bad interaction between USB and SPI. You might try upgrading to the latest FastLED. If that doesn't fix it, the FastLED community is very active and helpful.
 
There was a FastLED bug a while back that had this symptom. It was a bad interaction between USB and SPI. You might try upgrading to the latest FastLED. If that doesn't fix it, the FastLED community is very active and helpful.

Thanks pictographer. I tried with fastled release, fastled from teensyduino, and fastled TOT git.
Same problem with all 3, sadly.
 
As more debugging, I've confirmed that I have the same problem with teensy 3.6. Fastled.show() hangs for a very long time, but actually succeeds eventually. If I let it run long enough, I can get my subsequent show() commands to run, but they take maybe 30mn each.
In the process, it also seems to kill the serial port in that Serial.println stops outputting anything, but the program continues working by displaying LEDs slowly one by one, every second or minute, or up to 30mn it seems.
What time delay I get between each show() looks kind of random. Sometimes it works full speed, sometimes super slowly, and I haven't figured out what the difference outside of pure randomness, is.
 
I've put this on my list of bugs to investigate. I have one other FastLED issue on the list, so I'll probably look into both at the same time. That's likely 2-3 weeks away...

Any chance you could trim that 700+ line program a bit? A smaller program that's just enough to reproduce this problem would really help me to look into this more quickly.
 
I've put this on my list of bugs to investigate. I have one other FastLED issue on the list, so I'll probably look into both at the same time. That's likely 2-3 weeks away...

Any chance you could trim that 700+ line program a bit? A smaller program that's just enough to reproduce this problem would really help me to look into this more quickly.

Yeah Paul, trimming obviously helps, sorry about that.
While doing more debugging, I included FastLED demo code within my own code to see if that demo would work and then my code would work or not.

While doing this, I think I narrowed it down to replacing CFastLED::show() with FastLED.show();
https://github.com/marcmerlin/FastL...c07#diff-b9d84dcc00def4ba7216baf87a157624R101
on a C++ OOP standpoint, this kind of sucks, but code-wise it seems to have fixed my problem, and I'm not sure why yet.

that said, now it works on teensy (although the display looks garbled at times), still fails on ESP32.

ESP8266 which used to work, now show garbled display at times and crashes after a while:
0x40203878: ClocklessController5, 20, 50, 30, (EOrder)66, 0, false, 5>::showPixels(PixelController(EOrder)66, 1, 4294967295u>&) at /home/merlin/Arduino/libraries/FastLED_NeoMatrix/FastLED_NeoMatrix.cpp line 71
0x401076c8: delayMicroseconds at /home/merlin/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring.c line 76
0x40203878: ClocklessController5, 20, 50, 30, (EOrder)66, 0, false, 5>::showPixels(PixelController(EOrder)66, 1, 4294967295u>&) at /home/merlin/Arduino/libraries/FastLED_NeoMatrix/FastLED_NeoMatrix.cpp line 71
0x40203ab0: CPixelLEDController(EOrder)66, 1, 4294967295u>::show(CRGB const*, int, CRGB) at /home/merlin/Arduino/libraries/FastLED_NeoMatrix/FastLED_NeoMatrix.cpp line 71
0x40203bb2: CFastLED::countFPS(int) at /home/merlin/Arduino/libraries/FastLED/FastLED.cpp line 266
0x40203c50: CLEDController::setDither(unsigned char) at /home/merlin/Arduino/libraries/FastLED/FastLED.cpp line 266
: (inlined by) CFastLED::show(unsigned char) at /home/merlin/Arduino/libraries/FastLED/FastLED.cpp line 60
0x40203a4c: CPixelLEDController(EOrder)66, 1, 4294967295u>::show(CRGB const*, int, CRGB) at /home/merlin/Arduino/libraries/FastLED_NeoMatrix/FastLED_NeoMatrix.cpp line 71
0x402010a7: delay at /home/merlin/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring.c line 51
0x40201e9c: FastLED_NeoMatrix::show() at /home/merlin/Arduino/libraries/FastLED_NeoMatrix/FastLED_NeoMatrix.h line 104
0x40201ffa: count_pixels() at /home/merlin/Arduino/libraries/FastLED_NeoMatrix/examples/MatrixGFXDemo/MatrixGFXDemo.ino line 360 (discriminator 5)
0x402010b2: delay at /home/merlin/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring.c line 54
0x40202787: loop at /home/merlin/Arduino/libraries/FastLED_NeoMatrix/examples/MatrixGFXDemo/MatrixGFXDemo.ino line 634
0x402043f1: esp_schedule at /home/merlin/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp line 57
0x4020441c: loop_wrapper at /home/merlin/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp line 57
0x4010070c: cont_norm at /home/merlin/Arduino/hardware/esp8266com/esp8266/cores/esp8266/cont.S line 109
this is helpful though since at least I get a traceback, something to look into.


Either way, it seems that the problem is likely with the lib and/or my code, not with teensy. I'll have to think about this further.
 
I must confess I'm not familiar with many of FastLED's features. Until now, I didn't even know there was more than one FastLED show() function!

Who knows, this might be a bug inside FastLED. It wouldn't be the first time. Much of the code was designed around 8 bit AVR and it seems we often hit limits first with Teensy.

If I do dig into FastLED... a minimal sample program would *really* help. :)
 
I must confess I'm not familiar with many of FastLED's features. Until now, I didn't even know there was more than one FastLED show() function!

Who knows, this might be a bug inside FastLED. It wouldn't be the first time. Much of the code was designed around 8 bit AVR and it seems we often hit limits first with Teensy.

If I do dig into FastLED... a minimal sample program would *really* help. :)
Hi Paul, sorry that it took a long time for me to get back to you on this.
The more I looked into it, the more it looked like an obscure library or compiler bug that I just didn't have a reasonable chance to debug without a real debugger, which we still don't have :(
Sadly, printf debugging seems to fail on teensy v3, while at least I got farther with ESP32/ESP8266.
On teensy, Serial.printf just stops working after a while (a few lines of output). I haven't taken the time to debug that further, for now I just develop on ESP8266 and then recompile later on teensyv3.
The other problem I have with teensy where pressing compile takes 30 seconds if my serial console happens to be open, is just too annoying for doing work. Details on that there: https://forum.pjrc.com/threads/5052...rial-on-linux-and-FastLED?p=172862#post172862

Back to CFastLED, it's the actual object that is used for all the work. I tried to inherit from it in my Matrix class, but this is what caused those problems I could not debug.
So, the good news is that my code works now (outside of serial debugging disappearing).
If in your copious spare time (haha) you're interested in Adafruit's excellent Neomatrix library and adafruit_GFX working on teensy using the better FastLED library, git pull this code:
https://github.com/marcmerlin/FastLED_NeoMatrix/
then run MatrixGFXDemo in examples and plug your neomatrix data pin output 13.
If you have a 16x16 array, it'll just work. If not, you just need to change a few defines.
 
Status
Not open for further replies.
Back
Top