Page 1 of 1

Esp32 Tasks - communication and control

Posted: Mon Apr 29, 2024 9:16 pm
by mnfisher
A work in progress.

The esp32 makes it easy to have multiple tasks performing different functions. For example a task could update an LED display when required.

There are several options to communicate data to a task - for example to change the LED colour.

For example there are queues, semaphores and notifications.

Of these - notifications are simplest. I wrote a simple component - to allow notifications (which are a 32 bit value) to be passed to a task. The task is 'asleep' until it receives a notification - at which point it wakes, performs its task and then sleeps again until another instruction is passed.

Here is a very simple example - the main task creates a 'task' that prints the value of any notifications received to UART (note that it also has a delay which is not strictly necessary here - this is to allow testing of some of the notification types - which can 'fail' if the task is not ready)
Notify.fcpx
(1.69 KiB) Downloaded 650 times
TestNotify.fcfx
(9.35 KiB) Downloaded 659 times
Notify.fcfx
(9.41 KiB) Downloaded 640 times
I haven't included instructions for adding a component here...

Note that in more recent versions of FreeRTOS - the task can have an array of notifications. Tasks can receive notifications from other tasks or from ISRs.

Martin

Re: Esp32 Tasks - communication and control

Posted: Thu Jan 30, 2025 6:29 pm
by stefan.erni
Hi Martin

I have looked at a few examples of yours and learnt a lot. Thanks to you.
It works with the additional task to create.
In the additional task I can send UART and write to the sd-card.
I can also take over variables from the main.
I will try to place the saving of data to sd-disc in an additional task in my program.
Special I had to increase the stack size to 10240
2025-01-30_19-08-50.PNG
2025-01-30_19-08-50.PNG (5.87 KiB) Viewed 1956 times
File is ok:
2025-01-30_19-14-55.PNG
2025-01-30_19-14-55.PNG (13.81 KiB) Viewed 1956 times
uart is ok
2025-01-30_19-16-59.PNG
2025-01-30_19-16-59.PNG (22.4 KiB) Viewed 1956 times
my program
Queue_SD_Card.fcfx
(33.21 KiB) Downloaded 12 times

Re: Esp32 Tasks - communication and control

Posted: Thu Jan 30, 2025 8:21 pm
by mnfisher
Hi Stefan,

Glad your project is moving along.... The esp32 really is quite a remarkable MCU - and it looks like the trend towards more performance is continuing with espressif's new releases.
I'm sure Matrix will continue to support them in Flowcode making it easy (well easier) to tap into some of that power...

Martin

Re: Esp32 Tasks - communication and control

Posted: Wed Feb 05, 2025 2:06 pm
by stefan.erni
Hi Martin

One more question.
It works with the task and writing to the disk.
Only during writing, the sampling slows down.
Can I also run the task in the other core?

Re: Esp32 Tasks - communication and control

Posted: Wed Feb 05, 2025 2:22 pm
by mnfisher
I've never tried it - but xTaskCreate allows you to specify the priority and you could try increasing that.. You could also try xTaskCreatePinnedToCore - but the normal xTaskCreate should allow the task to run on either core - so this might not make much difference.

Make sure no tasks are busy-waiting (for pin change etc) - but yield and use a 'wait' procedure to pause until an event - as the system relies on tasks passing control back to the task-handler whenever possible.

Martin

Re: Esp32 Tasks - communication and control

Posted: Wed Feb 05, 2025 3:37 pm
by stefan.erni
Hi Martin

It looks like this is working :)
during writing, the sampling is not slows down! If the task is in core1 and not in core0
I will test it more.
2025-02-05_16-28-07.PNG
2025-02-05_16-28-07.PNG (170.51 KiB) Viewed 1771 times