Repository navigation
Description
Hello,
First of all, thank you for creating this awesome library.
I am using this library inside the ESP-IDF with the ESP32-S3 board. While testing out some code, I noticed that the library does not work properly when pinned to Core 1 with the xTaskCreate. I am driving merely 16 LEDs and it works fine on Core 0, but when I pin the task on Core 1, the lights either don't work at all or only a few LEDs get updated. I use WS2812B chips with the library. For some reason, when I set the whole frame to a fixed color it doesn't work at all. But when I set the frame with a code similar to Pride2015, just a few LEDs get updated but they work correctly. However, the rest of the LEDs don't work. I thought this was a priority issue of the tasks or because of the buffer size of the task, but changing neither made the library work on Core 1. However, when I switch the Core 0 everything works just fine. Since I have WiFi and ESP-Mesh code running on the Core 0, I don't want to bother with updating the LEDs which is a very low priority for me. This issue might be related to the one mentioned in #1438 but I'm not completely sure. That's why I opened a new issue.
For me, when I create it like this it works:
xTaskCreatePinnedToCore( DeviceInterface::frameTask, "Frame-Task", 2000, NULL, 2, NULL, PRO_CPU_NUM );
And when I create it like this, it doesn't work:
xTaskCreatePinnedToCore( DeviceInterface::frameTask, "Frame-Task", 2000, NULL, 2, NULL, APP_CPU_NUM );
I can't pinpoint the exact source of the issue since the code doesn't throw any errors, but I think the show function does not update the LEDs properly for some reason as mentioned in the other issue. The rest of the code seems to be working fine.
My task looks like this:
void DeviceInterface::frameTask( void * args ) {
InterfaceState lastState = INTERFACE_STATE_UNKNOWN;
while( true ) {
if( currentState == INTERFACE_IDLE ) {
LightFrame::frameRainbow();
}
delay(INTERFACE_LIGHT_FRAME_UPDATE_INTERVAL);
}
}
But even if I create a task only for updating the LEDs, the same issue occurs.
Waiting for your help, best regards.
Activity
toybuilder commentedon Jul 3, 2023
There's other tasks running and competing for CPU cycles. Try using I2S mode by prepending the #define before the #include.
This offloads the output work to the I2S peripheral so that it does not need the CPU cycles.
In my own applications, I've found that FastLED does not work well without using I2S mode. Downside is that if you need I2S hardware for other aspects of your system, you cannot use it for FastLED.
Oh- it looks like I2S support is broken on the S2 and possibly the S3? My experience is with the ESP32, not the -S2 or -S3.
alba-ado commentedon Jul 4, 2023
I added the following line and it gave lots of errors. There are no other competing tasks on Core 1. Only the Arduino task runs there. Also, the Core 0 is much more crowded but it still works on it. I tried turning on the WiFi and Mesh tasks as well, and it works even if those tasks are running. Nothing runs on Core 1, but the library refuses to work. Also, I don't think the ESP32-S3 has I2S support. At least not like the one in the ESP32. They have changed the hardware. But I also noticed that it says:
So do I need to define SPI pins in some way? (Edit: #1169 says this warning is useless since the chip doesn't have a clock)
Here is the full output:
alba-ado commentedon Oct 9, 2023
Any updates on this? The library simply don't work on Core 1 with esp32-s3. There are no other running tasks. Only a few LEDs get updated from time to time and the rest is not getting any updates.
zackees commentedon Oct 9, 2023
Just speculating - I think the interrupts are disabled globally while running WS2812. But when you have multi core the interrupts only get disabled for one of the chips, the one you aren't running the WS2812 on.
But I could be wrong.
alba-ado commentedon Oct 10, 2023
How can I try this? By calling the arduino function disableInterrupts before updating the LEDs? Also, the whole software stack runs on Core 1, shouldn't it be disabling the interrupts on whichever core it is running? Otherwise it should be using some low level commands to directly disable them.
alba-ado commentedon Oct 13, 2023
Tried disabling the interrupts using portDISABLE_INTERRUPTS();
It didn't change anything.
samguyer commentedon Oct 13, 2023
I've seen this kind of behavior before. Are you using WiFi for anything? I think what happens is that ESP-IDF puts the whole WiFi stack on Core 1, whether you use it or not. So there's a bunch of super-high priority interrupts running on Core 1.
alba-ado commentedon Oct 14, 2023
On the contrary, the ESP WiFi works on Core 0, and the behavior is persistent whether the WiFi is turned on or not. I tried a bare minimum example without anything and it still holds true. Nothing runs on Core 1
alba-ado commentedon Oct 14, 2023
Here is the task list printed:
As seen from above, nothing runs on Core 1 except a task called ipc1. I also tried increasing the task priority of the leds above this task and it still doesn't work. Only a few leds at the beginning gets updated, rest remains unlit.
samguyer commentedon Oct 14, 2023
Oh right, I had the two cores backwards. I think Arduino sketches run on Core 1 by default and Wifi runs on Core 0. But that makes the behavior you are seeing even more puzzling because most of our users are probably using the Arduino toolchain, so they are running FastLED.show() on Core 1.
Maybe one thing to try: get one of the demo sketches (like DemoReel) and upload it to your board using the Arduino IDE. If that does not work, it means we need to look more carefully at how the S3 differs from the other ESP32 models. If it DOES work, we need to look at your code more carefully, and maybe look at the toolchain you're using.
alba-ado commentedon Oct 16, 2023
Thanks for your response. Your logic made a lot of sense to me (that the Arduino also runs on Core 1) and I started a new project to test things out. Apparently, the library does indeed work on Core 1. What was different from that example and my code was where I initialized the library. In my code, I initialized the library on the app_main() function (which runs on Core 0) and used it in a new task that runs on Core 1. When I wrote the test code, I added the library initialization on the same task and it work. So, I tested it by moving the initialization step into the same task in my code and it worked as well. What confused me a lot was a few LEDs were actually getting updated and the rest was not. Also, other libraries were again initialized on Core 0 and made to be working on Core 1, but they all ran fine without any change. However, this library requires initialization on the same core as the program that runs it. I also tried it initializing it in another task that runs on Core 1, it also works fine without a problem. I don't know what this behavior is but I am actually initializing the library before spawning the task. I guess the library init needs to be on the same core as the task, unlike other libraries I used.
samguyer commentedon Oct 16, 2023
I was going to ask you if you were initializing on a different core from the main animation code. I think the problem has to do with the way interrupts are delivered. We set up the interrupt handler in the initialization, so I think there is a potential issue if the interrupts actually need to be delivered to the other core. Maybe it takes a little longer to reroute them, causing some of the data to get dropped.
We should probably at least document this issue, so that others don't run into the same problem.
alba-ado commentedon Oct 17, 2023
Documentation would be nice, since other libraries don't have a problem working this way. I use 7 other libraries inside the project the same way and this is the only one that caused an issue. Thanks for the help.