Page 1 of 1

Fastled and wifi

Posted: Fri May 29, 2020 9:34 pm
by RiccardoCagnasso
I'm trying to drive leds with Fastled by sending the data via UDP packets via wifi.

The size of the UDP packet is 1024B, that's the biggest that should confortably pass trough all the common routers. So I need 4 packets to get 1024 RGB leds (plus some headers)

I want to move the part that receives the packets on one core leave the other to Fastled.show(), so to maximize the resources for the frame drawing. So I made a double buffer architecture, where loop() receives the data, put them in a led buffer and when the buffer is complete it memcopy and notifies (via semaphore) the "fastled" routine that the next frame is ready.

I did put the "fastled" routine on core 0 and it kinda worked, but sometimes the leds would flicker. After ruling out everyting else, I came to the conclusion that it was the WiFi routines on core 0 that were interrupting Fastled.show() causing the flicker. (It's kind of a known behaviour).

Then I did put my "fastled" routine in core 1 and moved the UDP part in a new routine in core 0. But this seems to make the software crash with a dump. My guess here is that my UDP handling interrupts the wifi routines and causes issues.

Is there a way to read big packets from wifi on Core 1?

Re: Fastled and wifi

Posted: Sat May 30, 2020 8:06 am
by ESP_Sprite
UDP and WiFi on the same core should not crash. Can you give us the (decoded) core dump?

Re: Fastled and wifi

Posted: Sat May 30, 2020 10:07 am
by RiccardoCagnasso
I can do better, I can show you the code

https://pastebin.com/ZD6pwKJU

I will try to build a minimal working example later

Re: Fastled and wifi

Posted: Sun May 31, 2020 9:23 am
by ESP_Sprite
I'd still like to see the crash dump as well if you can, as I don't have the means to easily reproduce your setup here. (Also, my intuition tells me that 1000 bytes of stack is on the low side for your task... perhaps try to increase this to 8K and see if the problem persists?)

Re: Fastled and wifi

Posted: Mon Jun 01, 2020 2:32 pm
by RiccardoCagnasso
Yes, you are right. It was a stack size problem, I actually independently found it out yesterday.
I was forgetting how the stacks in C actually works with function calls.

Anyway, thanks.