Fastled and wifi

RiccardoCagnasso
Posts: 3
Joined: Fri May 29, 2020 9:22 pm

Fastled and wifi

Postby RiccardoCagnasso » Fri May 29, 2020 9:34 pm

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?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Fastled and wifi

Postby ESP_Sprite » Sat May 30, 2020 8:06 am

UDP and WiFi on the same core should not crash. Can you give us the (decoded) core dump?

RiccardoCagnasso
Posts: 3
Joined: Fri May 29, 2020 9:22 pm

Re: Fastled and wifi

Postby RiccardoCagnasso » Sat May 30, 2020 10:07 am

I can do better, I can show you the code

https://pastebin.com/ZD6pwKJU

I will try to build a minimal working example later

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Fastled and wifi

Postby ESP_Sprite » Sun May 31, 2020 9:23 am

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?)

RiccardoCagnasso
Posts: 3
Joined: Fri May 29, 2020 9:22 pm

Re: Fastled and wifi

Postby RiccardoCagnasso » Mon Jun 01, 2020 2:32 pm

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.

Who is online

Users browsing this forum: No registered users and 81 guests