How can I run independent tasks on separate cores using ESP-IDF on ESP32?
Hey @Middleware & OS coding gurus 👩💻, There is this thing I want to fully understand.
I'm working with ESP-IDF on an ESP32 and trying to run two independent tasks simultaneously on separate cores. Look how I did it using 👇👇:
The expected behavior is for both LEDs to be constantly lit. However, they are flickering, I think the tasks are running one core at a time. Adding in both tasks resolves the issue.
But my question is:
- Why are the LEDs flickering even though the tasks are assigned to separate cores and should be running concurrently?
- Why is the delay necessary if both cores are supposedly operating independently?
I understand that the delay allows for context switching between tasks, but shouldn't that be handled by the FreeRTOS scheduler with two cores available?
9 Replies
I am not sure about whether esp cores are SMP or AMP.
If cores are asymmetric multiprocessing then one core will act as primary core. In that case it will need some time for system level functioning.
In above example, The CPU is not getting the time for housekeeping and only one task is monopolizing the CPU.
It is based on assumption that cores are AMP. Please correct if i am wrong.
@shardul17 I think they are SMP configured
![attachment 0](https://cdn.answeroverflow.com/1234508169137356871/0Screenshot_20240427-081702.png)
Why is the expected behaviour of LED to be constantly on?
Exactly...
I also didn't get that...
Whenever using shared resources you should use mutexes to avoid collision, and more importantly there must be a way(Like notifications) to synchronize the task operation to make the behaviour predictable.
Are you expecting one Led to be on with each thread? The implementation seems different in terms of your expectations
@shic , that is what I want. I want both LEDs to be constantly on , except I am doing it the wrong way from my code. I am open to corrections
I think there's a misunderstanding in what you're looking for and what you have asked. If you want the two LED to be constantly on, don't turn them off. If you want them blinking concurrently in separate cores - only blink one LED per task.
Yh I shouldn't turn them off. I actually programmed it to blink .